-
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.
added login pages, and register/login functionality
- Loading branch information
Showing
7 changed files
with
277 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useRef, useState } from "react"; | ||
import { useNavigate } from "react-router"; | ||
import action from "../posts/buttons/Button.module.css"; | ||
import Post from "../UI/Post"; | ||
import classes from "./CreateLogin.module.css"; | ||
|
||
function CreateLoginForm({ setShowError, setErrorText, setIdToken }) { | ||
const [emailError, setEmailError] = useState(""); | ||
const navigate = useNavigate(); | ||
const emailRef = useRef(); | ||
const passRef = useRef(); | ||
let fireResp = false; | ||
function submitHandler(event) { | ||
event.preventDefault(); | ||
|
||
const account = { | ||
email: emailRef.current.value, | ||
password: passRef.current.value, | ||
returnSecureToken: true, | ||
}; | ||
|
||
createAccount(account); | ||
} | ||
|
||
function createAccount(account) { | ||
fetch( | ||
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyAaazs-kF0uByzgKnY4Di5bTGM-HOozi10", | ||
{ | ||
method: "POST", | ||
body: JSON.stringify(account), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
fireResp = true; | ||
} else { | ||
fireResp = false; | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (fireResp === true) { | ||
setIdToken(data.idToken); | ||
navigate("/feed"); | ||
} else { | ||
setEmailError(data.error.message); | ||
} | ||
}); | ||
} | ||
return ( | ||
<form className={classes.form} onSubmit={submitHandler}> | ||
<Post> | ||
<h3>Create Account</h3> | ||
<div className={classes.content}> | ||
<input placeholder="Email" ref={emailRef} /> | ||
<input placeholder="Password" ref={passRef} /> | ||
</div> | ||
{emailError !== "" && <p className={classes.error}>{emailError}</p>} | ||
<div className={action.actions}> | ||
<div className={classes.actions}> | ||
<button>Create Account</button> | ||
</div> | ||
</div> | ||
</Post> | ||
</form> | ||
); | ||
} | ||
|
||
export default CreateLoginForm; |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.form { | ||
position: absolute; | ||
z-index: 10; | ||
right: 30%; | ||
left: 30% | ||
} | ||
|
||
.form h3{ | ||
padding-top: 6%; | ||
margin: 0; | ||
padding-bottom: 0px; | ||
text-align: center; | ||
} | ||
|
||
.content { | ||
display: flex; | ||
flex-direction: column; | ||
padding-left: 10%; | ||
padding-right:10%; | ||
width: 100%; | ||
|
||
|
||
} | ||
.content input{ | ||
margin: 3px; | ||
display: inline-block; | ||
font: inherit; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
padding: 0.25rem; | ||
width: 100%; | ||
} | ||
|
||
.actions{ | ||
text-align: center; | ||
padding-top: 2%; | ||
padding-bottom: 5%; | ||
/* height: 50%; */ | ||
} | ||
|
||
.error{ | ||
text-align: center; | ||
color: red; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import Post from "../components/UI/Post"; | ||
import classes from "./Login.module.css"; | ||
import action from "../components/posts/buttons/Button.module.css"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useRef, useState } from "react"; | ||
import CreateLoginForm from "../components/login/CreateLogin"; | ||
import Backdrop from "../components/UI/Backdrop"; | ||
|
||
function LoginPage({ setShowError, setErrorText, setIdToken }) { | ||
const [showCreateLogin, setShowCreateLogin] = useState(false); | ||
const [emailError, setEmailError] = useState(""); | ||
const navigate = useNavigate(); | ||
const emailRef = useRef(); | ||
const passRef = useRef(); | ||
let fireResp = false; | ||
|
||
function onSubmit(event) { | ||
event.preventDefault(); | ||
|
||
const account = { | ||
email: emailRef.current.value, | ||
password: passRef.current.value, | ||
returnSecureToken: true, | ||
}; | ||
|
||
fetch( | ||
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=AIzaSyAaazs-kF0uByzgKnY4Di5bTGM-HOozi10", | ||
{ | ||
method: "POST", | ||
body: JSON.stringify(account), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
fireResp = true; | ||
} else { | ||
fireResp = false; | ||
} | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (fireResp === true) { | ||
setIdToken(data.idToken); | ||
navigate("/feed"); | ||
} else { | ||
setEmailError(data.error.message); | ||
} | ||
}); | ||
} | ||
|
||
function createLoginHandler() { | ||
setShowCreateLogin(!showCreateLogin); | ||
} | ||
return ( | ||
<> | ||
<form className={classes.login} onSubmit={onSubmit}> | ||
<Post> | ||
<div className={classes.content}> | ||
<div className={classes.input}> | ||
<input required placeholder="Email" ref={emailRef}></input> | ||
<input required placeholder="Password" ref={passRef}></input> | ||
</div> | ||
{emailError !== "" && <p className={classes.error}>{emailError}</p>} | ||
<div className={action.actions}> | ||
<button>Login</button> | ||
</div> | ||
</div> | ||
</Post> | ||
</form> | ||
<div className={action.actions}> | ||
<div className={classes.create}> | ||
<button onClick={createLoginHandler}>Create Login</button> | ||
</div> | ||
</div> | ||
{showCreateLogin && ( | ||
<> | ||
<CreateLoginForm | ||
setShowError={setShowError} | ||
setErrorText={setErrorText} | ||
setIdToken={setIdToken} | ||
/> | ||
<Backdrop onClick={createLoginHandler} /> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default LoginPage; |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.login{ | ||
display: flex; | ||
margin: 100px 30% 1% 30%; | ||
justify-content: center; | ||
} | ||
|
||
.content { | ||
text-align: center; | ||
padding: 10%; | ||
} | ||
|
||
.input input{ | ||
margin: 3px; | ||
display: inline-block; | ||
font: inherit; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
padding: 0.25rem; | ||
width: 100%; | ||
} | ||
|
||
.create { | ||
text-align: center; | ||
} | ||
|
||
.error{ | ||
text-align: center; | ||
color: red; | ||
} |