handling logout

This commit is contained in:
Belen Curcio
2017-05-15 13:13:28 -03:00
parent 5dae7bf4ac
commit 4e86e4197c
5 changed files with 19 additions and 4 deletions
+8 -2
View File
@@ -4,6 +4,7 @@ import * as Storage from '../helpers/storage';
import * as actions from '../constants/auth';
import coralApi, {base} from '../helpers/response';
import client from 'coral-framework/services/client';
import jwtDecode from 'jwt-decode';
const lang = new I18n(translations);
import translations from './../translations';
@@ -139,6 +140,7 @@ const signInFailure = error => ({
//==============================================================================
const handleAuthToken = token => dispatch => {
Storage.setItem('exp', jwtDecode(token).exp);
Storage.setItem('token', token);
dispatch({type: 'HANDLE_AUTH_TOKEN'});
};
@@ -290,8 +292,12 @@ export const fetchForgotPassword = email => dispatch => {
//==============================================================================
export const logout = () => dispatch => {
dispatch({type: actions.LOGOUT});
Storage.removeItem('token');
return coralApi('/auth', {method: 'DELETE'})
.then(() => {
dispatch({type: actions.LOGOUT});
Storage.removeItem('token');
fetchMe();
});
};
//==============================================================================
+5 -1
View File
@@ -10,17 +10,22 @@ function storageAvailable(type) {
error = e;
return (
e instanceof DOMException &&
// everything except Firefox
(e.code === 22 ||
// Firefox
e.code === 1014 ||
// test name field too, because code might not be present
// everything except Firefox
e.name === 'QuotaExceededError' ||
// Firefox
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
// acknowledge QuotaExceededError only if there's something already stored
storage.length !== 0
);
@@ -34,7 +39,6 @@ function lazyCheckStorage() {
}
export function getItem(item = '') {
console.log(`asking for item ${item}`);
lazyCheckStorage();
if (available) {
+1 -1
View File
@@ -1,4 +1,4 @@
import ApolloClient, {createNetworkInterface} from 'apollo-client';
import {createNetworkInterface} from 'apollo-client';
import * as Storage from '../helpers/storage';
//==============================================================================