reactjsoauthsupabase

Using Google Oauth with supabase, can't login with different account


I am using supabase Oauth Google provider in one of my projects, after the initial login with one of my accounts, when i logout and try to login again using google, it uses the same old account to login, instead of asking to select a different one.

This is the hook responsible for handling the login process

import { Provider } from "@supabase/supabase-js";
import { useState } from "react";
import supabase from "../utils/database";

const useLoginWithOAuth = () => {

   
    const [error,setError] = useState(null)
    const loginOauth = async (provider: Provider) => {
      try {
        const { data, error } = await supabase.auth.signInWithOAuth({
          provider: provider,
          options: {
            redirectTo: "http://localhost:5173/chatroom",
          },
        });

        if (error) {
          throw Error(error.message);
        } else {
            setError(null);
          return data;
        }
      } catch (error: any) {
        setError(error);
      }
    };
    

    return {error,loginOauth}
}

export default useLoginWithOAuth;

this is the logout hook

import { useSetAtom } from "jotai";
import { useState } from "react";
import { session, user } from "../main";
import supabase from "../utils/database";

const useLogout = () => {
    const [error, setError] = useState<{} | null>(null)
    const setSession = useSetAtom(session)
    const setUserData = useSetAtom(user)
    const logout = async () => {
        
        const { error } = await supabase.auth.signOut({scope:'global',});
        if (error) {
            setError(error.message)
        }
        setSession(null)
        setUserData(null)
    }

    return {logout,error}
}


export default useLogout

Solution

  • I fixed the issue by removing the {scope:'global',} option from logout hook.

    This should help