Reputation: 43
I am trying to set up next-auth using a tutorial for authjs v5. I am getting this InvalidCheck error on Vercel: InvalidCheck: pkceCodeVerifier value could not be parsed. Read more at https://errors.authjs.dev#invalidcheck
while trying to sign up with Google for the very first time.
I am directed to the sign in page for Google, and the Oauth process seems to complete, before landing on the error page.
This results in a 504 error This Serverless Function has timed out.
Which then requires me to clear the storage and cookies before trying again.
I am using NextJS 15.
My code works perfectly on localhost though.
Here is my auth.ts:
import NextAuth from "next-auth"
import Google from "next-auth/providers/google"
import client from "@lib/db"
import User from "@models/user"
import { connectToDB } from "@utils/database"
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [Google],
callbacks:{
async session({session}){
const sessionUser = await User.findOne({ email: session.user.email })
// console.log("sessionUser", session)
if(sessionUser){
session.user.id = sessionUser.id
}
return session;
},
async signIn({ account, profile, user, credentials }) {
try {
await connectToDB();
// check if user already exists
const userExists = await User.findOne({ email: profile.email });
// if not, create a new document and save user in MongoDB
if (!userExists) {
await User.create({
email: profile.email,
username: profile.name.replace(" ", "").toLowerCase(),
image: profile.picture,
});
}
return true
} catch (error) {
console.log("Error checking if user exists: ", error.message);
return false
}
},
}
})
I've tried to follow steps for the PKCE code_verifier cookie was missing on upgrade
error. However, this did not seem to resolve my issue. Any help would be greatly appreicated.
Upvotes: 2
Views: 736