{"record":{"id":"28205eae5e315de2","repo":"calcom/cal.diy","slug":"nextauthstrategy-user-associated-with-the-authen","errorCode":null,"errorMessage":"NextAuthStrategy - User associated with the authentication token email not found.","messagePattern":"NextAuthStrategy - User associated with the authentication token email not found\\.","errorType":"http","errorClass":"UnauthorizedException","httpStatus":401,"severity":"error","filePath":"apps/api/v2/src/modules/auth/strategies/next-auth/next-auth.strategy.ts","lineNumber":30,"sourceCode":"    super();\n  }\n\n  async authenticate(req: Request) {\n    try {\n      const nextAuthSecret = this.config.get(\"next.authSecret\", { infer: true });\n      const payload = await getToken({ req, secret: nextAuthSecret });\n\n      if (!payload) {\n        throw new UnauthorizedException(\"NextAuthStrategy - Authentication token is missing or invalid.\");\n      }\n\n      if (!payload.email) {\n        throw new UnauthorizedException(\"NextAuthStrategy - Email not found in the authentication token.\");\n      }\n\n      const user = await this.userRepository.findByEmailWithProfile(payload.email);\n      if (!user) {\n        throw new UnauthorizedException(\n          \"NextAuthStrategy - User associated with the authentication token email not found.\"\n        );\n      }\n\n      return this.success(user);\n    } catch (error) {\n      if (error instanceof Error) return this.error(error);\n      return this.error(\n        new InternalServerErrorException(\n          \"NextAuthStrategy - An error occurred while authenticating the request\"\n        )\n      );\n    }\n  }\n}\n","sourceCodeStart":12,"sourceCodeEnd":46,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/auth/strategies/next-auth/next-auth.strategy.ts#L12-L46","documentation":"Thrown by NextAuthStrategy.authenticate when findByEmailWithProfile(payload.email) returns null. The session decoded with an email, but no User row matches that email in the API's database.","triggerScenarios":"A request with a NextAuth session whose email belongs to a user that was deleted, never existed in this deployment, or whose email differs by case.","commonSituations":"Session cookie carried across deployments; user deleted after session creation; email casing mismatch (User@Example.com vs user@example.com).","solutions":["Re-authenticate in the current environment so a fresh session ties to an existing user.","Confirm the user exists: `SELECT id,email FROM users WHERE lower(email) = lower('<payload.email>')`.","Normalize email to lowercase on both session creation and user lookup."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const user = await db.user.findFirst({ where: { email: payload.email } });\nif (!user) throw new Error(`No user with email ${payload.email}; re-authenticate in this environment`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize email to lower-case on both session creation and user storage/lookup.","Cascade-revoke sessions on user deletion.","Re-authenticate whenever switching environments or databases."],"tags":["auth","next-auth","user","platform"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}