Skip to content

Commit fc5a034

Browse files
committed
1.7 Add client-side route protection
1 parent bb17ace commit fc5a034

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/pages/profile.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
import { useEffect } from 'react'
12
import Link from 'next/link'
3+
import Router from 'next/router'
24
import { useAuth } from '~/lib/auth'
35
import Layout from '~/components/Layout'
46
import { SpinnerFullPage } from '~/components/Spinner'
7+
import { ROUTE_AUTH } from '~/config'
58

69
const ProfilePage = ({}) => {
7-
const { user, loading, signOut } = useAuth()
10+
const { user, userLoading, signOut, loggedIn } = useAuth()
811

9-
if(loading) {
12+
useEffect(() => {
13+
if (!userLoading && !loggedIn) {
14+
Router.push(ROUTE_AUTH)
15+
}
16+
}, [userLoading, loggedIn]);
17+
18+
if(userLoading) {
1019
return <SpinnerFullPage/>
1120
}
1221

0 commit comments

Comments
 (0)