Strava provider returns Int for providerAccountId but Prisma adapter is expecting a String
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.
Can confirm the same behavior
Can confirm this behaviour too
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,
};
},
}),
Can confirm the same behavior