aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-frontend
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-09-05 15:29:24 +0100
committerGravatar Joe Banks <[email protected]>2024-09-05 15:29:24 +0100
commitd4a1202f08568fb971b794d91695fbb2fdc9878e (patch)
treee13c52d7da8f69b56244bf111555dabc03d790b9 /thallium-frontend
parentRefactor login methods to new API file (diff)
Store current refresh task in authorization slice
Diffstat (limited to 'thallium-frontend')
-rw-r--r--thallium-frontend/src/slices/authorization.ts6
-rw-r--r--thallium-frontend/src/store.ts7
2 files changed, 11 insertions, 2 deletions
diff --git a/thallium-frontend/src/slices/authorization.ts b/thallium-frontend/src/slices/authorization.ts
index 6ebc159..5e9e8ca 100644
--- a/thallium-frontend/src/slices/authorization.ts
+++ b/thallium-frontend/src/slices/authorization.ts
@@ -5,6 +5,7 @@ const authorizationSlice = createSlice({
initialState: {
voucherToken: null as string | null,
userToken: null as string | null,
+ refreshTask: null as NodeJS.Timeout | null,
},
reducers: {
setVoucherToken(state, action: { payload: string }) {
@@ -16,10 +17,13 @@ const authorizationSlice = createSlice({
clearToken(state) {
state.voucherToken = null;
state.userToken = null;
+ },
+ setRefreshTask(state, action: { payload: NodeJS.Timeout }) {
+ state.refreshTask = action.payload;
}
},
});
-export const { setVoucherToken, setUserToken, clearToken } = authorizationSlice.actions;
+export const { setVoucherToken, setUserToken, clearToken, setRefreshTask } = authorizationSlice.actions;
export default authorizationSlice.reducer;
diff --git a/thallium-frontend/src/store.ts b/thallium-frontend/src/store.ts
index 96c4405..d9b4873 100644
--- a/thallium-frontend/src/store.ts
+++ b/thallium-frontend/src/store.ts
@@ -18,6 +18,7 @@ const found = localStorage.getItem("authorizationState");
let persistedState: RootState["authorization"] = {
voucherToken: null,
userToken: null,
+ refreshTask: null,
};
if (found) {
@@ -35,5 +36,9 @@ export type AppStore = ReturnType<typeof setupStore>;
store.subscribe(() => {
console.log("Serializing state to localStorage");
- localStorage.setItem("authorizationState", JSON.stringify(store.getState().authorization));
+ const authState = store.getState().authorization;
+ localStorage.setItem("authorizationState", JSON.stringify({
+ voucherToken: authState.voucherToken,
+ userToken: authState.userToken,
+ }));
});