mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
Fix login page loop bug
This commit is contained in:
parent
6335690046
commit
41bcc78c3a
@ -19,7 +19,7 @@ import { logoutUser, getUserData } from './redux/actions/userActions';
|
||||
// Components
|
||||
import AuthRoute from "./util/AuthRoute";
|
||||
|
||||
axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
||||
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
||||
|
||||
// Pages
|
||||
import home from './pages/Home';
|
||||
@ -36,14 +36,19 @@ const theme = createMuiTheme(themeObject);
|
||||
|
||||
const token = localStorage.FBIdToken;
|
||||
if (token) {
|
||||
const decodedToken = jwtDecode(token);
|
||||
if (decodedToken.exp * 1000 < Date.now()) {
|
||||
store.dispatch(logoutUser);
|
||||
try {
|
||||
const decodedToken = jwtDecode(token);
|
||||
if (decodedToken.exp * 1000 < Date.now()) {
|
||||
store.dispatch(logoutUser());
|
||||
window.location.href = "/login";
|
||||
} else {
|
||||
store.dispatch({ type: SET_AUTHENTICATED });
|
||||
axios.defaults.headers.common['Authorization'] = token;
|
||||
store.dispatch(getUserData());
|
||||
}
|
||||
} catch (invalidTokenError) {
|
||||
store.dispatch(logoutUser());
|
||||
window.location.href = "/login";
|
||||
} else {
|
||||
store.dispatch({ type: SET_AUTHENTICATED });
|
||||
axios.defaults.headers.common['Authorization'] = token;
|
||||
store.dispatch(getUserData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user