From 77aded8c1a8f153406d2b781dd48cef8270701af Mon Sep 17 00:00:00 2001 From: Sahil Mobaidin Date: Fri, 14 May 2021 02:46:52 +0300 Subject: [PATCH] fix(kibbeh): prevent login screen from rendering if tokens is not yet checked fix #2735 --- kibbeh/src/modules/landing-page/LoginPage.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kibbeh/src/modules/landing-page/LoginPage.tsx b/kibbeh/src/modules/landing-page/LoginPage.tsx index 1b17babb1..b63811c30 100644 --- a/kibbeh/src/modules/landing-page/LoginPage.tsx +++ b/kibbeh/src/modules/landing-page/LoginPage.tsx @@ -1,6 +1,6 @@ import isElectron from "is-electron"; import { useRouter } from "next/router"; -import React, { useCallback, useContext, useEffect } from "react"; +import React, { useCallback, useContext, useEffect, useState } from "react"; import { LgLogo } from "../../icons"; import SvgSolidBug from "../../icons/SolidBug"; import SvgSolidDiscord from "../../icons/SolidDiscord"; @@ -75,6 +75,7 @@ export const LoginPage: React.FC = () => { const hasTokens = useTokenStore((s) => !!(s.accessToken && s.refreshToken)); const { setConn } = useContext(WebSocketContext); const { push } = useRouter(); + const [tokensChecked, setTokensChecked] = useState(false); useEffect(() => { // only want this on mount @@ -85,6 +86,8 @@ export const LoginPage: React.FC = () => { useEffect(() => { if (hasTokens) { push("/dash"); + } else { + setTokensChecked(true); } }, [hasTokens, push]); @@ -93,6 +96,8 @@ export const LoginPage: React.FC = () => { ? "?redirect_after_base=" + window.location.origin : ""; + if (!tokensChecked) return null; + return ( <>