-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marie MΓ©lody F
authored and
Marie MΓ©lody F
committed
Sep 2, 2023
1 parent
c14de08
commit c591f78
Showing
5 changed files
with
146 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,84 @@ | ||
import axios from "axios"; | ||
import React, { useState, useEffect } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import React, { useState } from "react"; | ||
import { Link, useNavigate } from "react-router-dom"; | ||
// import { useState } from "react"; | ||
|
||
const Login = () => { | ||
const Login = ({ token, setToken }) => { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<div> | ||
<span>Login</span> | ||
<div className="form-container"> | ||
<div className="form"> | ||
<form | ||
onSubmit={async (event) => { | ||
event.preventDefault(); | ||
|
||
try { | ||
const response = await axios.post( | ||
`https://site--marvel-backend--r2txk865xjj8.code.run/user/login`, | ||
{ | ||
email: email, | ||
password: password, | ||
} | ||
); | ||
console.log("log connexion", response.data); | ||
console.log("data.token", response.data.token); | ||
navigate("/characters"); | ||
setToken(response.data.token); | ||
} catch (error) { | ||
error.response; | ||
console.log("=>", error.response); | ||
if ( | ||
error.response.data.message === | ||
"Cannot read properties of null (reading 'salt')" | ||
) { | ||
alert( | ||
"Vous avez saisi un mauvais mot de passe ou identifiant π«€. Si vous n'avez pas de compte, merci de vous inscrire" | ||
); | ||
} else if ( | ||
error.response.data === | ||
"Le mot de passe ou l'identifiant n'est pas correct." | ||
) { | ||
alert( | ||
"Vous avez saisi un mauvais mot de passe ou identifiant π«€. Si vous n'avez pas de compte, merci de vous inscrire" | ||
); | ||
} | ||
} | ||
}} | ||
> | ||
<h1>Log in</h1> | ||
<input | ||
type="email" | ||
placeholder="[email protected]" | ||
value={email} | ||
onChange={(event) => { | ||
setEmail(event.target.value); | ||
}} | ||
/> | ||
<input | ||
type="password" | ||
placeholder="your password" | ||
value={password} | ||
onChange={(event) => { | ||
setPassword(event.target.value); | ||
}} | ||
/> | ||
<button | ||
className="form-validation" | ||
type="submit" | ||
value="Se connecter" | ||
> | ||
Log in | ||
</button> | ||
<Link to="/user/signup"> | ||
<span className="subscribe"> | ||
You dont have a account ? Come on, come to Sign up ! | ||
</span> | ||
</Link> | ||
</form> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters