Files
medreport_mrb2b/packages/supabase/src/hooks/use-sign-in-with-provider.ts
2025-09-08 01:02:10 +03:00

32 lines
755 B
TypeScript

import type { SignInWithOAuthCredentials } from '@supabase/supabase-js';
import { useMutation } from '@tanstack/react-query';
import { useSupabase } from './use-supabase';
export function useSignInWithProvider() {
const client = useSupabase();
const mutationKey = ['auth', 'sign-in-with-provider'];
const mutationFn = async (credentials: SignInWithOAuthCredentials) => {
const response = await client.auth.signInWithOAuth({
...credentials,
options: {
...credentials.options,
redirectTo: `${window.location.origin}/auth/callback`,
},
});
if (response.error) {
throw response.error.message;
}
return response.data;
};
return useMutation({
mutationFn,
mutationKey,
});
}