|
1 | 1 | import { useLocalStorage, useSessionStorage, StorageSerializers } from '@vueuse/core' |
2 | 2 | import { useCookies } from '@vueuse/integrations/useCookies' |
3 | | -import { clear as clearCart, fetchCustomerCart, linkUserToCart, cart } from './useCart' |
| 3 | +import { clear as clearCart, loggedIn as cartLoginHandler, cart } from './useCart' |
4 | 4 | import { clear as clearOrder } from './useOrder' |
5 | 5 | import { computed, watch } from 'vue' |
6 | 6 | import Jwt from '../jwt' |
@@ -61,7 +61,11 @@ export const refresh = async function () { |
61 | 61 |
|
62 | 62 | return (currentRefresh = (async function () { |
63 | 63 | try { |
| 64 | + const oldEmail = userStorage.value?.email |
64 | 65 | userStorage.value = (await magentoGraphQL(`{ customer { ${config.queries.customer} } }`))?.data?.customer |
| 66 | + if (oldEmail !== userStorage.value?.email) { |
| 67 | + await loggedIn() |
| 68 | + } |
65 | 69 | } catch (error) { |
66 | 70 | if (error instanceof SessionExpired) { |
67 | 71 | await clear() |
@@ -141,14 +145,12 @@ export const login = async function (email, password) { |
141 | 145 |
|
142 | 146 | export const loginByToken = async function (customerToken) { |
143 | 147 | token.value = customerToken |
| 148 | + await refresh() |
| 149 | +} |
144 | 150 |
|
145 | | - if (mask.value) { |
146 | | - await linkUserToCart() |
147 | | - } else { |
148 | | - await fetchCustomerCart() |
149 | | - } |
150 | | - |
| 151 | +export const loggedIn = async function () { |
151 | 152 | window.app.$emit('logged-in') |
| 153 | + await cartLoginHandler() |
152 | 154 | } |
153 | 155 |
|
154 | 156 | export const logout = async function () { |
|
0 commit comments