-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_app.tsx
37 lines (30 loc) · 889 Bytes
/
_app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* eslint-disable react-hooks/exhaustive-deps */
import type { AppProps } from 'next/app';
import { useRouter } from 'next/router.js';
import { useEffect } from 'react';
import NextNProgress from 'nextjs-progressbar';
import { useAuthState } from 'react-firebase-hooks/auth';
import { auth } from '../firebase';
import '../styles/globals.css';
import '@sweetalert2/theme-dark/dark.css';
export default function App({ Component, pageProps }: AppProps) {
const [user, loading] = useAuthState(auth);
const router = useRouter();
useEffect(() => {
if (!(user || loading)) {
router.push('/login');
}
}, [user, loading]);
useEffect(() => {
if (user) {
router.push('/');
}
}, [user]);
if (loading) return <NextNProgress color="#DC2626" />;
return (
<>
<NextNProgress color="#DC2626" />
<Component {...pageProps} />
</>
);
}