Use token var instead of signedIn or user
This commit is contained in:
@@ -3,8 +3,8 @@ import { Redirect, Route } from 'react-router-dom';
|
|||||||
import { useUserContext } from '../Contexts/UserContext';
|
import { useUserContext } from '../Contexts/UserContext';
|
||||||
|
|
||||||
export const ProtectedRoute = ({ render, ...others }) => {
|
export const ProtectedRoute = ({ render, ...others }) => {
|
||||||
const { user, setError } = useUserContext();
|
const { token, setError } = useUserContext();
|
||||||
if (!user || !user.sub || user.sub.length === 0) {
|
if (!token) {
|
||||||
setError('Please sign in to access');
|
setError('Please sign in to access');
|
||||||
return <Redirect to="/" />;
|
return <Redirect to="/" />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React, { useRef } from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { Link as RouterLink } from 'react-router-dom';
|
import { Link as RouterLink } from 'react-router-dom';
|
||||||
import { Avatar, Button, Container, CssBaseline, Grid, Link, TextField, Typography } from '@material-ui/core';
|
import { Button, Container, CssBaseline, Grid, Link, TextField, Typography } from '@material-ui/core';
|
||||||
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
|
|
||||||
import { useUserContext } from '../Contexts/UserContext';
|
import { useUserContext } from '../Contexts/UserContext';
|
||||||
import useStyles from '../Styles';
|
import useStyles from '../Styles';
|
||||||
|
|
||||||
@@ -16,8 +15,10 @@ export default function SignInForm() {
|
|||||||
const username = emailEl.current.value;
|
const username = emailEl.current.value;
|
||||||
const password = passwordEl.current.value;
|
const password = passwordEl.current.value;
|
||||||
const result = await signIn(username, password);
|
const result = await signIn(username, password);
|
||||||
|
debugger;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
debugger;
|
||||||
setError(e.message);
|
setError(e.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -26,9 +27,6 @@ export default function SignInForm() {
|
|||||||
<Container component="main" maxWidth="xs">
|
<Container component="main" maxWidth="xs">
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<div className={classes.paper}>
|
<div className={classes.paper}>
|
||||||
<Avatar className={classes.avatar}>
|
|
||||||
<LockOutlinedIcon />
|
|
||||||
</Avatar>
|
|
||||||
<Typography component="h1" variant="h5">
|
<Typography component="h1" variant="h5">
|
||||||
Sign in
|
Sign in
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -66,7 +64,7 @@ export default function SignInForm() {
|
|||||||
className={classes.submit}
|
className={classes.submit}
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
>
|
>
|
||||||
Sign In
|
{ fetching ? "Signing In..." : "Sign In" }
|
||||||
</Button>
|
</Button>
|
||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React, { useRef } from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { Link as RouterLink } from 'react-router-dom';
|
import { Link as RouterLink } from 'react-router-dom';
|
||||||
import { Avatar, Button, Container, CssBaseline, Grid, Link, TextField, Typography } from '@material-ui/core';
|
import { Button, Container, CssBaseline, Grid, Link, TextField, Typography } from '@material-ui/core';
|
||||||
import LockOpenOutlinedIcon from '@material-ui/icons/LockOpenOutlined';
|
|
||||||
import useStyles from '../Styles';
|
import useStyles from '../Styles';
|
||||||
import { useUserContext } from '../Contexts/UserContext';
|
import { useUserContext } from '../Contexts/UserContext';
|
||||||
|
|
||||||
@@ -18,6 +17,7 @@ export default function SignInForm() {
|
|||||||
const password = passwordEl.current.value;
|
const password = passwordEl.current.value;
|
||||||
const confirm = confirmEl.current.value;
|
const confirm = confirmEl.current.value;
|
||||||
const result = await signUp(email, password, confirm);
|
const result = await signUp(email, password, confirm);
|
||||||
|
debugger;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
setError(e.message);
|
setError(e.message);
|
||||||
@@ -28,9 +28,6 @@ export default function SignInForm() {
|
|||||||
<Container component="main" maxWidth="xs">
|
<Container component="main" maxWidth="xs">
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<div className={classes.paper}>
|
<div className={classes.paper}>
|
||||||
<Avatar className={classes.avatar}>
|
|
||||||
<LockOpenOutlinedIcon />
|
|
||||||
</Avatar>
|
|
||||||
<Typography component="h1" variant="h5">
|
<Typography component="h1" variant="h5">
|
||||||
Sign up
|
Sign up
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -78,7 +75,7 @@ export default function SignInForm() {
|
|||||||
className={classes.submit}
|
className={classes.submit}
|
||||||
disabled={fetching}
|
disabled={fetching}
|
||||||
>
|
>
|
||||||
Sign Up
|
{ fetching ? "Signing Up..." : "Sign Up" }
|
||||||
</Button>
|
</Button>
|
||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
|
|||||||
Reference in New Issue
Block a user