{"record":{"id":"4c8298cfe9fab8f5","repo":"Tencent/WeKnora","slug":"user-not-found-in-context","errorCode":null,"errorMessage":"user not found in context","messagePattern":"user not found in context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/user.go","lineNumber":1396,"sourceCode":"\n// RevokeToken revokes a token\nfunc (s *userService) RevokeToken(ctx context.Context, tokenString string) error {\n\ttokenRecord, err := s.tokenRepo.GetTokenByValue(ctx, tokenString)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttokenRecord.IsRevoked = true\n\ttokenRecord.UpdatedAt = time.Now()\n\n\treturn s.tokenRepo.UpdateToken(ctx, tokenRecord)\n}\n\n// GetCurrentUser gets current user from context\nfunc (s *userService) GetCurrentUser(ctx context.Context) (*types.User, error) {\n\tuser, ok := ctx.Value(types.UserContextKey).(*types.User)\n\tif !ok {\n\t\treturn nil, errors.New(\"user not found in context\")\n\t}\n\n\treturn user, nil\n}\n\n// SearchUsers searches users by username or email\nfunc (s *userService) SearchUsers(ctx context.Context, query string, limit int) ([]*types.User, error) {\n\tif query == \"\" {\n\t\treturn []*types.User{}, nil\n\t}\n\treturn s.userRepo.SearchUsers(ctx, query, limit)\n}\n\ntype oidcDiscoveryDocument struct {\n\tAuthorizationEndpoint string `json:\"authorization_endpoint\"`\n\tTokenEndpoint         string `json:\"token_endpoint\"`\n\tUserInfoEndpoint      string `json:\"userinfo_endpoint\"`\n\tJwksURI               string `json:\"jwks_uri\"`","sourceCodeStart":1378,"sourceCodeEnd":1414,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/user.go#L1378-L1414","documentation":"Raised in GetCurrentUser when the request context carries no *types.User under types.UserContextKey — the auth middleware did not run or did not inject the user, so the handler bypassed authentication. Context-shape guard.","triggerScenarios":"Thrown at internal/application/service/user.go:1396 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the route is protected by the auth middleware before calling GetCurrentUser","Return 401 instead of treating it as a normal business error"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}