Google Oauth SSR issue
Hello everyone, I have a project with hundreds of users and I gave a google auth feature which works for some people but not others because of a code exchange issue. The project runs on Next.js
Apparently if some users launch the auth from www.website.com instead of website.com it will fail to do the code exchange.
I have dragged this issue for the past month wihtout 100% success rate.
Here is my quite simple code :
},
});
if (error) {
console.error("Google OAuth error:", error);
}
if (data.url) {
redirect(data.url);
}
}
and
export async function getGoogleOAuthUrl() {
const supabase = await createClient();
const { data, error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
skipBrowserRedirect: true,
redirectTo:
},
});
if (error) {
console.error("Google OAuth error:", error);
}
return { url: data.url };
} `
error :
https://www.chatify.fr/auth/auth-code-error?error=session_exchange&description=code challenge does not match previously saved code verifier
or the usual : invalid request: both auth code and code verifier should be non-empty
what am I missing here ?
Apparently if some users launch the auth from www.website.com instead of website.com it will fail to do the code exchange.
I have dragged this issue for the past month wihtout 100% success rate.
Here is my quite simple code :
"use server"
export async function signInWithGoogle() {
const supabase = await createClient();
const { data, error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: https://chatify.fr/auth/callback`,},
});
if (error) {
console.error("Google OAuth error:", error);
}
if (data.url) {
redirect(data.url);
}
}
and
export async function getGoogleOAuthUrl() {
const supabase = await createClient();
const { data, error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
skipBrowserRedirect: true,
redirectTo:
https://chatify.fr/auth/callback,},
});
if (error) {
console.error("Google OAuth error:", error);
}
return { url: data.url };
} `
error :
https://www.chatify.fr/auth/auth-code-error?error=session_exchange&description=code challenge does not match previously saved code verifier
or the usual : invalid request: both auth code and code verifier should be non-empty
what am I missing here ?



L'application IA
L'application IA