Supabase google ouath doesnt work on production
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Hello everyone! I have an application setup and I was trying to implement the google authentication option. I was following the docs and it worked out all fine on localhost however on production I'm not getting redirected to the URL.
This is my authentication code:
This is my authentication config:
On localhost it works fine and I got redirected.
Also in production I got this weird access_token query in the URL which I dont get locally.
One more thing to mention is that on the login page I have a useEffect setup to redirect the user because it doesnt happen automatically:
Thanks!
This is my authentication code:
export async function googleLogin(
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
supabase: SupabaseClient<any, "public", any>,
router: any
) {
event.preventDefault();
// Attempt to sign in with Google OAuth
const { data, error } = await supabase.auth.signInWithOAuth({
provider: "google",
options: {
redirectTo: `${process.env.NEXT_PUBLIC_CLIENT_URL}/dashboard`,
},
});
// If there's an error during the sign-in process, log it to the console
if (error) {
console.log(error);
return;
}
// If sign-in is successful, the user will be redirected to the "/dashboard" route.
// The redirection happens automatically due to the options set in the `signInWithOAuth` call.
}This is my authentication config:
On localhost it works fine and I got redirected.
Also in production I got this weird access_token query in the URL which I dont get locally.
One more thing to mention is that on the login page I have a useEffect setup to redirect the user because it doesnt happen automatically:
useEffect(() => {
supabase.auth.onAuthStateChange((event, session) => {
if (event == "SIGNED_IN") router.push("/dashboard");
console.log("event, session");
});
}, []);Thanks!
1 Reply
Did you set your environment variables in vercel?