2
0

Add Dashboard

This commit is contained in:
Baptiste Arnaud
2021-12-06 15:48:50 +01:00
parent 5e14a94dea
commit 54a641b819
47 changed files with 2002 additions and 168 deletions

View File

@ -1,17 +1,12 @@
import { useSession } from 'next-auth/react'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { User } from '@typebot/prisma'
export type withAuthProps = {
user?: User
}
const withAuth =
(WrappedComponent: ({ user }: withAuthProps) => JSX.Element) =>
(props: JSX.IntrinsicAttributes & withAuthProps) => {
(WrappedComponent: (props: any) => JSX.Element) =>
(props: JSX.IntrinsicAttributes) => {
const router = useRouter()
const { data: session, status } = useSession()
const { status } = useSession()
useEffect(() => {
if (!router.isReady) return
@ -19,9 +14,7 @@ const withAuth =
if (status === 'unauthenticated') router.replace('/signin')
}, [status, router])
return (
<WrappedComponent user={session?.user as User | undefined} {...props} />
)
return <WrappedComponent {...props} />
}
export default withAuth