-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapPageElement.js
40 lines (36 loc) · 1.08 KB
/
wrapPageElement.js
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
38
39
40
import React from "react"
import { LazyMotion, domMax } from "framer-motion"
import { AuthProvider } from "./src/context/auth-context"
import { SessionProvider } from "./src/context/session-context"
import { ToastProvider } from "./src/context/toast-context"
const publicRoutes = ["/", "/login"]
const AuthWrapper = ({ children, pathname }) => {
return (
<AuthProvider loginRequired={!publicRoutes.includes(pathname)}>
{children}
</AuthProvider>
)
}
const SessionWrapper = ({ children, pathname }) => {
if (!publicRoutes.includes(pathname)) {
return (
<SessionProvider loginRequired={!publicRoutes.includes(pathname)}>
{children}
</SessionProvider>
)
}
return <>{children}</>
}
export const wrapPageElement = ({ element, props }) => {
return (
<LazyMotion strict features={domMax}>
<AuthWrapper pathname={props.location.pathname}>
<ToastProvider>
<SessionWrapper pathname={props.location.pathname}>
{element}
</SessionWrapper>
</ToastProvider>
</AuthWrapper>
</LazyMotion>
)
}