next-auth: Unexpected token d in JSON at position 0 in Vercel Production Environment
Environment
System:
OS: macOS 12.3
CPU: (10) arm64 Apple M1 Pro
Memory: 63.27 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.12.1 - /usr/local/bin/node
npm: 8.19.2 - /usr/local/bin/npm
Browsers:
Chrome: 107.0.5304.121
Safari: 15.4
Reproduction URL
Private repo
Describe the issue
When I try to log into my Nextjs app deployed on Vercel, I get redirected to the error page .../api/auth/signin?error=OAuthCallback
Stack trace:
2023-02-11T01:23:14.775Z 1e150ed2-eefe-42fe-af99-e6a6cfab3ddf ERROR [next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error Unexpected token d in JSON at position 0 {
error: SyntaxError: Unexpected token d in JSON at position 0
at JSON.parse (<anonymous>)
at IncomingMessage.get (/var/task/node_modules/openid-client/lib/helpers/request.js:153:30)
at processResponse (/var/task/node_modules/openid-client/lib/helpers/process_response.js:55:25)
at Issuer.discover (/var/task/node_modules/openid-client/lib/issuer.js:152:20)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async openidClient (/var/task/node_modules/next-auth/core/lib/oauth/client.js:16:14)
at async oAuthCallback (/var/task/node_modules/next-auth/core/lib/oauth/callback.js:85:20)
at async Object.callback (/var/task/node_modules/next-auth/core/routes/callback.js:52:11)
at async AuthHandler (/var/task/node_modules/next-auth/core/index.js:201:28)
at async NextAuthHandler (/var/task/node_modules/next-auth/next/index.js:24:19) {
name: 'OAuthCallbackError',
code: undefined
},
providerId: 'google',
message: 'Unexpected token d in JSON at position 0'
}
Versions on package.json:
{
...
"next": "13.1.6",
"next-auth": "^4.19.2",
...
}
The openid-client version in my node_modules is 5.4.0.
The auth options in my app:
export const authOptions = {
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
})
],
callbacks: {
async session({ session, token, user }) {
session.user.id = user.id
return session
},
}
}
import NextAuth from "next-auth"
import { authOptions } from "../../../lib/auth"
export default NextAuth(authOptions)
Confirmed the env variables are all set correctly in Vercel

How to reproduce
Try to login to my app, redirects me into the Error page
This does not occur on my local environment, only on Vercel deployed environment.
Expected behavior
Try to login to my app, does not redirect me to the Error page
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 25
Hi,
We reverted a change that we believe should fix the problem. Please redeploy your app, and let us know If you are still facing this issue: https://vercel.com/help
Hi everyone,
My name is Swarnava and I work on Vercel Customer Success team. We are investigating this issue now.
Thought it was just me, this has been driving me insane for the last few hours.
I have the exact same Issue.
i have no oauth or users, but my project no deploed (nextjs, prisma, mongodb) i have errors in pages: SyntaxError: Unexpected token < in JSON at position 0
Vercel is aware and looking into it: https://twitter.com/leeerob/status/1624237510900563971?s=20&t=fNKQ1tBh_RKQhxmGSvMhAg
Oooh. It must be something they are packaging in the new code. Thanks, @felipap. It worked for us by using rollback vs. redeploy.
Yep, seems to be a larger issue with Vercel. Longer thread here: https://github.com/nextauthjs/next-auth/issues/6685