Update to store authorized state in _app
This commit is contained in:
parent
752e468c4b
commit
84a7ca7733
1 changed files with 24 additions and 0 deletions
|
|
@ -1,11 +1,35 @@
|
|||
import { useEffect } from "react"
|
||||
import { getCookie } from "cookies-next"
|
||||
import { appWithTranslation } from "next-i18next"
|
||||
|
||||
import type { AppProps } from "next/app"
|
||||
import Layout from "~components/Layout"
|
||||
|
||||
import { accountState } from "~utils/accountState"
|
||||
|
||||
import "../styles/globals.scss"
|
||||
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
const cookie = getCookie("account")
|
||||
const cookieData = cookie ? JSON.parse(cookie as string) : null
|
||||
|
||||
useEffect(() => {
|
||||
if (cookie) {
|
||||
console.log(`Logged in as user "${cookieData.username}"`)
|
||||
|
||||
accountState.account.authorized = true
|
||||
accountState.account.user = {
|
||||
id: cookieData.user_id,
|
||||
username: cookieData.username,
|
||||
picture: "",
|
||||
element: "",
|
||||
gender: 0,
|
||||
}
|
||||
} else {
|
||||
console.log(`You are not currently logged in.`)
|
||||
}
|
||||
}, [cookieData])
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Component {...pageProps} />
|
||||
|
|
|
|||
Loading…
Reference in a new issue