mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-06-09 03:39:43 +08:00
first commit
This commit is contained in:
23
server/internal/httpapi/context.go
Normal file
23
server/internal/httpapi/context.go
Normal file
@@ -0,0 +1,23 @@
|
||||
//go:build ignore
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const claimsContextKey = "authClaims"
|
||||
|
||||
func getUserID(c *gin.Context) (uint, error) {
|
||||
value, ok := c.Get(claimsContextKey)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("missing auth claims")
|
||||
}
|
||||
claims, ok := value.(AuthClaims)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("invalid auth claims")
|
||||
}
|
||||
return claims.UserID, nil
|
||||
}
|
||||
Reference in New Issue
Block a user