- fetchAuthService erstellt zum Auslesen von isAdminLoggedIn aus localStorage - getAuthThunks Thunk implementiert zur Initialisierung von authSlice - authSlice erweitert um setIsAdminLoggedIn Reducer - dispatch(getAuthThunks()) in _app.tsx integriert für automatische Initialisierung bei App-Start - Flackern und falscher Admin-Status nach Reload dauerhaft behoben
13 lines
448 B
TypeScript
13 lines
448 B
TypeScript
// redux/thunks/getAuthThunks.ts
|
|
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
import { fetchAuthService } from "@/services/fetchAuthService";
|
|
import { setAdminLoggedIn } from "@/redux/slices/authSlice";
|
|
|
|
export const getAuthThunks = createAsyncThunk(
|
|
"auth/getAuthThunks",
|
|
async (_, { dispatch }) => {
|
|
const { isAdminLoggedIn } = fetchAuthService();
|
|
dispatch(setAdminLoggedIn(isAdminLoggedIn)); // boolean, nicht string!
|
|
}
|
|
);
|