[GH-ISSUE #5107] [bug]: GitHub login fails with unique constraint failed for provider and providerAccountId #1942

Closed
opened 2026-03-16 22:31:11 +03:00 by kerem · 3 comments
Owner

Originally created by @nitobuendia on GitHub (May 29, 2025).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5107

Is there an existing issue for this?

  • I have searched existing issues and this bug hasn't been reported yet

Current behavior

I have Hoppscotch self-hosted on a custom domain. It has been working well in the past.

Today, when I tried to login using GitHub, it failed. (See steps to reproduce).

The URL redirected to: https://<backend>/v1/auth/github/callback?code=<code>&state=<state>

which simply remplied wtih the following JSON:

{"statusCode":500,"message":"Internal server error"}

I think I had this issue before and was able to fix it - but (1) I don't remember how, and (2) it feels too recurrent now.

Steps to reproduce

  1. (Optional) Open Incognito Mode, to avoid cookie issues.
  2. Go to the main Hoppscotch instance, on my custom domain.
  3. Click Login.
  4. Click "Continue with GitHub"
  5. It redirects to the /v1/auth/github/callback with the aforementioned error.

Logs and Screenshots

Looking at the logs, we can get some more detail:

Backend Server | [Nest] 42  - 05/29/2025, 2:36:27 AM   ERROR [ExceptionsHandler] 

Backend Server | Invalid `this.prisma.user.create()` invocation in

Backend Server | /dist/backend/dist/user/user.service.js:113:52

Backend Server | 

Backend Server |   110 async createUserSSO(accessTokenSSO, refreshTokenSSO, profile) {

Backend Server |   111     const userDisplayName = !profile.displayName ? null : profile.displayName;

Backend Server |   112     const userPhotoURL = !profile.photos ? null : profile.photos[0].value;

Backend Server |113     const createdUser = await this.prisma.user.create(

Backend Server | Unique constraint failed on the fields: (`provider`,`providerAccountId`)

Backend Server | PrismaClientKnownRequestError: 

Backend Server | Invalid `this.prisma.user.create()` invocation in

Backend Server | /dist/backend/dist/user/user.service.js:113:52

Backend Server | 

Backend Server |   110 async createUserSSO(accessTokenSSO, refreshTokenSSO, profile) {

Backend Server |   111     const userDisplayName = !profile.displayName ? null : profile.displayName;

Backend Server |   112     const userPhotoURL = !profile.photos ? null : profile.photos[0].value;

Backend Server |113     const createdUser = await this.prisma.user.create(

Backend Server | Unique constraint failed on the fields: (`provider`,`providerAccountId`)

Backend Server |     at Mn.handleRequestError (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:121:7753)

Backend Server |     at Mn.handleAndLogRequestError (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:121:7061)

Backend Server |     at Mn.request (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:121:6745)

Backend Server |     at async l (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:130:9633)

Backend Server |     at async UserService.createUserSSO (/dist/backend/dist/user/user.service.js:113:29)

Backend Server |     at async GithubStrategy.validate (/dist/backend/dist/auth/strategies/github.strategy.js:37:33)

Backend Server |     at async GithubStrategy.callback [as _verify] (/dist/backend/node_modules/.pnpm/@nestjs+passport@10.0.3_@nestjs+common@10.4.16_class-transformer@0.5.1_class-validator@_972aa39c941543fe8e9de55b2cefd6f8/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:11:44)

Looking at the Postgres database, and the Account table, there are 3 users:

  • 2 are provider=magic and have different providerAccountId (i.e. different emails)
  • only 1 is provider=github and the id is therefore unique.
  • for all 3 users, id is different, userId is different, providerAccountId is different.
  • only github has a providerAccessToken
  • the data for github looks correct

I feel it might be trying to create a new account instead of using the existing one. I am not sure if this might be related to the client id / secret or something else. I am not sure how to troubleshoot since the error is throwing me a bit off.

Environment

Production

Hoppscotch Version

Self-hosted

Interceptor

Not Applicable - Issue not related to network requests

Browsers Affected

Chrome, Not browser-specific

Operating System

MacOS

Additional Information

  • Self Hosted: v2025.4.2
Originally created by @nitobuendia on GitHub (May 29, 2025). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5107 ### Is there an existing issue for this? - [x] I have searched existing issues and this bug hasn't been reported yet ### Current behavior I have Hoppscotch self-hosted on a custom domain. It has been working well in the past. Today, when I tried to login using GitHub, it failed. (See steps to reproduce). The URL redirected to: `https://<backend>/v1/auth/github/callback?code=<code>&state=<state>` which simply remplied wtih the following JSON: ```json {"statusCode":500,"message":"Internal server error"} ``` I think I had this issue before and was able to fix it - but (1) I don't remember how, and (2) it feels too recurrent now. ### Steps to reproduce 1. (Optional) Open Incognito Mode, to avoid cookie issues. 2. Go to the main Hoppscotch instance, on my custom domain. 3. Click Login. 4. Click "Continue with GitHub" 5. It redirects to the <backend>/v1/auth/github/callback with the aforementioned error. ### Logs and Screenshots Looking at the logs, we can get some more detail: ```shell Backend Server | [Nest] 42 - 05/29/2025, 2:36:27 AM ERROR [ExceptionsHandler] Backend Server | Invalid `this.prisma.user.create()` invocation in Backend Server | /dist/backend/dist/user/user.service.js:113:52 Backend Server | Backend Server | 110 async createUserSSO(accessTokenSSO, refreshTokenSSO, profile) { Backend Server | 111 const userDisplayName = !profile.displayName ? null : profile.displayName; Backend Server | 112 const userPhotoURL = !profile.photos ? null : profile.photos[0].value; Backend Server | → 113 const createdUser = await this.prisma.user.create( Backend Server | Unique constraint failed on the fields: (`provider`,`providerAccountId`) Backend Server | PrismaClientKnownRequestError: Backend Server | Invalid `this.prisma.user.create()` invocation in Backend Server | /dist/backend/dist/user/user.service.js:113:52 Backend Server | Backend Server | 110 async createUserSSO(accessTokenSSO, refreshTokenSSO, profile) { Backend Server | 111 const userDisplayName = !profile.displayName ? null : profile.displayName; Backend Server | 112 const userPhotoURL = !profile.photos ? null : profile.photos[0].value; Backend Server | → 113 const createdUser = await this.prisma.user.create( Backend Server | Unique constraint failed on the fields: (`provider`,`providerAccountId`) Backend Server | at Mn.handleRequestError (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:121:7753) Backend Server | at Mn.handleAndLogRequestError (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:121:7061) Backend Server | at Mn.request (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:121:6745) Backend Server | at async l (/dist/backend/node_modules/.pnpm/@prisma+client@5.20.0_prisma@5.20.0/node_modules/@prisma/client/runtime/library.js:130:9633) Backend Server | at async UserService.createUserSSO (/dist/backend/dist/user/user.service.js:113:29) Backend Server | at async GithubStrategy.validate (/dist/backend/dist/auth/strategies/github.strategy.js:37:33) Backend Server | at async GithubStrategy.callback [as _verify] (/dist/backend/node_modules/.pnpm/@nestjs+passport@10.0.3_@nestjs+common@10.4.16_class-transformer@0.5.1_class-validator@_972aa39c941543fe8e9de55b2cefd6f8/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:11:44) ``` Looking at the Postgres database, and the Account table, there are 3 users: - 2 are `provider=magic` and have different providerAccountId (i.e. different emails) - only 1 is `provider=github` and the id is therefore unique. - for all 3 users, id is different, userId is different, providerAccountId is different. - only github has a providerAccessToken - the data for github looks correct I feel it might be trying to create a new account instead of using the existing one. I am not sure if this might be related to the client id / secret or something else. I am not sure how to troubleshoot since the error is throwing me a bit off. ### Environment Production ### Hoppscotch Version Self-hosted ### Interceptor Not Applicable - Issue not related to network requests ### Browsers Affected Chrome, Not browser-specific ### Operating System MacOS ### Additional Information - Self Hosted: v2025.4.2
kerem 2026-03-16 22:31:11 +03:00
Author
Owner

@mirarifhasan commented on GitHub (May 30, 2025):

Hi @nitobuendia,

To resolve the error, you could delete the entry from the account table where provider = 'github'.

However, let's hold off on that for now and try to identify the root cause first. Could you please try the following:

We've only been able to reproduce this issue when the email was manually updated in the user table via SQL or similar methods. If you haven’t done that, please try logging in again using GitHub SSO with the same email that’s linked (via the foreign key relationship) to the existing provider = 'github' account.

Let me know how it goes or if you notice any new entries in the account table.

<!-- gh-comment-id:2922478955 --> @mirarifhasan commented on GitHub (May 30, 2025): Hi @nitobuendia, To resolve the error, you could delete the entry from the `account` table where `provider = 'github'`. However, let's hold off on that for now and try to identify the root cause first. Could you please try the following: We've only been able to reproduce this issue when the email was manually updated in the user table via SQL or similar methods. If you haven’t done that, please try logging in again using GitHub SSO with the same **email** that’s linked (via the foreign key relationship) to the existing `provider = 'github'` account. Let me know how it goes or if you notice any new entries in the `account` table.
Author
Owner

@mirarifhasan commented on GitHub (Jul 21, 2025):

Closing this issue as the solution has been provided. Feel free to reopen if you're still experiencing problems after trying the suggested fix.

<!-- gh-comment-id:3095181569 --> @mirarifhasan commented on GitHub (Jul 21, 2025): Closing this issue as the solution has been provided. Feel free to reopen if you're still experiencing problems after trying the suggested fix.
Author
Owner

@nitobuendia commented on GitHub (Aug 5, 2025):

Hi @mirarifhasan - I missed this. The application started working again without any changes from my side. Hence, I didn't need to follow these steps, but thank you for sharing and I will try this if it happens again.

FWIW, I had made changes to the table once to update the providerAccessToken, due to a different error back then. Nothing else was changed and it worked ever since. However, it would align to what you're mentioning somehow.

Thank you!

<!-- gh-comment-id:3155201605 --> @nitobuendia commented on GitHub (Aug 5, 2025): Hi @mirarifhasan - I missed this. The application started working again without any changes from my side. Hence, I didn't need to follow these steps, but thank you for sharing and I will try this if it happens again. FWIW, I had made changes to the table once to update the `providerAccessToken`, due to a different error back then. Nothing else was changed and it worked ever since. However, it would align to what you're mentioning somehow. Thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#1942
No description provided.