Add OAuth sign-in method to AuthContext
cgen-1e41a31a8c764e05a4b9b1ef88a3f9e1
This commit is contained in:
parent
80f2285943
commit
adefe127ee
1 changed files with 32 additions and 0 deletions
|
|
@ -171,6 +171,38 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||
}
|
||||
};
|
||||
|
||||
const signInWithOAuth = async (provider: 'github' | 'google') => {
|
||||
if (!isSupabaseConfigured) {
|
||||
aethexToast.warning({
|
||||
title: 'Demo Mode',
|
||||
description: 'OAuth login requires Supabase to be configured. Currently in demo mode.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { data, error } = await supabase.auth.signInWithOAuth({
|
||||
provider,
|
||||
options: {
|
||||
redirectTo: `${window.location.origin}/dashboard`,
|
||||
},
|
||||
});
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
aethexToast.success({
|
||||
title: 'Redirecting...',
|
||||
description: `Signing in with ${provider}`
|
||||
});
|
||||
} catch (error: any) {
|
||||
aethexToast.error({
|
||||
title: `${provider} sign in failed`,
|
||||
description: error.message
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const signOut = async () => {
|
||||
if (!isSupabaseConfigured) {
|
||||
setUser(null);
|
||||
|
|
|
|||
Loading…
Reference in a new issue