-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from CS3219-AY2425S1/shishir/fix-fe-authentica…
…tion
- Loading branch information
Showing
24 changed files
with
552 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client' | ||
|
||
export default function Loading() { | ||
return ( | ||
<div className="flex items-center justify-center"> | ||
<svg | ||
style={{ marginTop: '30vh' }} | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="64" | ||
height="64" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="rgb(147 51 234)" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
className={'animate-spin'} | ||
> | ||
<path d="M21 12a9 9 0 1 1-6.219-8.56" /> | ||
</svg> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// hooks/useProtectedRoute.ts | ||
|
||
import { useEffect, useState } from 'react' | ||
|
||
import { useRouter } from 'next/router' | ||
import { useSession } from 'next-auth/react' | ||
|
||
const useProtectedRoute = () => { | ||
const { data: session, status } = useSession() | ||
const router = useRouter() | ||
const [isLoading, setIsLoading] = useState(true) | ||
|
||
useEffect(() => { | ||
if (status === 'loading') return | ||
|
||
if (!session) { | ||
router.push('/auth') | ||
} else { | ||
setIsLoading(false) | ||
} | ||
}, [session, status, router]) | ||
|
||
return { session, loading: isLoading } | ||
} | ||
|
||
export default useProtectedRoute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import '@/styles/globals.css' | ||
|
||
import { AppProps } from 'next/app' | ||
import Layout from '@/components/layout/layout' | ||
import CustomToaster from '@/components/customs/custom-toaster' | ||
import Layout from '@/components/layout/layout' | ||
import { RecoilRoot } from 'recoil' | ||
import { SessionProvider } from 'next-auth/react' | ||
|
||
export default function App({ Component, pageProps }: AppProps) { | ||
export default function App({ Component, pageProps: { session, ...pageProps } }: AppProps) { | ||
return ( | ||
<RecoilRoot> | ||
<Layout> | ||
<Component {...pageProps} /> | ||
<CustomToaster /> | ||
</Layout> | ||
</RecoilRoot> | ||
<SessionProvider session={session} refetchInterval={60}> | ||
<RecoilRoot> | ||
<Layout> | ||
<Component {...pageProps} /> | ||
<CustomToaster /> | ||
</Layout> | ||
</RecoilRoot> | ||
</SessionProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import AccountSettings from '@/components/account/AccountSetting' | ||
import Loading from '@/components/customs/loading' | ||
import useProtectedRoute from '@/hooks/UseProtectedRoute' | ||
|
||
export default function Account() { | ||
const { loading } = useProtectedRoute() | ||
if (loading) return <Loading /> | ||
return <AccountSettings /> | ||
} |
Oops, something went wrong.