diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 7238068..38ab104 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -43,8 +43,8 @@ const options = { } }, pages: { - signIn: '/mon-compte', - // signOut: '/auth/signout', + signIn: '/', + signOut: '/mon-compte', error: '/auth/error', // Error code passed in query string as ?error= verifyRequest: '/verify-request', // (used for check email message) // newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest) diff --git a/pages/mon-compte.tsx b/pages/mon-compte.tsx index f25a1aa..15a3708 100644 --- a/pages/mon-compte.tsx +++ b/pages/mon-compte.tsx @@ -43,6 +43,16 @@ type FormData = { export async function getServerSideProps(context) { const session = await getSession(context) + if (!session) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + const user = await prisma.user.findUnique({ where: { email: session?.user.email @@ -60,33 +70,29 @@ export async function getServerSideProps(context) { - return { props: { user: JSON.parse(JSON.stringify(user)), - userGains: JSON.parse(JSON.stringify(userGains)), + userGains, }, } + + + + + + } type Props = { user: User; - userGains: Gain; + userGains: any; } const MonCompte = (props: Props) => { const { data: session, status } = useSession(); - - - - - useEffect(() => { - console.log('user', props.user); - console.log('userGains', props.userGains); - }, []) - const validationSchema = Yup.object().shape({ name: Yup.string() .trim() @@ -110,6 +116,8 @@ const MonCompte = (props: Props) => { }); const onSubmit: SubmitHandler = data => console.log(data); + + return ( <> @@ -191,27 +199,25 @@ const MonCompte = (props: Props) => {

Mes cadeaux


{!props.userGains &&

Pas encore de cadeau gagné

} - - - - - - - - - - - - {props.userGains.map((info: any) => { +
#Mes codes jouéMes cadeauxHandle
+ - - - - + + + - })} - -
MarkOtto@mdo#Mes codes jouéMes cadeaux
+ + + {props.userGains.map((info: any) => { + return + + {info.codeCadeau} + {info.produit.nomProduit} + + })} + + +