fix: avoid flash target page show
This commit is contained in:
@ -11,12 +11,15 @@ const AuthLayout = () => {
|
|||||||
|
|
||||||
const loadingAccounts = useAuth((state) => state.loadingAccounts);
|
const loadingAccounts = useAuth((state) => state.loadingAccounts);
|
||||||
const loadAccounts = useAuth((state) => state.loadAccounts);
|
const loadAccounts = useAuth((state) => state.loadAccounts);
|
||||||
|
const hasLoadedAccounts = useAuth((state) => state.hasLoadedAccounts);
|
||||||
|
|
||||||
const activeAccount = useAuth((state) => state.activeAccount);
|
const activeAccount = useAuth((state) => state.activeAccount);
|
||||||
|
|
||||||
const hasAccounts = useAuth((state) => state.accounts.length > 0);
|
const hasAccounts = useAuth((state) => state.accounts.length > 0);
|
||||||
|
|
||||||
const fetchingProfile = useAuth((state) => state.authenticating);
|
const authenticating = useAuth((state) => state.authenticating);
|
||||||
const authenticate = useAuth((state) => state.authenticate);
|
const authenticate = useAuth((state) => state.authenticate);
|
||||||
|
const hasAuthenticated = useAuth((state) => state.hasAuthenticated);
|
||||||
|
|
||||||
const signInRequired = useAuth((state) => state.signInRequired);
|
const signInRequired = useAuth((state) => state.signInRequired);
|
||||||
|
|
||||||
@ -32,20 +35,12 @@ const AuthLayout = () => {
|
|||||||
return true;
|
return true;
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
console.log({
|
|
||||||
isAuthPage,
|
|
||||||
loadingAccounts,
|
|
||||||
fetchingProfile,
|
|
||||||
connecting,
|
|
||||||
dbConnected,
|
|
||||||
});
|
|
||||||
|
|
||||||
const loading = useMemo(() => {
|
const loading = useMemo(() => {
|
||||||
if (isAuthPage) {
|
if (isAuthPage) {
|
||||||
return connecting;
|
return connecting;
|
||||||
}
|
}
|
||||||
return loadingAccounts || fetchingProfile || connecting;
|
return (!hasAuthenticated || !hasLoadedAccounts) || loadingAccounts || authenticating || connecting;
|
||||||
}, [connecting, fetchingProfile, isAuthPage, loadingAccounts]);
|
}, [isAuthPage, hasAuthenticated, hasLoadedAccounts, loadingAccounts, authenticating, connecting]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
connect();
|
connect();
|
||||||
|
@ -17,6 +17,9 @@ export interface IAuthState {
|
|||||||
accounts: LocalAccount[];
|
accounts: LocalAccount[];
|
||||||
signInRequired: boolean;
|
signInRequired: boolean;
|
||||||
|
|
||||||
|
hasAuthenticated: boolean;
|
||||||
|
hasLoadedAccounts: boolean;
|
||||||
|
|
||||||
loadAccounts: () => Promise<void>;
|
loadAccounts: () => Promise<void>;
|
||||||
updateActiveAccount: (account: LocalAccount) => Promise<void>;
|
updateActiveAccount: (account: LocalAccount) => Promise<void>;
|
||||||
authenticate: () => Promise<void>;
|
authenticate: () => Promise<void>;
|
||||||
@ -47,6 +50,9 @@ export const useAuth = create<IAuthState>((set, get) => ({
|
|||||||
loadingAccounts: false,
|
loadingAccounts: false,
|
||||||
signInRequired: false,
|
signInRequired: false,
|
||||||
|
|
||||||
|
hasAuthenticated: false,
|
||||||
|
hasLoadedAccounts: false,
|
||||||
|
|
||||||
updateActiveAccount: async (account) => {
|
updateActiveAccount: async (account) => {
|
||||||
set({ activeAccount: account });
|
set({ activeAccount: account });
|
||||||
|
|
||||||
@ -82,7 +88,12 @@ export const useAuth = create<IAuthState>((set, get) => ({
|
|||||||
set({ signInRequired: true });
|
set({ signInRequired: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
set({ activeAccount: account, accounts, loadingAccounts: false });
|
set({
|
||||||
|
activeAccount: account,
|
||||||
|
accounts,
|
||||||
|
loadingAccounts: false,
|
||||||
|
hasLoadedAccounts: true,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
authenticate: async () => {
|
authenticate: async () => {
|
||||||
@ -114,7 +125,7 @@ export const useAuth = create<IAuthState>((set, get) => ({
|
|||||||
// TODO: set error
|
// TODO: set error
|
||||||
console.log(err);
|
console.log(err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ authenticating: false });
|
set({ authenticating: false, hasAuthenticated: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user