💄 ajout de redirection sur la page mon compte

feature/page-admin
Eric 4 years ago
parent cb95d93831
commit 9d41546603

@ -43,8 +43,8 @@ const options = {
} }
}, },
pages: { pages: {
signIn: '/mon-compte', signIn: '/',
// signOut: '/auth/signout', signOut: '/mon-compte',
error: '/auth/error', // Error code passed in query string as ?error= error: '/auth/error', // Error code passed in query string as ?error=
verifyRequest: '/verify-request', // (used for check email message) 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) // newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest)

@ -43,6 +43,16 @@ type FormData = {
export async function getServerSideProps(context) { export async function getServerSideProps(context) {
const session = await getSession(context) const session = await getSession(context)
if (!session) {
return {
redirect: {
destination: '/',
permanent: false
}
}
}
const user = await prisma.user.findUnique({ const user = await prisma.user.findUnique({
where: { where: {
email: session?.user.email email: session?.user.email
@ -60,33 +70,29 @@ export async function getServerSideProps(context) {
return { return {
props: { props: {
user: JSON.parse(JSON.stringify(user)), user: JSON.parse(JSON.stringify(user)),
userGains: JSON.parse(JSON.stringify(userGains)), userGains,
}, },
} }
} }
type Props = { type Props = {
user: User; user: User;
userGains: Gain; userGains: any;
} }
const MonCompte = (props: Props) => { const MonCompte = (props: Props) => {
const { data: session, status } = useSession(); const { data: session, status } = useSession();
useEffect(() => {
console.log('user', props.user);
console.log('userGains', props.userGains);
}, [])
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
name: Yup.string() name: Yup.string()
.trim() .trim()
@ -110,6 +116,8 @@ const MonCompte = (props: Props) => {
}); });
const onSubmit: SubmitHandler<FormData> = data => console.log(data); const onSubmit: SubmitHandler<FormData> = data => console.log(data);
return ( return (
<> <>
<Head> <Head>
@ -191,27 +199,25 @@ const MonCompte = (props: Props) => {
<h1 className="fw-light">Mes cadeaux</h1> <h1 className="fw-light">Mes cadeaux</h1>
<hr /> <hr />
{!props.userGains && <p>Pas encore de cadeau gagné</p>} {!props.userGains && <p>Pas encore de cadeau gagné</p>}
</div> <table className="table">
<table className="table"> <thead>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Mes codes joué</th>
<th scope="col">Mes cadeaux</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
{props.userGains.map((info: any) => {
<tr> <tr>
<th scope="row"></th> <th scope="col">#</th>
<td>Mark</td> <th scope="col">Mes codes joué</th>
<td>Otto</td> <th scope="col">Mes cadeaux</th>
<td>@mdo</td>
</tr> </tr>
})} </thead>
</tbody> <tbody>
</table> {props.userGains.map((info: any) => {
return <tr>
<th scope="row"></th>
<td>{info.codeCadeau}</td>
<td>{info.produit.nomProduit}</td>
</tr>
})}
</tbody>
</table>
</div>
</div> </div>

Loading…
Cancel
Save