fix: can not enable workspace if not sign in (#4265)

Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
Qi
2023-09-08 15:41:07 +08:00
committed by GitHub
parent 81a3bcee4f
commit f9eea85577
9 changed files with 102 additions and 38 deletions
+25
View File
@@ -0,0 +1,25 @@
import { atom, useAtom } from 'jotai';
import { useCallback } from 'react';
export type OnceSignedInEvent = () => void;
export const onceSignedInEventsAtom = atom<OnceSignedInEvent[]>([]);
export const setOnceSignedInEventAtom = atom(
null,
(get, set, event: OnceSignedInEvent) => {
set(onceSignedInEventsAtom, [...get(onceSignedInEventsAtom), event]);
}
);
export const useOnceSignedInEvents = () => {
const [events, setEvents] = useAtom(onceSignedInEventsAtom);
return useCallback(async () => {
try {
await Promise.all(events.map(event => event()));
} catch (err) {
console.error('Error executing one of the events:', err);
}
setEvents([]);
}, [events, setEvents]);
};
-2
View File
@@ -27,8 +27,6 @@ export type AuthAtom = {
state: AuthProps['state'];
email?: string;
emailType?: AuthProps['emailType'];
// Only used for sign in page callback, after called, it will be set to undefined
onceSignedIn?: () => void;
};
export const authAtom = atom<AuthAtom>({