Skip to content

Commit ee7b153

Browse files
emontylunny
authored andcommitted
Fix 500 when getting user as unauthenticated user (#8653)
When doing GET /api/v1/users/{user} as an unauthenticated user, gitea throws a 500 because it's trying to dereference elements from the context user. It wants to do this to see whether to show the primary email and will do that if the logged in user is admin or the user in question. However, if ctx.User is nil, go gets really unhappy.
1 parent c84174b commit ee7b153

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

routers/api/v1/user/user.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func GetInfo(ctx *context.APIContext) {
104104
return
105105
}
106106

107-
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.ID == u.ID || ctx.User.IsAdmin))
107+
ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin)))
108108
}
109109

110110
// GetAuthenticatedUser get current user's information

0 commit comments

Comments
 (0)