Removed logout on refresh
This commit is contained in:
parent
82be61472a
commit
2fdd78a8e0
4 changed files with 12 additions and 23 deletions
|
|
@ -2,16 +2,15 @@ import { Card, CardContent } from '@mui/material';
|
|||
import { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { useUser } from 'contexts';
|
||||
import { AskForm } from 'controllers/FormControllers';
|
||||
import { MdPreview } from 'components';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export default function Ask() {
|
||||
const navigate = useNavigate();
|
||||
const { userData } = useUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (!userData.username) {
|
||||
if (!Cookies.get('token')) {
|
||||
navigate('/users/login', {
|
||||
state: {
|
||||
name: 'dashboard',
|
||||
|
|
@ -21,7 +20,7 @@ export default function Ask() {
|
|||
});
|
||||
}
|
||||
}, [navigate]);
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Card>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
import { Card, CardContent } from '@mui/material';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { useUser } from 'contexts';
|
||||
import { Inbox } from 'controllers';
|
||||
import { SendMail } from 'controllers/FormControllers';
|
||||
import { MdPreview } from 'components';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export default function Mail() {
|
||||
const navigate = useNavigate();
|
||||
const { userData} = useUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (!userData.username) {
|
||||
if (!Cookies.get('token')) {
|
||||
navigate('/users/login', {
|
||||
state: {
|
||||
name: 'dashboard',
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ import { UpdateForm } from 'controllers/FormControllers';
|
|||
import { useNavigate } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
import { useUser } from 'contexts';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export default function Register() {
|
||||
const navigate = useNavigate();
|
||||
const { userData: loading } = useUser();
|
||||
|
||||
useEffect(() => {
|
||||
if (loading === false) {
|
||||
if (Cookies.get('token')) {
|
||||
navigate('/users/login', {
|
||||
state: {
|
||||
name: 'dashboard',
|
||||
|
|
@ -18,7 +18,7 @@ export default function Register() {
|
|||
},
|
||||
});
|
||||
}
|
||||
}, [loading, navigate]);
|
||||
}, [navigate]);
|
||||
|
||||
return (
|
||||
<Grid
|
||||
|
|
|
|||
|
|
@ -4,14 +4,12 @@ import { composeMailFields } from 'services/fields';
|
|||
import { postMail } from 'services/mailServices';
|
||||
import { mailSchema } from 'services/schemas';
|
||||
import { useEffect } from 'react';
|
||||
import { useUser } from 'contexts';
|
||||
|
||||
export default function SendMailController() {
|
||||
const { userData } = useUser();
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export default function SendMailController({ sendMail }) {
|
||||
const navigate = useNavigate();
|
||||
useEffect(() => {
|
||||
if (checkAuth()) {
|
||||
if (!Cookies.get('token')) {
|
||||
navigate('/users/login', {
|
||||
state: {
|
||||
name: 'ask',
|
||||
|
|
@ -22,15 +20,9 @@ export default function SendMailController() {
|
|||
}
|
||||
}, []);
|
||||
|
||||
function checkAuth() {
|
||||
if (!userData.username) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return Form({
|
||||
fields: composeMailFields,
|
||||
onSubmit: postMail,
|
||||
onSubmit: sendMail,
|
||||
validationSchema: mailSchema,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue