Skip to content
This repository was archived by the owner on Apr 9, 2022. It is now read-only.

Commit 079f4d5

Browse files
committed
only persist token for development
1 parent 7c4fa26 commit 079f4d5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

client/src/store/auth.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from './types';
1111

1212
const TOKEN_STORAGE_KEY = 'TOKEN_STORAGE_KEY';
13+
const isProduction = process.env.NODE_ENV === 'production';
1314

1415
const initialState = {
1516
authenticating: false,
@@ -37,11 +38,13 @@ const actions = {
3738
initialize({ commit }) {
3839
const token = localStorage.getItem(TOKEN_STORAGE_KEY);
3940

40-
if (token) {
41-
commit(SET_TOKEN, token);
42-
} else {
41+
if (isProduction && token) {
4342
commit(REMOVE_TOKEN);
4443
}
44+
45+
if (!isProduction && token) {
46+
commit(SET_TOKEN, token);
47+
}
4548
},
4649
};
4750

@@ -63,7 +66,7 @@ const mutations = {
6366
state.error = false;
6467
},
6568
[SET_TOKEN](state, token) {
66-
localStorage.setItem(TOKEN_STORAGE_KEY, token);
69+
if (!isProduction) localStorage.setItem(TOKEN_STORAGE_KEY, token);
6770
session.defaults.headers.Authorization = `Token ${token}`;
6871
state.token = token;
6972
},

0 commit comments

Comments
 (0)