fix logout problems
This commit is contained in:
@@ -2,6 +2,7 @@ import axios from 'axios';
|
||||
|
||||
import { HOST } from '../constants';
|
||||
import { logout } from '../redux/actions/userActions';
|
||||
import { useDispatch } from 'react-redux';
|
||||
|
||||
const authenticate = async (code, privateAccess, userKey) => {
|
||||
try {
|
||||
@@ -22,13 +23,14 @@ const authenticate = async (code, privateAccess, userKey) => {
|
||||
};
|
||||
|
||||
const getUserMetadata = async (userKey) => {
|
||||
const dispatch = useDispatch();
|
||||
try {
|
||||
const fullUrl = `https://${HOST}/api/user-access?user_key=${userKey}`;
|
||||
const result = await axios.get(fullUrl);
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
if (error.response && error.response.status === 404) {
|
||||
logout(userKey);
|
||||
dispatch(logout(userKey));
|
||||
}
|
||||
console.error(error);
|
||||
return null;
|
||||
|
||||
@@ -21,7 +21,7 @@ export default (state = initialState, action) => {
|
||||
case types.LOGOUT:
|
||||
if (
|
||||
action.payload.userKey !== null &&
|
||||
action.payload.userKey !== localStorage.getItem('userKey')
|
||||
action.payload.userKey !== JSON.parse(localStorage.getItem('userKey'))
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user