openreplay/backend/pkg/common/api/auth/model.go
2024-10-18 18:06:40 +02:00

34 lines
692 B
Go

package auth
import "github.com/golang-jwt/jwt/v5"
type JWTClaims struct {
UserId int `json:"userId"`
TenantID int `json:"tenantId"`
jwt.RegisteredClaims
}
type User struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
TenantID uint64 `json:"tenantId"`
JwtIat int `json:"jwtIat"`
Permissions map[string]bool `json:"permissions"`
AuthMethod string
}
func (u *User) HasPermission(perm string) bool {
if u.Permissions == nil {
return true // no permissions
}
_, ok := u.Permissions[perm]
return ok
}
func abs(x int) int {
if x < 0 {
return -x
}
return x
}