mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 21:14:45 +08:00
handling logout
This commit is contained in:
@@ -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();
|
||||
});
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
import ApolloClient, {createNetworkInterface} from 'apollo-client';
|
||||
import {createNetworkInterface} from 'apollo-client';
|
||||
import * as Storage from '../helpers/storage';
|
||||
|
||||
//==============================================================================
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
"inquirer": "^3.0.6",
|
||||
"joi": "^10.4.1",
|
||||
"jsonwebtoken": "^7.3.0",
|
||||
"jwt-decode": "^2.2.0",
|
||||
"kue": "^0.11.5",
|
||||
"linkify-it": "^2.0.3",
|
||||
"lodash": "^4.16.6",
|
||||
|
||||
@@ -4600,6 +4600,10 @@ jws@^3.1.4:
|
||||
jwa "^1.1.4"
|
||||
safe-buffer "^5.0.1"
|
||||
|
||||
jwt-decode@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-2.2.0.tgz#7d86bd56679f58ce6a84704a657dd392bba81a79"
|
||||
|
||||
kareem@1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/kareem/-/kareem-1.4.0.tgz#640285bc0174f10d4bf2127bb30e861bc0372c1c"
|
||||
|
||||
Reference in New Issue
Block a user