bjw
bjw
BABetter Auth
Created by 7ocomotive on 3/14/2025 in #help
ERROR [Better Auth]: State Mismatch. Verification not found
i have the same problem. It looks like the errorURL doesn't work. I use the server action to sign in with google oauth and onAPIError was also defined. If the oauth verification token expires, better-auth redirects me to the api/auth/error route. I just cant deactivate this standard error page. Hi @7ocomotive did you solve this problem? In the production the user should never see this standard error page from better-auth.
// sign-in.ts
export const signInGoogle = async () => {
const data = await auth.api.signInSocial({
body: {
provider: 'google',
callbackURL: authSuccessRedirectRoute,
errorCallbackURL: '/auth-error',
newUserCallbackURL: authSuccessRedirectRoute,
},
});
redirect(data.url as string);
};
// sign-in.ts
export const signInGoogle = async () => {
const data = await auth.api.signInSocial({
body: {
provider: 'google',
callbackURL: authSuccessRedirectRoute,
errorCallbackURL: '/auth-error',
newUserCallbackURL: authSuccessRedirectRoute,
},
});
redirect(data.url as string);
};
// lib/auth.ts
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
}),
onAPIError: {
throw: true, // false doesn't work also
onError: (error, ctx) => {
console.log('api error!'); // i can't see this log on server side
},
errorURL: '/auth-errorx',
},
socialProviders: {
github: {
clientId: process.env.AUTH_GITHUB_ID!,
clientSecret: process.env.AUTH_GITHUB_SECRET!,
},
google: {
clientId: process.env.AUTH_GOOGLE_ID!,
clientSecret: process.env.AUTH_GOOGLE_SECRET!,
},
}
}
// lib/auth.ts
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: 'pg',
}),
onAPIError: {
throw: true, // false doesn't work also
onError: (error, ctx) => {
console.log('api error!'); // i can't see this log on server side
},
errorURL: '/auth-errorx',
},
socialProviders: {
github: {
clientId: process.env.AUTH_GITHUB_ID!,
clientSecret: process.env.AUTH_GITHUB_SECRET!,
},
google: {
clientId: process.env.AUTH_GOOGLE_ID!,
clientSecret: process.env.AUTH_GOOGLE_SECRET!,
},
}
}
6 replies