next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

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

Open tbrundige opened this issue 1 year ago • 3 comments

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 avatar May 26 '24 06:05 tbrundige

Can confirm the same behavior

oceandrama avatar Sep 05 '24 09:09 oceandrama

Can confirm this behaviour too

x2764tech avatar Oct 03 '24 14:10 x2764tech

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 avatar Oct 03 '24 15:10 x2764tech

Can confirm the same behavior

hilia avatar Mar 26 '25 07:03 hilia