mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
Handling non safari browsers
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import {pym} from 'coral-framework';
|
||||
import * as Storage from '../helpers/storage';
|
||||
import * as actions from '../constants/auth';
|
||||
import coralApi, {base} from '../helpers/response';
|
||||
import jwtDecode from 'jwt-decode';
|
||||
import {pym} from 'coral-framework';
|
||||
import browser from 'detect-browser';
|
||||
import * as actions from '../constants/auth';
|
||||
import * as Storage from '../helpers/storage';
|
||||
import coralApi, {base} from '../helpers/response';
|
||||
|
||||
const lang = new I18n(translations);
|
||||
import translations from './../translations';
|
||||
import I18n from '../../coral-framework/modules/i18n/i18n';
|
||||
|
||||
// Dialog Actions
|
||||
export const showSignInDialog = () => (dispatch) => {
|
||||
const signInPopUp = window.open(
|
||||
'/embed/stream/login',
|
||||
@@ -112,8 +112,10 @@ const signInFailure = (error) => ({
|
||||
//==============================================================================
|
||||
|
||||
export const handleAuthToken = (token) => (dispatch) => {
|
||||
Storage.setItem('exp', jwtDecode(token).exp);
|
||||
Storage.setItem('token', token);
|
||||
if (!browser || browser.name !== 'safari') {
|
||||
Storage.setItem('exp', jwtDecode(token).exp);
|
||||
Storage.setItem('token', token);
|
||||
}
|
||||
dispatch({type: 'HANDLE_AUTH_TOKEN'});
|
||||
};
|
||||
|
||||
@@ -269,7 +271,9 @@ export const fetchForgotPassword = (email) => (dispatch) => {
|
||||
|
||||
export const logout = () => (dispatch) => {
|
||||
return coralApi('/auth', {method: 'DELETE'}).then(() => {
|
||||
Storage.removeItem('token');
|
||||
if (!browser || browser.name !== 'safari') {
|
||||
Storage.removeItem('token');
|
||||
}
|
||||
dispatch({type: actions.LOGOUT});
|
||||
});
|
||||
};
|
||||
@@ -292,7 +296,9 @@ export const checkLogin = () => (dispatch) => {
|
||||
coralApi('/auth')
|
||||
.then((result) => {
|
||||
if (!result.user) {
|
||||
Storage.removeItem('token');
|
||||
if (!browser || browser.name !== 'safari') {
|
||||
Storage.removeItem('token');
|
||||
}
|
||||
throw new Error('Not logged in');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
import * as Storage from './storage';
|
||||
import browser from 'detect-browser';
|
||||
|
||||
const buildOptions = (inputOptions = {}) => {
|
||||
const defaultOptions = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${Storage.getItem('token')}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'same-origin'
|
||||
};
|
||||
|
||||
let options = Object.assign({}, defaultOptions, inputOptions);
|
||||
options.headers = Object.assign(
|
||||
{},
|
||||
defaultOptions.headers,
|
||||
inputOptions.headers
|
||||
);
|
||||
let options = {
|
||||
defaultOptions,
|
||||
...inputOptions
|
||||
};
|
||||
|
||||
if (!browser || browser.name !== 'safari') {
|
||||
let authorization = localStorage.getItem('token');
|
||||
|
||||
if (authorization) {
|
||||
options.headers = {
|
||||
Authorization: `Bearer ${authorization}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (options.method.toLowerCase() !== 'get') {
|
||||
options.body = JSON.stringify(options.body);
|
||||
@@ -25,9 +32,9 @@ const buildOptions = (inputOptions = {}) => {
|
||||
return options;
|
||||
};
|
||||
|
||||
const handleResp = (res) => {
|
||||
const handleResp = res => {
|
||||
if (res.status > 399) {
|
||||
return res.json().then((err) => {
|
||||
return res.json().then(err => {
|
||||
let message = err.message || res.status;
|
||||
const error = new Error();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user