import React from "react"; import prisma from '../lib/prisma' import Image from 'next/image'; import * as Yup from 'yup'; import Head from "next/head"; import { getCsrfToken, signIn, useSession } from "next-auth/react"; import { yupResolver } from "@hookform/resolvers/yup"; import { useForm } from "react-hook-form"; import { AiOutlineGoogle } from 'react-icons/ai' import Router from "next/router"; import style from '../styles/Connexion.module.css'; 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"; import { isGeneratorFunction } from "util/types"; 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 = ({ csrfToken }: Props) => { const { data: session } = useSession(); const validationSchema = Yup.object().shape({ // email: Yup.string().email( // "Veuillez rentrer une adresse mail valide" // ), // acceptTerms: Yup.bool().oneOf( // [true], // "Vous devez accepter les conditions obligatoire" // ) }) const { register, clearErrors, handleSubmit, watch, trigger, formState: { errors } } = useForm({ resolver: yupResolver(validationSchema) }); const acceptTermCheckBox = watch("acceptTerms") const connexionWithGoogle = async () => { if (onCheckTerms()) { signIn("google") } await trigger("acceptTerms"); } const onMailSubmit = async (data: LoginSubmitForm) => { if (onCheckTerms()) { signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` }) } await trigger("acceptTerms"); await trigger("email"); } const onCheckTerms = (): any => { if (acceptTermCheckBox) { return true; } else { toast.error('Vous devez accepter les conditions obligatoires', { position: "top-center", autoClose: 2000, 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); // } return ( <> Connexion

Connexion


) }; export default MainPage;