Skip to content

Commit

Permalink
fix: set user to authenticate
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Urban committed May 1, 2024
1 parent bda12eb commit 5717941
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions backend/internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
return
}
oneTimeStore[oneTimeToken] = TokenInfo{true, inputUser.Email}
slog.Info("token set")
slog.Info("token set", inputUser.Email)
sendJSONResponse(w, response, http.StatusOK)
}

Expand Down Expand Up @@ -223,8 +223,10 @@ func (h *Handler) HandleAuthenticate(w http.ResponseWriter, r *http.Request) {
auth, ok := session.Values["authenticated"].(bool)
token, ok := session.Values["oneTimeToken"].(string)
tokenAuthenticated := oneTimeStore[token].authenticated
tokenUser := oneTimeStore[token].user
slog.Info("token ?:", token)
slog.Info("tokenAuth ?:", tokenAuthenticated)
slog.Info("tokenUser ?:", tokenUser)
slog.Info("auth ?:", auth)
slog.Info("ok: ", ok)
if !ok || (!auth && !tokenAuthenticated) {
Expand Down Expand Up @@ -260,10 +262,10 @@ func (h *Handler) HandleAuthenticate(w http.ResponseWriter, r *http.Request) {
return
}
if tokenAuthenticated {
delete(oneTimeStore, token)
session.Values["authenticated"] = true
session.Values["user"] = oneTimeStore[token].user
session.Save(r, w)
delete(oneTimeStore, token)
}
slog.Info("Incoming session is authenticated")
sessionUser, ok := session.Values["user"].(string)
Expand Down

0 comments on commit 5717941

Please sign in to comment.