modularised webserver and auth systems
This commit is contained in:
9
pkg/contexts/currentuser.go
Normal file
9
pkg/contexts/currentuser.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package contexts
|
||||
|
||||
import (
|
||||
"projectreshoot/internal/models"
|
||||
|
||||
"git.haelnorr.com/h/golib/hwsauth"
|
||||
)
|
||||
|
||||
var CurrentUser hwsauth.ContextLoader[*models.User]
|
||||
@@ -1,25 +0,0 @@
|
||||
package contexts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"projectreshoot/internal/models"
|
||||
)
|
||||
|
||||
type AuthenticatedUser struct {
|
||||
*models.User
|
||||
Fresh int64
|
||||
}
|
||||
|
||||
// Return a new context with the user added in
|
||||
func SetUser(ctx context.Context, u *AuthenticatedUser) context.Context {
|
||||
return context.WithValue(ctx, contextKeyAuthorizedUser, u)
|
||||
}
|
||||
|
||||
// Retrieve a user from the given context. Returns nil if not set
|
||||
func GetUser(ctx context.Context) *AuthenticatedUser {
|
||||
user, ok := ctx.Value(contextKeyAuthorizedUser).(*AuthenticatedUser)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return user
|
||||
}
|
||||
Reference in New Issue
Block a user