prettier fix
This commit is contained in:
@@ -21,7 +21,7 @@ export function createAuthCallbackService(client: SupabaseClient) {
|
||||
* @description Service for handling auth callbacks in Supabase
|
||||
*/
|
||||
class AuthCallbackService {
|
||||
constructor(private readonly client: SupabaseClient) { }
|
||||
constructor(private readonly client: SupabaseClient) {}
|
||||
|
||||
/**
|
||||
* @name verifyTokenHash
|
||||
@@ -131,10 +131,13 @@ class AuthCallbackService {
|
||||
* @description Exchanges the auth code for a session and redirects the user to the next page or an error page
|
||||
* @param authCode
|
||||
*/
|
||||
async exchangeCodeForSession(authCode: string): Promise<{
|
||||
isSuccess: boolean;
|
||||
user: User;
|
||||
} | ErrorURLParameters> {
|
||||
async exchangeCodeForSession(authCode: string): Promise<
|
||||
| {
|
||||
isSuccess: boolean;
|
||||
user: User;
|
||||
}
|
||||
| ErrorURLParameters
|
||||
> {
|
||||
let user: User;
|
||||
try {
|
||||
const { data, error } =
|
||||
@@ -181,8 +184,10 @@ class AuthCallbackService {
|
||||
* Check if user is from Keycloak provider
|
||||
*/
|
||||
private isKeycloakUser(user: any): boolean {
|
||||
return user?.app_metadata?.provider === 'keycloak' ||
|
||||
user?.app_metadata?.providers?.includes('keycloak');
|
||||
return (
|
||||
user?.app_metadata?.provider === 'keycloak' ||
|
||||
user?.app_metadata?.providers?.includes('keycloak')
|
||||
);
|
||||
}
|
||||
|
||||
private async setupMedusaUserForKeycloak(user: any): Promise<void> {
|
||||
@@ -202,11 +207,16 @@ class AuthCallbackService {
|
||||
.single();
|
||||
|
||||
if (fetchError && fetchError.code !== 'PGRST116') {
|
||||
console.error('Error fetching account data for Keycloak user:', fetchError);
|
||||
console.error(
|
||||
'Error fetching account data for Keycloak user:',
|
||||
fetchError,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const { medusaLoginOrRegister } = await import('../../features/medusa-storefront/src/lib/data/customer');
|
||||
const { medusaLoginOrRegister } = await import(
|
||||
'../../features/medusa-storefront/src/lib/data/customer'
|
||||
);
|
||||
const medusaAccountId = await medusaLoginOrRegister({
|
||||
email: user.email,
|
||||
supabaseUserId: user.id,
|
||||
@@ -215,7 +225,10 @@ class AuthCallbackService {
|
||||
});
|
||||
|
||||
const currentMedusaAccountId = accountData?.medusa_account_id;
|
||||
if (!currentMedusaAccountId || currentMedusaAccountId !== medusaAccountId) {
|
||||
if (
|
||||
!currentMedusaAccountId ||
|
||||
currentMedusaAccountId !== medusaAccountId
|
||||
) {
|
||||
const { error: updateError } = await this.client
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
@@ -228,12 +241,21 @@ class AuthCallbackService {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Successfully set up Medusa account for Keycloak user:', medusaAccountId);
|
||||
console.log(
|
||||
'Successfully set up Medusa account for Keycloak user:',
|
||||
medusaAccountId,
|
||||
);
|
||||
} else {
|
||||
console.log('Keycloak user already has Medusa account:', accountData.medusa_account_id);
|
||||
console.log(
|
||||
'Keycloak user already has Medusa account:',
|
||||
accountData.medusa_account_id,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error setting up Medusa account for Keycloak user:', error);
|
||||
console.error(
|
||||
'Error setting up Medusa account for Keycloak user:',
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,15 +6,20 @@ import { z } from 'zod';
|
||||
export function getSupabaseClientKeys() {
|
||||
return z
|
||||
.object({
|
||||
url: z.string({
|
||||
error: `Please provide the variable NEXT_PUBLIC_SUPABASE_URL`,
|
||||
})
|
||||
.describe(`This is the URL of your hosted Supabase instance. Please provide the variable NEXT_PUBLIC_SUPABASE_URL.`),
|
||||
url: z
|
||||
.string({
|
||||
error: `Please provide the variable NEXT_PUBLIC_SUPABASE_URL`,
|
||||
})
|
||||
.describe(
|
||||
`This is the URL of your hosted Supabase instance. Please provide the variable NEXT_PUBLIC_SUPABASE_URL.`,
|
||||
),
|
||||
anonKey: z
|
||||
.string({
|
||||
error: `Please provide the variable NEXT_PUBLIC_SUPABASE_ANON_KEY`,
|
||||
})
|
||||
.describe(`This is the anon key provided by Supabase. It is a public key used client-side. Please provide the variable NEXT_PUBLIC_SUPABASE_ANON_KEY.`)
|
||||
.describe(
|
||||
`This is the anon key provided by Supabase. It is a public key used client-side. Please provide the variable NEXT_PUBLIC_SUPABASE_ANON_KEY.`,
|
||||
)
|
||||
.min(1),
|
||||
})
|
||||
.parse({
|
||||
|
||||
@@ -31,7 +31,8 @@ export function useSignInWithEmailPassword() {
|
||||
isDevPasswordLogin: true,
|
||||
});
|
||||
await client
|
||||
.schema('medreport').from('accounts')
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.update({ medusa_account_id: medusaAccountId })
|
||||
.eq('primary_owner_user_id', user.id)
|
||||
.eq('is_personal_account', true);
|
||||
|
||||
@@ -9,7 +9,9 @@ export function useSignOut() {
|
||||
mutationFn: async () => {
|
||||
try {
|
||||
try {
|
||||
const { medusaLogout } = await import('../../../features/medusa-storefront/src/lib/data/customer');
|
||||
const { medusaLogout } = await import(
|
||||
'../../../features/medusa-storefront/src/lib/data/customer'
|
||||
);
|
||||
await medusaLogout(undefined, false);
|
||||
} catch (medusaError) {
|
||||
console.warn('Medusa logout failed or not available:', medusaError);
|
||||
|
||||
@@ -46,7 +46,8 @@ export function useSignUpWithEmailAndPassword() {
|
||||
isDevPasswordLogin: true,
|
||||
});
|
||||
await client
|
||||
.schema('medreport').from('accounts')
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.update({ medusa_account_id: medusaAccountId })
|
||||
.eq('primary_owner_user_id', user!.id)
|
||||
.eq('is_personal_account', true);
|
||||
|
||||
Reference in New Issue
Block a user