Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strava provider returns Int for providerAccountId but Prisma adapter is expecting a String #11013

Open
tbrundige opened this issue May 26, 2024 · 0 comments
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@tbrundige
Copy link

tbrundige commented May 26, 2024

Adapter type

@auth/prisma-adapter

Environment

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 108.07 GB / 127.91 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.7.0 - ~\AppData\Roaming\npm\npm.CMD
    pnpm: 9.1.2 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (123.0.2420.97)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @auth/prisma-adapter: ^2.1.0 => 2.1.0
    next: 14.2.3 => 14.2.3
    next-auth: ^5.0.0-beta.18 => 5.0.0-beta.18
    react: ^18 => 18.3.1

Reproduction URL

https://github.com/tbrundige/authjs-adapter-issue

Describe the issue

When using the Strava provider with the Prisma adapter, when a user attempts to authenticate the following error occurs.

[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: PrismaClientValidationError:
Invalid `prisma.account.findUnique()` invocation:

{
  where: {
    provider_providerAccountId: {
      providerAccountId: 111122233,
                         ~~~~~~~~~
      provider: "strava"
    }
  },
  select: {
    user: true
  }
}

Argument `providerAccountId`: Invalid value provided. Expected String, provided Int.

While updating the schema.prisma to providerAccountId Int @map("provider_account_id") fixes the issue. I believe this will break other providers that are using a string and limit the project to only the Strava provider.

How to reproduce

Create/log in to a Strava account and create an API application to get a client id/secret.
Note: Once logged in to Strava go to this url www.strava.com/settings/api and grab the client/secret after creating the API application.

Clone the provided repo.
Populate the following values in .env in the root of the project

AUTH_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
AUTH_STRAVA_ID="<clientId>"
AUTH_STRAVA_SECRET="<secret>"
DATABASE_URL="<postgres connection string>"

Start/ensure the postgres database is running.
Run npm install && npm run dev
Open web browser to localhost:3000
Click "Signin with Strava"
Log in to Strava and you should be redirected to an AuthError page and the server should print out.

[auth][error] AdapterError:
[auth][cause]: PrismaClientValidationError:

Expected behavior

The user should be able to authenticate successfully .
Possible solution: check the type of the providerId from the response, convert the int to the string value and persist in the database as a string.

@tbrundige tbrundige added adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant