fix(auth): block render while logging in

This commit is contained in:
Paul
2021-12-24 11:32:59 +00:00
parent 74430b1a8f
commit c31bcd0200
2 changed files with 5 additions and 4 deletions

View File

@@ -30,7 +30,6 @@ export interface ClientOperations {
export const AppContext = createContext<Client>(null!);
export const StatusContext = createContext<ClientStatus>(null!);
export const OperationsContext = createContext<ClientOperations>(null!);
export const LogOutContext = createContext(() => {});
type Props = {
@@ -57,12 +56,12 @@ export default observer(({ children }: Props) => {
useEffect(() => {
if (state.auth.isLoggedIn()) {
setLoaded(false);
const client = state.config.createClient();
setClient(client);
client
.useExistingSession(state.auth.getSession()!)
.then(() => setLoaded(true))
.catch((err) => {
const error = takeError(err);
if (error === "Forbidden" || error === "Unauthorized") {
@@ -72,7 +71,8 @@ export default observer(({ children }: Props) => {
setStatus(ClientStatus.DISCONNECTED);
openScreen({ id: "error", error });
}
});
})
.finally(() => setLoaded(true));
} else {
setStatus(ClientStatus.READY);
setLoaded(true);