feat(MED-100): create medusa store account for user
This commit is contained in:
@@ -2,6 +2,7 @@ import type { SignInWithPasswordCredentials } from '@supabase/supabase-js';
|
||||
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { medusaLoginOrRegister } from '../../../features/medusa-storefront/src/lib/data/customer';
|
||||
import { useSupabase } from './use-supabase';
|
||||
|
||||
export function useSignInWithEmailPassword() {
|
||||
@@ -18,11 +19,22 @@ export function useSignInWithEmailPassword() {
|
||||
const user = response.data?.user;
|
||||
const identities = user?.identities ?? [];
|
||||
|
||||
// if the user has no identities, it means that the email is taken
|
||||
if (identities.length === 0) {
|
||||
throw new Error('User already registered');
|
||||
}
|
||||
|
||||
if ('email' in credentials) {
|
||||
try {
|
||||
await medusaLoginOrRegister({
|
||||
email: credentials.email,
|
||||
password: credentials.password,
|
||||
});
|
||||
} catch (error) {
|
||||
await client.auth.signOut();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { useSupabase } from './use-supabase';
|
||||
import { medusaLoginOrRegister } from '../../../features/medusa-storefront/src/lib/data/customer';
|
||||
|
||||
interface Credentials {
|
||||
personalCode: string;
|
||||
@@ -41,6 +42,18 @@ export function useSignUpWithEmailAndPassword() {
|
||||
throw new Error('User already registered');
|
||||
}
|
||||
|
||||
if ('email' in credentials) {
|
||||
try {
|
||||
await medusaLoginOrRegister({
|
||||
email: credentials.email,
|
||||
password: credentials.password,
|
||||
});
|
||||
} catch (error) {
|
||||
await client.auth.signOut();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user