feat: add GetUserFromContext

This commit is contained in:
Derrick Hammer 2024-02-13 23:22:36 -05:00
parent 9d25690d72
commit 16689f6c31
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 20 additions and 0 deletions

View File

@ -156,3 +156,23 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl
})
}
}
func GetUserFromContext(ctx context.Context, key ...string) uint {
realKey := ""
if len(key) > 0 {
realKey = key[0]
}
if realKey == "" {
realKey = DEFAULT_AUTH_CONTEXT_KEY
}
userId, ok := ctx.Value(key).(uint)
if !ok {
panic("user id stored in context is not of type uint")
}
return userId
}