{"record":{"id":"002fcb8b2c4a51b0","repo":"Tencent/WeKnora","slug":"invalid-user-id-in-token","errorCode":null,"errorMessage":"invalid user ID in token","messagePattern":"invalid user ID in token","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/user.go","lineNumber":1341,"sourceCode":"\t})\n\n\tif err != nil || !token.Valid {\n\t\treturn \"\", \"\", errors.New(\"invalid refresh token\")\n\t}\n\n\tclaims, ok := token.Claims.(jwt.MapClaims)\n\tif !ok {\n\t\treturn \"\", \"\", errors.New(\"invalid token claims\")\n\t}\n\n\ttokenType, ok := claims[\"type\"].(string)\n\tif !ok || tokenType != \"refresh\" {\n\t\treturn \"\", \"\", errors.New(\"not a refresh token\")\n\t}\n\n\tuserID, ok := claims[\"user_id\"].(string)\n\tif !ok {\n\t\treturn \"\", \"\", errors.New(\"invalid user ID in token\")\n\t}\n\n\t// Check if token is revoked\n\ttokenRecord, err := s.tokenRepo.GetTokenByValue(ctx, refreshTokenString)\n\tif err != nil || tokenRecord == nil || tokenRecord.IsRevoked {\n\t\treturn \"\", \"\", errors.New(\"refresh token is revoked\")\n\t}\n\tif tokenRecord.TokenType != \"refresh_token\" {\n\t\treturn \"\", \"\", errors.New(\"not a refresh token\")\n\t}\n\n\t// Get user\n\tuser, err := s.userRepo.GetUserByID(ctx, userID)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\t// Revoke old refresh token","sourceCodeStart":1323,"sourceCodeEnd":1359,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/user.go#L1323-L1359","documentation":"Raised in RefreshToken when the JWT claims map lacks a string user_id — the refresh token parsed and signed correctly but its payload is malformed or was minted without the expected claim. Auth-flow guard; treat as an invalid token.","triggerScenarios":"Thrown at internal/application/service/user.go:1341 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reject the token (401) and force a fresh login","Check token-issuing code so refresh tokens always carry user_id"],"exampleFix":null,"handlingStrategy":"validation","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"}