feat(MED-85): create customer group for company account in Medusa

This commit is contained in:
2025-08-25 11:51:12 +03:00
parent 5108087cc5
commit 89d6035151
8 changed files with 109 additions and 4 deletions

View File

@@ -281,6 +281,7 @@ export type Database = {
primary_owner_user_id: string
public_data: Json
slug: string | null
medusa_account_id: string | null
updated_at: string | null
updated_by: string | null
}
@@ -302,6 +303,7 @@ export type Database = {
primary_owner_user_id?: string
public_data?: Json
slug?: string | null
medusa_account_id?: string | null
updated_at?: string | null
updated_by?: string | null
}
@@ -323,6 +325,7 @@ export type Database = {
primary_owner_user_id?: string
public_data?: Json
slug?: string | null
medusa_account_id?: string | null
updated_at?: string | null
updated_by?: string | null
}

View File

@@ -20,15 +20,20 @@ export function useSignInWithEmailPassword() {
const identities = user?.identities ?? [];
if (identities.length === 0) {
throw new Error('User already registered');
throw new Error('Invalid user');
}
if ('email' in credentials) {
try {
await medusaLoginOrRegister({
const medusaAccountId = await medusaLoginOrRegister({
email: credentials.email,
password: credentials.password,
});
await client
.schema('medreport').from('accounts')
.update({ medusa_account_id: medusaAccountId })
.eq('primary_owner_user_id', user.id)
.eq('is_personal_account', true);
} catch (error) {
await client.auth.signOut();
throw error;

View File

@@ -39,10 +39,15 @@ export function useSignUpWithEmailAndPassword() {
if ('email' in credentials) {
try {
await medusaLoginOrRegister({
const medusaAccountId = await medusaLoginOrRegister({
email: credentials.email,
password: credentials.password,
});
await client
.schema('medreport').from('accounts')
.update({ medusa_account_id: medusaAccountId })
.eq('primary_owner_user_id', user!.id)
.eq('is_personal_account', true);
} catch (error) {
await client.auth.signOut();
throw error;