MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / requireUser

Function requireUser

internal/api/auth.go:9–23  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

7)
8
9func requireUser(ctx *gin.Context) (ijwt.UserClaims, bool) {
10 user, exists := ctx.Get("user")
11 if !exists {
12 apiresponse.UnauthorizedErrorWithDetails(ctx, nil, "未登录或登录已过期")
13 return ijwt.UserClaims{}, false
14 }
15
16 claims, ok := user.(ijwt.UserClaims)
17 if !ok || claims.Uid == 0 {
18 apiresponse.UnauthorizedErrorWithDetails(ctx, nil, "未登录或登录已过期")
19 return ijwt.UserClaims{}, false
20 }
21
22 return claims, true
23}
24
25func currentUserID(ctx *gin.Context) int64 {
26 user, exists := ctx.Get("user")

Callers 15

CreateCommentMethod · 0.85
DeleteCommentMethod · 0.85
ParticipateSecondKillMethod · 0.85
EditMethod · 0.85
UpdateMethod · 0.85
PublishMethod · 0.85
WithdrawMethod · 0.85
ListMethod · 0.85
DetailMethod · 0.85
DeletePostMethod · 0.85
LikeMethod · 0.85

Calls 2

GetMethod · 0.65

Tested by

no test coverage detected