diff --git a/jest/config.js b/jest/config.js index 3ac0720..f907412 100644 --- a/jest/config.js +++ b/jest/config.js @@ -23,7 +23,6 @@ module.exports = { __SERVER__: false, __LOCAL__: false, __TEST__: true, - localStorage: { getItem: () => null, setItem: () => null, removeItem: () => null }, }, maxConcurrency: 50, maxWorkers: 1, diff --git a/src/client/index.tsx b/src/client/index.tsx index 2960f9b..f0b9947 100755 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -8,13 +8,15 @@ import Cookies from "js-cookie" import createStore from "../store" import routes from "../routes" -const storage: any = localStorage - // Get the initial state from server-side rendering const initialState = window.__INITIAL_STATE__ -const id = +(Cookies.get("id") || storage?.getItem("id")) -const jwt = Cookies.get("jwt") || storage?.getItem("jwt") +const id = +(Cookies.get("id") || 0) +const jwt = Cookies.get("jwt") +if (id && jwt) { + Cookies.set("id", `${id}`, { expires: 3650 }) + Cookies.set("jwt", jwt, { expires: 3650 }) +} const { store, history } = createStore({ initialState, id, jwt }) const render = (Routes: RouteConfig[]) => diff --git a/src/services/auth.ts b/src/services/auth.ts index 8ef6525..ff74daf 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -3,24 +3,18 @@ import Cookies from "js-cookie" import { VolunteerLogin } from "./volunteers" -const storage: any = localStorage - export const axiosConfig: AxiosRequestConfig = { headers: {}, } export function setJWT(token: string, id: number): void { axiosConfig.headers.Authorization = `Bearer ${token}` - storage?.setItem("jwt", token) - storage?.setItem("id", id) Cookies.set("jwt", token, { expires: 3650 }) Cookies.set("id", `${id}`, { expires: 3650 }) } export function unsetJWT(): void { delete axiosConfig.headers.Authorization - storage?.removeItem("jwt") - storage?.removeItem("id") Cookies.remove("jwt") Cookies.remove("id") diff --git a/src/store/index.ts b/src/store/index.ts index af49c9f..2944046 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -41,10 +41,12 @@ const createStore = ({ initialState, url, jwt, id }: Arg = {}) => { return { store, history } } -const storage: any = localStorage -const id = +(Cookies.get("id") || storage?.getItem("id")) -const jwt = Cookies.get("jwt") || storage?.getItem("jwt") - +const id = +(Cookies.get("id") || 0) +const jwt = Cookies.get("jwt") +if (id && jwt) { + Cookies.set("id", `${id}`, { expires: 3650 }) + Cookies.set("jwt", jwt, { expires: 3650 }) +} const { store } = createStore({ id, jwt }) export type AppState = ReturnType diff --git a/webpack/server.config.ts b/webpack/server.config.ts index cea8955..5b12d75 100644 --- a/webpack/server.config.ts +++ b/webpack/server.config.ts @@ -30,7 +30,6 @@ const config: Configuration = { raw: true, }), new webpack.DefinePlugin({ - localStorage: { getItem: () => null, setItem: () => null, removeItem: () => null }, "location.protocol": "http:", }), ],