mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-09-11 22:06:29 +02:00
Fix auth with jwt and localDb only in dev
This commit is contained in:
@@ -3,16 +3,16 @@ import { AppState } from "."
|
||||
|
||||
// Define a type for the slice state
|
||||
interface AuthState {
|
||||
jwt: string
|
||||
id: number
|
||||
roles: string[]
|
||||
jwt: string
|
||||
}
|
||||
|
||||
// Define the initial state using that type
|
||||
const initialState: AuthState = {
|
||||
jwt: "",
|
||||
id: 0,
|
||||
roles: [],
|
||||
jwt: "",
|
||||
}
|
||||
|
||||
export const auth = createSlice({
|
||||
@@ -20,15 +20,15 @@ export const auth = createSlice({
|
||||
initialState,
|
||||
reducers: {
|
||||
setCurrentUser: (state, action: PayloadAction<AuthState>) => {
|
||||
state.jwt = action.payload.jwt
|
||||
state.id = action.payload.id
|
||||
state.roles = action.payload.roles
|
||||
state.jwt = action.payload.jwt
|
||||
},
|
||||
logoutUser: (state) => {
|
||||
// Unused, just reload page :/
|
||||
state.jwt = ""
|
||||
state.id = 0
|
||||
state.roles = []
|
||||
state.jwt = ""
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@@ -42,13 +42,13 @@ const createStore = ({ initialState, url, jwt, id, roles }: Arg = {}) => {
|
||||
return { store, history }
|
||||
}
|
||||
|
||||
const jwt = Cookies.get("jwt")
|
||||
const id = +(Cookies.get("id") || 0)
|
||||
const roles = Cookies.get("roles")?.split(",") || []
|
||||
const jwt = Cookies.get("jwt")
|
||||
if (id && jwt && roles) {
|
||||
if (jwt && id && roles) {
|
||||
Cookies.set("jwt", jwt, { expires: 3650 })
|
||||
Cookies.set("id", `${id}`, { expires: 3650 })
|
||||
Cookies.set("roles", roles.join(","), { expires: 3650 })
|
||||
Cookies.set("jwt", jwt, { expires: 3650 })
|
||||
}
|
||||
const { store } = createStore({ jwt, id, roles })
|
||||
|
||||
|
@@ -50,7 +50,7 @@ export const fetchVolunteerDayWishesSetIfNeed =
|
||||
let jwt = ""
|
||||
|
||||
if (!id) {
|
||||
;({ id, jwt } = getState().auth)
|
||||
;({ jwt, id } = getState().auth)
|
||||
}
|
||||
if (shouldFetchVolunteerDayWishesSet(getState(), id))
|
||||
return dispatch(fetchVolunteerDayWishesSet(jwt, id, wishes))
|
||||
|
@@ -50,7 +50,7 @@ export const fetchVolunteerNotifsSetIfNeed =
|
||||
let jwt = ""
|
||||
|
||||
if (!id) {
|
||||
;({ id, jwt } = getState().auth)
|
||||
;({ jwt, id } = getState().auth)
|
||||
}
|
||||
if (shouldFetchVolunteerNotifsSet(getState(), id))
|
||||
return dispatch(fetchVolunteerNotifsSet(jwt, id, notif))
|
||||
|
@@ -54,7 +54,7 @@ export const fetchVolunteerParticipationDetailsSetIfNeed =
|
||||
let jwt = ""
|
||||
|
||||
if (!id) {
|
||||
;({ id, jwt } = getState().auth)
|
||||
;({ jwt, id } = getState().auth)
|
||||
}
|
||||
if (shouldFetchVolunteerParticipationDetailsSet(getState(), id))
|
||||
return dispatch(fetchVolunteerParticipationDetailsSet(jwt, id, wishes))
|
||||
|
@@ -50,7 +50,7 @@ export const fetchVolunteerTeamWishesSetIfNeed =
|
||||
let jwt = ""
|
||||
|
||||
if (!id) {
|
||||
;({ id, jwt } = getState().auth)
|
||||
;({ jwt, id } = getState().auth)
|
||||
}
|
||||
if (shouldFetchVolunteerTeamWishesSet(getState(), id))
|
||||
return dispatch(fetchVolunteerTeamWishesSet(jwt, id, wishes))
|
||||
|
Reference in New Issue
Block a user