Browse Source

removed cookies

feature/qrscanner
Nareshkumar Rao 3 years ago
parent
commit
77f0b3b753
  1. 4
      src/features/auth/authSlice.js
  2. 6
      src/screens/LoginScreen.js

4
src/features/auth/authSlice.js

@ -9,11 +9,13 @@ export const authSlice = createSlice({
name: 'auth', name: 'auth',
initialState, initialState,
reducers: { reducers: {
authLogin: (state, action) => {
authLogin: state => {
state.isAuthenticated = true; state.isAuthenticated = true;
Cookies.set('authorized', true);
}, },
authLogout: state => { authLogout: state => {
state.isAuthenticated = false; state.isAuthenticated = false;
Cookies.set('authorized', false);
}, },
}, },
}); });

6
src/screens/LoginScreen.js

@ -10,7 +10,7 @@ import axios from 'axios';
import { React, useState } from 'react'; import { React, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Redirect, useHistory } from 'react-router-dom'; import { Redirect, useHistory } from 'react-router-dom';
import { authLogin } from '../features/auth/authSlice';
import { authLogin, authLogout } from '../features/auth/authSlice';
function Login() { function Login() {
const [email, setEmail] = useState(null); const [email, setEmail] = useState(null);
@ -21,7 +21,7 @@ function Login() {
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); const isAuthenticated = useSelector(state => state.auth.isAuthenticated);
if (isAuthenticated) return <Redirect to="/home" />; if (isAuthenticated) return <Redirect to="/home" />;
const handleSubmit = e => { const handleSubmit = e => {
if (!email | !password) { if (!email | !password) {
toast({ toast({
@ -57,6 +57,7 @@ function Login() {
dispatch(authLogin()); dispatch(authLogin());
history.push('/home'); history.push('/home');
} else { } else {
dispatch(authLogout());
toast({ toast({
title: 'An error occurred', title: 'An error occurred',
description: response.data.message, description: response.data.message,
@ -67,6 +68,7 @@ function Login() {
} }
}) })
.catch(err => { .catch(err => {
dispatch(authLogout());
toast({ toast({
title: 'An error occurred', title: 'An error occurred',
description: 'Sorry, an error occurred on our side.', description: 'Sorry, an error occurred on our side.',

Loading…
Cancel
Save