diff --git a/.env b/.env index d60be06..3ce60ad 100644 --- a/.env +++ b/.env @@ -9,10 +9,13 @@ GITHUB_SECRET=YOUR_GITHUB_CLIENT_SECRET GOOGLE_CLIENT_ID=5572607706-p6dftn0ss3m2qnvqbhk4khqte8lk7kt3.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=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 +DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop" + # Email (magic link) -EMAIL_SERVER=smtp://2bfdbee5372880:af828174d7f2ad@smtp.mailtrap.io:2525 +EMAIL_SERVER_USER=2bfdbee5372880 +EMAIL_SERVER_PASSWORD=af828174d7f2ad +EMAIL_SERVER_HOST=smtp.mailtrap.io +EMAIL_SERVER_PORT=2525 EMAIL_FROM=thetiptop@test.com -DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop" - diff --git a/components/NavBar.tsx b/components/NavBar.tsx index 7cb03a0..f316a63 100644 --- a/components/NavBar.tsx +++ b/components/NavBar.tsx @@ -6,6 +6,8 @@ import { signOut, useSession } from "next-auth/react"; import style from '../styles/NavBar.module.css'; import Image from 'next/image'; +import { FiArrowRight } from 'react-icons/fi'; + const NavBar = () => { const navRef = useRef(); @@ -33,12 +35,20 @@ const NavBar = () => { width={250} height={100} /> + + +
Accueil | Nos produits | Contactez-nous | - Connexion + {!session && Connexion} + {session && Mon compte} + {session && signOut()} className={style.link} >Se déconnecter} + + + {session && {session.user.email}}
@@ -46,6 +56,9 @@ const NavBar = () => { ☰ +
+
+
@@ -54,8 +67,11 @@ const NavBar = () => {
Accueil | Nos produits | + + Contactez-nous | - Connexion + Connexion + {session && {session.user.email}}
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 452f9c6..dee978b 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -18,8 +18,15 @@ const options = { authorization: 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code', }), EmailProvider({ - server: process.env.EMAIL_SERVER, - from: process.env.EMAIL_FROM, + server: { + host: process.env.EMAIL_SERVER_HOST, + port: parseInt(process.env.EMAIL_SERVER_PORT), + auth: { + user: process.env.EMAIL_SERVER_USER, + pass: process.env.EMAIL_SERVER_PASSWORD + } + }, + from: process.env.EMAIL_FROM }), ], adapter: PrismaAdapter(prisma), @@ -32,14 +39,9 @@ const options = { }) //récupération du role const { role } = getCurrentUser[0]; - session.user.role = role - - - return session } }, error: '/error', - } diff --git a/pages/connexion.tsx b/pages/connexion.tsx index 284aa84..3e6d80e 100644 --- a/pages/connexion.tsx +++ b/pages/connexion.tsx @@ -4,7 +4,7 @@ import prisma from '../lib/prisma' import Image from 'next/image'; import * as Yup from 'yup'; import Head from "next/head"; -import { signIn, useSession } from "next-auth/react"; +import { getCsrfToken, signIn, useSession } from "next-auth/react"; import { yupResolver } from "@hookform/resolvers/yup"; import { useForm } from "react-hook-form"; @@ -21,31 +21,43 @@ import imageConnexion from '../public/images/connexion_image.png' import Link from "next/link"; import { SiGnuprivacyguard } from 'react-icons/si' +import { toast } from "react-toastify"; +import { Token } from "nodemailer/lib/xoauth2"; - - - +export async function getServerSideProps(context) { + const csrfToken = await getCsrfToken(context) + return { + props: { csrfToken }, + } +} type LoginSubmitForm = { email: string, acceptTerms: boolean }; +type Props = { + csrfToken: Token +} + -const MainPage = () => { +const MainPage = ({ csrfToken }: Props) => { const { data: session } = useSession(); const validationSchema = Yup.object().shape({ - email: Yup.string().email(), + email: Yup.string().email( + "Veuillez rentrer une adresse mail valide" + ), acceptTerms: Yup.bool().oneOf( [true], - "Accepter les conditions est obligatoire" + "Vous devez accepter les conditions obligatoire" ) }) const { register, + clearErrors, handleSubmit, watch, trigger, @@ -56,36 +68,68 @@ const MainPage = () => { const term = watch("acceptTerms") + + const connexionWithGoogle = async () => { + clearErrors("acceptTerms") if (term) { signIn("google"); + } else { + toast.error('Vous devez accepter les conditions obligatoire', { + position: "top-center", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "light", + }); + //relance une vérification de la checkbox + // await trigger("acceptTerms"); } - //relance une vérification de la checkbox - await trigger("acceptTerms"); + + } const onSubmit = async (data: LoginSubmitForm) => { + if (term && !errors.email?.message) { + console.log("email", data.email); + + signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` }) + } else { + toast.error('Vous devez accepter les conditions obligatoire', { + position: "top-center", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + theme: "light", + }); + } + } - // try { - // const body = { bioValue: data.bio }; - // await fetch(`/api/profile`, { - // method: "POST", - // headers: { "Content-Type": "application/json" }, - // body: JSON.stringify(body), - // }) - // .then((res) => res.json()) - // .then((data) => { - // setResponse(data); - // console.log('response', data); - // }) - // await Router.push("/profile"); - // } catch (error) { - // console.error(error); - // } - }; + // try { + // const body = { bioValue: data.bio }; + // await fetch(`/api/profile`, { + // method: "POST", + // headers: { "Content-Type": "application/json" }, + // body: JSON.stringify(body), + // }) + // .then((res) => res.json()) + // .then((data) => { + // setResponse(data); + // console.log('response', data); + // }) + // await Router.push("/profile"); + // } catch (error) { + // console.error(error); + // } return ( <> @@ -93,70 +137,48 @@ const MainPage = () => { -
- -

Connexion

-
- -
- - -
+
-
- - - - -
- -
- -
- -
- - - -
- +
{errors.email?.message}
+
+
+
+ +
+
+ + + {/*
{errors.acceptTerms?.message}
*/}
-
-
{errors.acceptTerms?.message}
-
{errors.email?.message}
-
- - - - + ) }; diff --git a/public/images/jeuconcours.png b/public/images/jeuconcours.png index bd972f0..57a6fde 100644 Binary files a/public/images/jeuconcours.png and b/public/images/jeuconcours.png differ diff --git a/public/images/rearrow.png b/public/images/rearrow.png new file mode 100644 index 0000000..959f539 Binary files /dev/null and b/public/images/rearrow.png differ diff --git a/styles/Connexion.module.css b/styles/Connexion.module.css index 24c099c..b8c67e6 100644 --- a/styles/Connexion.module.css +++ b/styles/Connexion.module.css @@ -11,4 +11,10 @@ .imageWrapper { display: block; +} + +.connexion { + position: absolute; + top: 0; + right: 0; } \ No newline at end of file diff --git a/styles/Index.module.css b/styles/Index.module.css index f9a5b7f..8729f49 100644 --- a/styles/Index.module.css +++ b/styles/Index.module.css @@ -5,7 +5,7 @@ background-position: 50% 50%; background-repeat: no-repeat; background-size: contain; - animation: zoomInOut 4s ease-in-out infinite; + /* animation: zoomInOut 4s ease-in-out infinite; */ z-index: 9000; } diff --git a/styles/NavBar.module.css b/styles/NavBar.module.css index 04c7f68..b11a4ee 100644 --- a/styles/NavBar.module.css +++ b/styles/NavBar.module.css @@ -9,6 +9,12 @@ text-decoration: underline; } +.connexion { + position: absolute; + top: 0; + right: 0; +} + /**************************/ .overlay {