rano/pkg/auth/ctx.go

29 lines
544 B
Go
Raw Normal View History

2024-11-10 09:22:33 +00:00
package auth
import (
"context"
"gitserver.in/patialtech/rano/config"
)
type SessionUser struct {
ID int64
Email string
DisplayName string
RoleID int
}
func CtxWithUser(ctx context.Context, u *AuthUser) context.Context {
return context.WithValue(ctx, config.AuthUserCtxKey, &SessionUser{
ID: u.ID,
Email: u.Email,
DisplayName: u.DisplayName,
RoleID: u.RoleID,
})
}
func CtxUser(ctx context.Context) *SessionUser {
u, _ := ctx.Value(config.AuthUserCtxKey).(*SessionUser)
return u
}