mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-08 00:24:21 +02:00
Remove localStorage support because it breaks ssr
This commit is contained in:
parent
b21b77e513
commit
3264336aab
@ -23,7 +23,6 @@ module.exports = {
|
||||
__SERVER__: false,
|
||||
__LOCAL__: false,
|
||||
__TEST__: true,
|
||||
localStorage: { getItem: () => null, setItem: () => null, removeItem: () => null },
|
||||
},
|
||||
maxConcurrency: 50,
|
||||
maxWorkers: 1,
|
||||
|
@ -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[]) =>
|
||||
|
@ -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")
|
||||
|
@ -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<typeof store.getState>
|
||||
|
@ -30,7 +30,6 @@ const config: Configuration = {
|
||||
raw: true,
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
localStorage: { getItem: () => null, setItem: () => null, removeItem: () => null },
|
||||
"location.protocol": "http:",
|
||||
}),
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user