mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-12 02:20:36 +08:00
24 lines
389 B
Go
24 lines
389 B
Go
//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
|
|
}
|