Switch header on [id] depending on auth

This commit is contained in:
Max Leiter 2022-03-06 22:23:39 -08:00
parent 773920bb41
commit 41f0dd5c7a
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA

View file

@ -1,8 +1,9 @@
import { Loading, Page, Text } from "@geist-ui/core"; import { Loading, Page, Text } from "@geist-ui/core";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import Document from '../../components/document' import Document from '../../components/document'
import Header from "../../components/header"; import Header from "../../components/header";
import UnauthenticatedHeader from "../../components/unauthenticated-header";
import VisibilityBadge from "../../components/visibility-badge"; import VisibilityBadge from "../../components/visibility-badge";
import { ThemeProps } from "../_app"; import { ThemeProps } from "../_app";
@ -42,12 +43,19 @@ const Post = ({ theme, changeTheme }: ThemeProps) => {
} }
fetchPost() fetchPost()
}, [router, router.query.id]) }, [router, router.query.id])
console.log(post, isLoading, error)
const token = useCallback(() => {
if (typeof window !== "undefined") {
return localStorage.getItem("drift-token")
} else {
return ""
}
}, [])
return ( return (
<Page> <Page>
<Page.Header> <Page.Header>
<Header theme={theme} changeTheme={changeTheme} /> {token() && <Header theme={theme} changeTheme={changeTheme} />}
{!token() && <UnauthenticatedHeader theme={theme} changeTheme={changeTheme} />}
</Page.Header> </Page.Header>
<Page.Content width={"var(--main-content-width)"} margin="auto"> <Page.Content width={"var(--main-content-width)"} margin="auto">
{error && <Text type="error">{error}</Text>} {error && <Text type="error">{error}</Text>}