Add Dashboard
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user