Skip to content

Commit

Permalink
fix(kibbeh): prevent login screen from rendering if tokens is not yet…
Browse files Browse the repository at this point in the history
… checked

fix benawad#2735
  • Loading branch information
sahilmob committed May 13, 2021
1 parent e321a9a commit 77aded8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kibbeh/src/modules/landing-page/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -85,6 +86,8 @@ export const LoginPage: React.FC = () => {
useEffect(() => {
if (hasTokens) {
push("/dash");
} else {
setTokensChecked(true);
}
}, [hasTokens, push]);

Expand All @@ -93,6 +96,8 @@ export const LoginPage: React.FC = () => {
? "?redirect_after_base=" + window.location.origin
: "";

if (!tokensChecked) return null;

return (
<>
<div className="flex">
Expand Down

0 comments on commit 77aded8

Please sign in to comment.