feat(orion): add rest api for waitlist
This commit is contained in:
@@ -14,6 +14,7 @@ type contextKey string
|
||||
const (
|
||||
emailContextKey contextKey = "email"
|
||||
humanIdContextKey contextKey = "humanId"
|
||||
isAdminContextKey contextKey = "isAdmin"
|
||||
)
|
||||
|
||||
// WithEmail adds the email to the context
|
||||
@@ -38,6 +39,17 @@ func HumanIdFromContext(ctx context.Context) (string, bool) {
|
||||
return humanId, ok
|
||||
}
|
||||
|
||||
// WithIsAdmin adds the admin flag to the context
|
||||
func WithIsAdmin(ctx context.Context, isAdmin bool) context.Context {
|
||||
return context.WithValue(ctx, isAdminContextKey, isAdmin)
|
||||
}
|
||||
|
||||
// IsAdminFromContext extracts the admin flag from the context
|
||||
func IsAdminFromContext(ctx context.Context) bool {
|
||||
isAdmin, ok := ctx.Value(isAdminContextKey).(bool)
|
||||
return ok && isAdmin
|
||||
}
|
||||
|
||||
// Auth returns a middleware that validates the session token and adds the email to the context
|
||||
func Auth(authSvc auth.AuthService) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
@@ -61,6 +73,7 @@ func Auth(authSvc auth.AuthService) func(http.Handler) http.Handler {
|
||||
|
||||
ctx := WithEmail(r.Context(), session.Email)
|
||||
ctx = WithHumanId(ctx, session.HumanId)
|
||||
ctx = WithIsAdmin(ctx, authSvc.IsSystemAdmin(r.Context(), session.Email))
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user