Skip to content

Commit

Permalink
fix: refactor mounting splash twice
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Oct 7, 2024
1 parent 71b7aef commit 93eda35
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { isAndroid, isWebView } from '~/utils/isWebView'
import { Splash } from '../App/Splash'

export const AuthGuard = ({ children }: PropsWithChildren) => {
const [unAuthorized, setUnauthorized] = useState(true)
const [unAuthorized, setUnauthorized] = useState(false)
const { setBudget, setIsAdmin, setPubKey, setIsAuthenticated } = useUserStore((s) => s)
const { splashDataLoading } = useDataStore((s) => s)
const [showSplashScreen, setShowSplashScreen] = useState(true)
const [renderMainPage, setRenderMainPage] = useState(false)

const [
setTrendingTopicsFeatureFlag,
Expand Down Expand Up @@ -66,8 +66,6 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {
try {
const res = await getIsAdmin()

setUnauthorized(false)

if (res.data) {
localStorage.setItem('admin', JSON.stringify({ isAdmin: res.data.isAdmin }))

Expand All @@ -80,10 +78,10 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {
}

setIsAuthenticated(true)
setRenderMainPage(true)
} catch (error) {
/* not an admin */
} finally {
setShowSplashScreen(false)
setUnauthorized(true)
}
}, [
setIsAuthenticated,
Expand Down Expand Up @@ -119,10 +117,6 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {

const message = 'This is a private Graph, Contact Admin'

if (showSplashScreen) {
return <>{splashDataLoading && <Splash />}</>
}

if (unAuthorized) {
return (
<StyledFlex>
Expand All @@ -133,8 +127,8 @@ export const AuthGuard = ({ children }: PropsWithChildren) => {

return (
<>
{/* {splashDataLoading && <Splash />} */}
{children}
{splashDataLoading && <Splash />}
{renderMainPage && children}
</>
)
}
Expand Down

0 comments on commit 93eda35

Please sign in to comment.