diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-17 18:07:11 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-17 18:07:11 +0200 |
commit | 70031d8971136583647125d967ace7b9c831ed00 (patch) | |
tree | 9b3b329b366ab9e5637de3dabb2a64c46bfc76f0 /pages/login.go | |
parent | 650053446d18424500ae6330b5ad0da81fa86373 (diff) | |
download | gosten-70031d8971136583647125d967ace7b9c831ed00.tar.gz gosten-70031d8971136583647125d967ace7b9c831ed00.tar.bz2 gosten-70031d8971136583647125d967ace7b9c831ed00.zip |
Save User as part of the context
Diffstat (limited to 'pages/login.go')
-rw-r--r-- | pages/login.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/pages/login.go b/pages/login.go index 14b1ce1..84119e9 100644 --- a/pages/login.go +++ b/pages/login.go @@ -6,6 +6,7 @@ import ( "errors" "gosten/csrf" "gosten/form" + "gosten/model" "gosten/session" "log" "net/http" @@ -17,8 +18,8 @@ import ( type userContextKey struct{} -func userId(r *http.Request) int32 { - return r.Context().Value(userContextKey{}).(int32) +func getUser(ctx context.Context) model.User { + return ctx.Value(userContextKey{}).(model.User) } const ( @@ -34,7 +35,7 @@ func RequireAuth(next http.Handler) http.Handler { u, err := Q.GetUserById(r.Context(), s.UserID) if err == nil { // authenticated --> done - ctx := context.WithValue(r.Context(), userContextKey{}, u.ID) + ctx := context.WithValue(r.Context(), userContextKey{}, u) next.ServeHTTP(w, r.WithContext(ctx)) return } @@ -126,5 +127,5 @@ func handleLogin(w http.ResponseWriter, r *http.Request) { } func showLoginPage(r *http.Request, w http.ResponseWriter, u user) { - render(login(u), w, r) + render(login(u))(w, r) } |