mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-12-15 04:36:37 +00:00
refactor: use controller approach in handlers
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"tinyauth/internal/types"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/traefik/paerser/parser"
|
||||
"golang.org/x/crypto/hkdf"
|
||||
|
||||
@@ -348,3 +349,19 @@ func CoalesceToString(value any) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func GetContext(c *gin.Context) (types.UserContext, error) {
|
||||
userContextValue, exists := c.Get("context")
|
||||
|
||||
if !exists {
|
||||
return types.UserContext{}, errors.New("no user context in request")
|
||||
}
|
||||
|
||||
userContext, ok := userContextValue.(*types.UserContext)
|
||||
|
||||
if !ok {
|
||||
return types.UserContext{}, errors.New("invalid user context in request")
|
||||
}
|
||||
|
||||
return *userContext, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user