Skip to content

Commit 522a720

Browse files
committed
Reset cookie on update active at
Otherwise users will be logged out after 30min.
1 parent 57a0577 commit 522a720

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

auth/middleware.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func sessionCallbacks(request *http.Request, writer http.ResponseWriter) *http.R
5050
return request.WithContext(WithDestroySession(WithCreateSession(request.Context(), createSession), destroySession))
5151
}
5252

53-
func reqisterUser(request *http.Request, _ http.ResponseWriter, db *gorm.DB) *http.Request {
53+
func reqisterUser(request *http.Request, writer http.ResponseWriter, db *gorm.DB) *http.Request {
5454
if token, err := getToken(request); err == nil {
5555
device := &model.Device{}
5656
if db.Where("token = ?", token).Find(device).RecordNotFound() {
@@ -67,6 +67,11 @@ func reqisterUser(request *http.Request, _ http.ResponseWriter, db *gorm.DB) *ht
6767
log.Debug().Int("deviceId", device.ID).Str("deviceName", device.Name).Msg("update device activeAt")
6868
device.ActiveAt = timeNow()
6969
db.Save(device)
70+
71+
if cookie, err := request.Cookie(traggoSession); err == nil && cookie != nil {
72+
cookie.MaxAge = device.Type.Seconds()
73+
http.SetCookie(writer, cookie)
74+
}
7075
}
7176

7277
return request.WithContext(WithUser(WithDevice(request.Context(), device), user))

0 commit comments

Comments
 (0)