This commit is contained in:
@@ -12,6 +12,8 @@ const emptyPhoneState = () => ({
|
||||
const savedPhoneState = uni.getStorageSync(PHONE_STATE_KEY);
|
||||
const token = uni.getStorageSync('token') || '';
|
||||
const identifier = uni.getStorageSync('identifier') || '';
|
||||
const isOAuthCallback = typeof window !== 'undefined' && typeof sessionStorage !== 'undefined' &&
|
||||
!!new URLSearchParams(window.location.search).get('code') && !!sessionStorage.getItem('assetToken');
|
||||
const phoneState = savedPhoneState?.token === token && savedPhoneState?.identifier === identifier && token
|
||||
? {
|
||||
customerPhone: typeof savedPhoneState.customerPhone === 'string' ? savedPhoneState.customerPhone : null,
|
||||
@@ -25,6 +27,7 @@ const state = reactive({
|
||||
token,
|
||||
assetToken: '',
|
||||
identifier,
|
||||
loginPending: isOAuthCallback,
|
||||
...phoneState,
|
||||
phoneRevision: 0,
|
||||
isDevice: false,
|
||||
@@ -36,6 +39,7 @@ const state = reactive({
|
||||
});
|
||||
|
||||
export const useUserStore = () => {
|
||||
const setLoginPending = (pending) => { state.loginPending = pending === true; };
|
||||
const persistPhoneState = () => {
|
||||
uni.setStorageSync(PHONE_STATE_KEY, {
|
||||
token: state.token, identifier: state.identifier,
|
||||
@@ -111,6 +115,7 @@ export const useUserStore = () => {
|
||||
const clearUser = () => {
|
||||
resetContext();
|
||||
state.token = '';
|
||||
state.loginPending = false;
|
||||
state.assetToken = '';
|
||||
state.identifier = '';
|
||||
state.isDevice = false;
|
||||
@@ -124,6 +129,7 @@ export const useUserStore = () => {
|
||||
return {
|
||||
state,
|
||||
setToken,
|
||||
setLoginPending,
|
||||
setAssetToken,
|
||||
setIdentifier,
|
||||
setIsDevice,
|
||||
|
||||
Reference in New Issue
Block a user