-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from sajidrsk/forgot-password-page-and-private…
…-routing - added forgot password page - added private routing based on user is logged in or not - added update email and password feature(gui not available yet) - added sign out button
- Loading branch information
Showing
8 changed files
with
217 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 +1,22 @@ | ||
import * as React from "react"; | ||
import { Route, Redirect } from "react-router-dom"; | ||
|
||
const PrivateRoute = ({ auth, component: Component, ...rest }) => { | ||
import { useAuth } from "./contexts/auth-context"; | ||
|
||
const PrivateRoute = ({ component: Component, ...rest }) => { | ||
const { currentUser } = useAuth(); | ||
return ( | ||
<Route | ||
{...rest} | ||
render={(props) => { | ||
return auth ? <Component {...props} /> : <Redirect to="/login" />; | ||
return currentUser ? ( | ||
<Component {...props} /> | ||
) : ( | ||
<Redirect to="/login" /> | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default PrivateRoute; | ||
export default PrivateRoute; |
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,29 +1,53 @@ | ||
import React, { useContext } from "react"; | ||
import { Button } from "@material-ui/core"; | ||
import { useHistory } from "react-router-dom"; | ||
|
||
import Recipe from "./Recipe"; | ||
import { RecipeContext } from "../contexts/recipe-context"; | ||
import { useAuth } from "../contexts/auth-context"; | ||
|
||
export default function RecipeList({ recipes }) { | ||
const { handleRecipeAdd } = useContext(RecipeContext); | ||
const { logout } = useAuth(); | ||
const history = useHistory(); | ||
|
||
const handleLogout = async () => { | ||
// setError("") | ||
try { | ||
await logout(); | ||
history.push("/login"); | ||
} catch { | ||
// setError("Failed to log out") | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="recipe-list"> | ||
<div className="recipe-list__grid"> | ||
{recipes.map((recipe) => { | ||
return <Recipe key={recipe.id} {...recipe} />; | ||
})} | ||
</div> | ||
<div className="recipe-list__add-recipe-btn-container"> | ||
<Button | ||
size="small" | ||
color="primary" | ||
variant="contained" | ||
onClick={handleRecipeAdd} | ||
> | ||
Add Recipe | ||
</Button> | ||
<> | ||
<Button | ||
size="small" | ||
color="Secondary" | ||
variant="contained" | ||
onClick={handleLogout} | ||
> | ||
SignOut | ||
</Button> | ||
<div className="recipe-list"> | ||
<div className="recipe-list__grid"> | ||
{recipes.map((recipe) => { | ||
return <Recipe key={recipe.id} {...recipe} />; | ||
})} | ||
</div> | ||
<div className="recipe-list__add-recipe-btn-container"> | ||
<Button | ||
size="small" | ||
color="primary" | ||
variant="contained" | ||
onClick={handleRecipeAdd} | ||
> | ||
Add Recipe | ||
</Button> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import React, { useState, useRef } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { | ||
Avatar, | ||
Button, | ||
CssBaseline, | ||
TextField, | ||
Grid, | ||
Box, | ||
Typography, | ||
Container, | ||
Grow, | ||
} from "@material-ui/core"; | ||
import LockOutlinedIcon from "@material-ui/icons/LockOutlined"; | ||
import { makeStyles } from "@material-ui/core/styles"; | ||
import { useSnackbar } from "notistack"; | ||
|
||
import { useAuth } from "../../contexts/auth-context"; | ||
|
||
function Copyright() { | ||
return ( | ||
<Typography variant="body2" color="textSecondary" align="center"> | ||
{`Copyright © Kitchen Recipe by Sajid ${new Date().getFullYear()}.`} | ||
</Typography> | ||
); | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
paper: { | ||
marginTop: theme.spacing(8), | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
}, | ||
avatar: { | ||
margin: theme.spacing(1), | ||
backgroundColor: theme.palette.secondary.main, | ||
}, | ||
form: { | ||
width: "100%", | ||
marginTop: theme.spacing(1), | ||
}, | ||
submit: { | ||
margin: theme.spacing(3, 0, 2), | ||
}, | ||
})); | ||
|
||
const ForgotPassword = () => { | ||
const classes = useStyles(); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
|
||
const emailRef = useRef(); | ||
const { resetPassword } = useAuth(); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
|
||
try { | ||
setLoading(true); | ||
await resetPassword(emailRef.current.value); | ||
|
||
enqueueSnackbar("Password Reset Email Sent to Your Mail", { | ||
anchorOrigin: { | ||
vertical: "bottom", | ||
horizontal: "center", | ||
}, | ||
TransitionComponent: Grow, | ||
variant: "success", | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
enqueueSnackbar(e.message, { | ||
anchorOrigin: { | ||
vertical: "bottom", | ||
horizontal: "center", | ||
}, | ||
TransitionComponent: Grow, | ||
variant: "error", | ||
}); | ||
} | ||
|
||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<Container component="main" maxWidth="xs"> | ||
<CssBaseline /> | ||
<div className={classes.paper}> | ||
<Avatar className={classes.avatar}> | ||
<LockOutlinedIcon /> | ||
</Avatar> | ||
<Typography component="h1" variant="h5"> | ||
Password Reset | ||
</Typography> | ||
<form className={classes.form} noValidate onSubmit={handleSubmit}> | ||
<TextField | ||
variant="outlined" | ||
margin="normal" | ||
required | ||
fullWidth | ||
id="email" | ||
label="Email Address" | ||
name="email" | ||
autoComplete="email" | ||
inputRef={emailRef} | ||
/> | ||
<Button | ||
type="submit" | ||
fullWidth | ||
variant="contained" | ||
color="primary" | ||
className={classes.submit} | ||
disabled={loading} | ||
> | ||
Reset Password | ||
</Button> | ||
<Grid container justify="flex-end"> | ||
<Grid item xs> | ||
<Button color="primary" to="/login" component={Link}> | ||
{"Log In!"} | ||
</Button> | ||
</Grid> | ||
<Grid item> | ||
<Button color="primary" to="/signup" component={Link}> | ||
{"Don't have an account? SignUp"} | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
</form> | ||
</div> | ||
<Box mt={8}> | ||
<Copyright /> | ||
</Box> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default ForgotPassword; |
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