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 · 3 comments · May be fixed by #11960
Open

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

tbrundige opened this issue May 26, 2024 · 3 comments · May be fixed by #11960
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
@oceandrama
Copy link

Can confirm the same behavior

@x2764tech
Copy link

Can confirm this behaviour too

@x2764tech
Copy link

FWIW, instantiating your Strava provider like this is a work-around:

    Strava({
        authorization: { params: { scope: "activity:read_all" } },
        profile(profile) {
          return {
            id: String(profile.id),
            name: `${profile.firstname} ${profile.lastname}`,
            email: null,
            image: profile.profile,
          };
        },
      }),

x2764tech added a commit to x2764tech/next-auth that referenced this issue Oct 3, 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

Successfully merging a pull request may close this issue.

3 participants