-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie.go
44 lines (35 loc) · 786 Bytes
/
cookie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"net/http"
"time"
uuid "github.com/satori/go.uuid"
)
// create new cookie struct
func (s *Session) createCookie() *http.Cookie {
id := uuid.NewV4()
c := &http.Cookie{
Name: AuthTypeCookie,
Value: id.String(),
Secure: true, // https
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
Expires: time.Now().Add(time.Minute), // 1 minute expire session removed
}
s.ID = c.Value
s.Name = c.Name
return c
}
// deleteCookie method remove cookie and reset user credentials
func (s *Session) deleteCookie(w http.ResponseWriter) {
c := &http.Cookie{
Name: AuthTypeCookie,
Value: "",
MaxAge: -1,
Secure: true,
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
}
http.SetCookie(w, c)
s.ID = ""
s.Name = ""
}