feat: expire & prolong sessions
This commit is contained in:
@@ -34,6 +34,7 @@ func indexPageRoute(
|
||||
) http.HandlerFunc {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getRequestSession(r, sessionSM)
|
||||
log.Printf("/ the session i got is %+v", session)
|
||||
if err != nil {
|
||||
log.Printf("/ session not found, means should render the login section %s", err)
|
||||
// TODO return error i guess
|
||||
|
||||
@@ -71,7 +71,7 @@ func getRequestSession(r *http.Request,
|
||||
if err != nil {
|
||||
return sessions.SessionData{}, ErrAuthCookieValueInvalid
|
||||
}
|
||||
session := sessionsM.Get(sessionId)
|
||||
session := sessionsM.Get(r.Context(), sessionId)
|
||||
if session == (sessions.SessionData{}) {
|
||||
return sessions.SessionData{}, ErrAuthSessionNotFound
|
||||
}
|
||||
@@ -177,6 +177,7 @@ func createRoomHandler(templateFs *embed.FS,
|
||||
// todo return error notice somehow
|
||||
}
|
||||
newSession, err := sessionSM.Save(r.Context(), newRoom.Name, person.Id)
|
||||
log.Printf("saving session %v", newSession)
|
||||
if err != nil {
|
||||
log.Printf("what am i to do? error saving session %s", err)
|
||||
// todo return error notice somehow
|
||||
@@ -187,6 +188,7 @@ func createRoomHandler(templateFs *embed.FS,
|
||||
Secure: true,
|
||||
HttpOnly: true,
|
||||
Path: "/",
|
||||
Expires: time.Now().Add(newSession.ExpireIn),
|
||||
})
|
||||
w.Header().Add("HX-Redirect", fmt.Sprintf("/room/%s", newRoom.Name))
|
||||
}
|
||||
@@ -308,6 +310,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
}
|
||||
|
||||
newSession, err := sessionSM.Save(r.Context(), room.Name, person.Id)
|
||||
log.Printf("saving session %v", newSession)
|
||||
if err != nil {
|
||||
log.Printf("/login/submit > error saving session %s", err)
|
||||
}
|
||||
@@ -317,6 +320,7 @@ func joinRoomHandler(templateFs *embed.FS,
|
||||
Secure: true,
|
||||
HttpOnly: true,
|
||||
Path: "/",
|
||||
Expires: time.Now().Add(newSession.ExpireIn),
|
||||
})
|
||||
log.Printf("is is %+v. room things %s & %s, personal things %s and %s. \n found room %+v",
|
||||
newSession, roomName, roomPass, personName, personPass, room,
|
||||
|
||||
Reference in New Issue
Block a user