mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-05 16:56:22 +00:00
⚡ refactor user service methods, implement OIDC login and user management features, and enhance token handling
This commit is contained in:
19
internal/ctxutils/user.go
Normal file
19
internal/ctxutils/user.go
Normal file
@ -0,0 +1,19 @@
|
||||
package ctxutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/snowykami/neo-blog/internal/model"
|
||||
"github.com/snowykami/neo-blog/internal/repo"
|
||||
)
|
||||
|
||||
func GetCurrentUser(ctx context.Context) *model.User {
|
||||
userIDValue := ctx.Value("user_id").(uint)
|
||||
if userIDValue <= 0 {
|
||||
return nil
|
||||
}
|
||||
user, err := repo.User.GetUserByID(userIDValue)
|
||||
if err != nil || user == nil || user.ID == 0 {
|
||||
return nil
|
||||
}
|
||||
return user
|
||||
}
|
Reference in New Issue
Block a user