Insert account info into state when the app first loads
This commit is contained in:
parent
a6b222000c
commit
1d82bc5055
1 changed files with 23 additions and 6 deletions
|
|
@ -1,13 +1,30 @@
|
|||
import '../styles/globals.scss'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { CookiesProvider } from 'react-cookie'
|
||||
|
||||
import Layout from '~components/Layout'
|
||||
import { useEffect } from 'react'
|
||||
import { useCookies, CookiesProvider } from 'react-cookie'
|
||||
|
||||
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 [cookies] = useCookies(['user'])
|
||||
|
||||
useEffect(() => {
|
||||
if (cookies.user) {
|
||||
console.log(`Logged in as user "${cookies.user.username}"`)
|
||||
|
||||
accountState.account.authorized = true
|
||||
accountState.account.user = {
|
||||
id: cookies.user.user_id,
|
||||
username: cookies.user.username
|
||||
}
|
||||
} else {
|
||||
console.log(`You are not currently logged in.`)
|
||||
}
|
||||
}, [cookies.user])
|
||||
|
||||
return (
|
||||
<CookiesProvider>
|
||||
<Layout>
|
||||
|
|
|
|||
Loading…
Reference in a new issue