mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-06-03 20:13:00 +00:00
cleanup
This commit is contained in:
@@ -12,8 +12,23 @@ import (
|
||||
|
||||
const principalContextKey = "principal"
|
||||
|
||||
func RequireAuth(verifier *Verifier, repo db.Repository) gin.HandlerFunc {
|
||||
// DemoPrincipal is the auto-authenticated user in demo mode
|
||||
var DemoPrincipal = domain.Principal{
|
||||
Subject: "demo-owner",
|
||||
Email: "demo@bookra.dev",
|
||||
Name: "Demo User",
|
||||
Role: "owner",
|
||||
}
|
||||
|
||||
func RequireAuth(verifier *Verifier, repo db.Repository, demoMode bool) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// In demo mode, auto-authenticate as the demo user
|
||||
if demoMode {
|
||||
c.Set(principalContextKey, DemoPrincipal)
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
if verifier == nil || !verifier.Enabled() {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "auth_not_configured"})
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user