feat: proper redirect handling

This commit is contained in:
2025-05-29 14:17:09 +02:00
parent 8364a8e9ec
commit 807d7538a0
10 changed files with 106 additions and 53 deletions

View File

@ -22,7 +22,10 @@ export interface IAuthState {
loadAccounts: () => Promise<void>;
updateActiveAccount: (account: LocalAccount) => Promise<void>;
deleteActiveAccount: () => Promise<void>;
authenticate: () => Promise<void>;
requireSignIn: () => void;
signOut: () => void;
}
@ -79,23 +82,30 @@ export const useAuth = create<IAuthState>((set, get) => ({
if (!active) {
set({ signInRequired: true });
}
} else {
const account = accounts.find((acc) => acc.accountId === active);
const account = accounts.find((acc) => acc.accountId === active);
if (!account) {
resetActiveAccount();
set({ signInRequired: true });
if (!account) {
resetActiveAccount();
set({ signInRequired: true });
} else {
set({ activeAccount: account });
}
}
set({
activeAccount: account,
accounts,
loadingAccounts: false,
hasLoadedAccounts: true,
});
},
deleteActiveAccount: async () => {
resetActiveAccount();
set({ activeAccount: null });
get().loadAccounts();
},
authenticate: async () => {
const { authenticating } = get();
if (authenticating) return;