From 77f0b3b753a97900c532f6b1230a314e9c53ac7d Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao <_accounts@nareshkumarrao.com> Date: Mon, 26 Jul 2021 18:48:29 +0200 Subject: [PATCH] removed cookies --- src/features/auth/authSlice.js | 4 +++- src/screens/LoginScreen.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/features/auth/authSlice.js b/src/features/auth/authSlice.js index 5823c91..92146e1 100644 --- a/src/features/auth/authSlice.js +++ b/src/features/auth/authSlice.js @@ -9,11 +9,13 @@ export const authSlice = createSlice({ name: 'auth', initialState, reducers: { - authLogin: (state, action) => { + authLogin: state => { state.isAuthenticated = true; + Cookies.set('authorized', true); }, authLogout: state => { state.isAuthenticated = false; + Cookies.set('authorized', false); }, }, }); diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index c7d0789..833aba8 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -10,7 +10,7 @@ import axios from 'axios'; import { React, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Redirect, useHistory } from 'react-router-dom'; -import { authLogin } from '../features/auth/authSlice'; +import { authLogin, authLogout } from '../features/auth/authSlice'; function Login() { const [email, setEmail] = useState(null); @@ -21,7 +21,7 @@ function Login() { const isAuthenticated = useSelector(state => state.auth.isAuthenticated); if (isAuthenticated) return ; - + const handleSubmit = e => { if (!email | !password) { toast({ @@ -57,6 +57,7 @@ function Login() { dispatch(authLogin()); history.push('/home'); } else { + dispatch(authLogout()); toast({ title: 'An error occurred', description: response.data.message, @@ -67,6 +68,7 @@ function Login() { } }) .catch(err => { + dispatch(authLogout()); toast({ title: 'An error occurred', description: 'Sorry, an error occurred on our side.',