log out of medusa and reset cart on supabase logout
This commit is contained in:
@@ -127,7 +127,7 @@ export async function login(_currentState: unknown, formData: FormData) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function signout(countryCode: string) {
|
||||
export async function signout(countryCode?: string, shouldRedirect = true) {
|
||||
await sdk.auth.logout()
|
||||
|
||||
await removeAuthToken()
|
||||
@@ -140,7 +140,9 @@ export async function signout(countryCode: string) {
|
||||
const cartCacheTag = await getCacheTag("carts")
|
||||
revalidateTag(cartCacheTag)
|
||||
|
||||
redirect(`/${countryCode}/account`)
|
||||
if (shouldRedirect) {
|
||||
redirect(`/${countryCode!}/account`)
|
||||
}
|
||||
}
|
||||
|
||||
export async function transferCart() {
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { useSupabase } from './use-supabase';
|
||||
import { signout } from '../../../features/medusa-storefront/src/lib/data/customer';
|
||||
|
||||
export function useSignOut() {
|
||||
const client = useSupabase();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => {
|
||||
mutationFn: async () => {
|
||||
await signout(undefined, false);
|
||||
return client.auth.signOut();
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user