Skip to content

Commit 28cfce2

Browse files
remo5000ning-y
authored andcommitted
Fix Local Storage not using stored accessToken and refreshToken (#224)
* Add documentation for ISavedState * Store role in localStorage * Format localStorage
1 parent 14431f0 commit 28cfce2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/localStorage.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import { IState } from './reducers/states'
1+
import { IState, Role } from './reducers/states'
22
import { HistoryHelper } from './utils/history'
33

4+
/**
5+
* Note that the properties in this interface are a
6+
* subset of the properties in IState.session, so an instance
7+
* of an object that implements this interface cannot
8+
* be used as a substitute for IState. Rather, it can be used
9+
* to complement defaultState.session with saved properties.
10+
*/
411
export interface ISavedState {
512
historyHelper: HistoryHelper
613
accessToken?: string
714
refreshToken?: string
15+
role?: Role
816
username?: string
917
}
1018

@@ -17,6 +25,7 @@ export const loadStoredState = (): ISavedState | undefined => {
1725
return JSON.parse(serializedState) as ISavedState
1826
}
1927
} catch (err) {
28+
// Issue #143
2029
return undefined
2130
}
2231
}
@@ -27,6 +36,7 @@ export const saveState = (state: IState) => {
2736
accessToken: state.session.accessToken,
2837
historyHelper: state.session.historyHelper,
2938
refreshToken: state.session.refreshToken,
39+
role: state.session.role,
3040
username: state.session.username
3141
}
3242
const serialized = JSON.stringify(stateToBeSaved)

0 commit comments

Comments
 (0)