feat: Auth-Status bei App-Start aus localStorage laden und in Redux speichern
- 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
This commit is contained in:
@@ -6,6 +6,6 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false
|
|||||||
NEXT_PUBLIC_EXPORT_STATIC=false
|
NEXT_PUBLIC_EXPORT_STATIC=false
|
||||||
NEXT_PUBLIC_USE_CGI=false
|
NEXT_PUBLIC_USE_CGI=false
|
||||||
# App-Versionsnummer
|
# App-Versionsnummer
|
||||||
NEXT_PUBLIC_APP_VERSION=1.6.520
|
NEXT_PUBLIC_APP_VERSION=1.6.521
|
||||||
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)
|
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL
|
|||||||
NEXT_PUBLIC_EXPORT_STATIC=true
|
NEXT_PUBLIC_EXPORT_STATIC=true
|
||||||
NEXT_PUBLIC_USE_CGI=true
|
NEXT_PUBLIC_USE_CGI=true
|
||||||
# App-Versionsnummer
|
# App-Versionsnummer
|
||||||
NEXT_PUBLIC_APP_VERSION=1.6.520
|
NEXT_PUBLIC_APP_VERSION=1.6.521
|
||||||
NEXT_PUBLIC_CPL_MODE=production
|
NEXT_PUBLIC_CPL_MODE=production
|
||||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,3 +1,13 @@
|
|||||||
|
## [1.6.521] – 2025-07-02
|
||||||
|
|
||||||
|
- refactor: Admin-Status direkt aus Redux ausgelesen und Props entfernt
|
||||||
|
|
||||||
|
- isAdminLoggedIn wird jetzt direkt aus authSlice im Redux-Store gelesen
|
||||||
|
- useAdminAuth und Prop-Weitergabe entfernt
|
||||||
|
- Flackern des Firmware-Buttons dauerhaft behoben
|
||||||
|
- Codestruktur vereinfacht und stabilisiert
|
||||||
|
|
||||||
|
---
|
||||||
## [1.6.520] – 2025-07-02
|
## [1.6.520] – 2025-07-02
|
||||||
|
|
||||||
- refactor: Admin-Status direkt aus Redux ausgelesen und Props entfernt
|
- refactor: Admin-Status direkt aus Redux ausgelesen und Props entfernt
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "cpl-v4",
|
"name": "cpl-v4",
|
||||||
"version": "1.6.520",
|
"version": "1.6.521",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cpl-v4",
|
"name": "cpl-v4",
|
||||||
"version": "1.6.520",
|
"version": "1.6.521",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/roboto": "^5.1.0",
|
"@fontsource/roboto": "^5.1.0",
|
||||||
"@iconify-icons/ri": "^1.2.10",
|
"@iconify-icons/ri": "^1.2.10",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cpl-v4",
|
"name": "cpl-v4",
|
||||||
"version": "1.6.520",
|
"version": "1.6.521",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { getReferenceCurveBySlotThunk } from "@/redux/thunks/getReferenceCurveBy
|
|||||||
import { getAllTDRReferenceChartThunk } from "@/redux/thunks/getAllTDRReferenceChartThunk";
|
import { getAllTDRReferenceChartThunk } from "@/redux/thunks/getAllTDRReferenceChartThunk";
|
||||||
import { getTDRChartDataByIdThunk } from "@/redux/thunks/getTDRChartDataByIdThunk";
|
import { getTDRChartDataByIdThunk } from "@/redux/thunks/getTDRChartDataByIdThunk";
|
||||||
import { getLoopChartDataThunk } from "@/redux/thunks/getLoopChartDataThunk";
|
import { getLoopChartDataThunk } from "@/redux/thunks/getLoopChartDataThunk";
|
||||||
|
import { getAuthThunks } from "@/redux/thunks/getAuthThunks";
|
||||||
import Modal from "react-modal";
|
import Modal from "react-modal";
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
Modal.setAppElement("#__next"); // oder "#root", je nach App-Struktur
|
Modal.setAppElement("#__next"); // oder "#root", je nach App-Struktur
|
||||||
@@ -54,6 +55,7 @@ function AppContent({
|
|||||||
const pathname = window.location.pathname;
|
const pathname = window.location.pathname;
|
||||||
|
|
||||||
const loadAndDispatch = () => {
|
const loadAndDispatch = () => {
|
||||||
|
dispatch(getAuthThunks());
|
||||||
if (pathname.includes("kabelueberwachung")) {
|
if (pathname.includes("kabelueberwachung")) {
|
||||||
dispatch(getKueDataThunk());
|
dispatch(getKueDataThunk());
|
||||||
} else if (pathname.includes("digitalOutputs")) {
|
} else if (pathname.includes("digitalOutputs")) {
|
||||||
|
|||||||
12
redux/thunks/getAuthThunks.ts
Normal file
12
redux/thunks/getAuthThunks.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// 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!
|
||||||
|
}
|
||||||
|
);
|
||||||
6
services/fetchAuthService.ts
Normal file
6
services/fetchAuthService.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// services/fetchAuthService.ts
|
||||||
|
export const fetchAuthService = () => {
|
||||||
|
const isAdminLoggedInRaw = localStorage.getItem("isAdminLoggedIn");
|
||||||
|
const isAdminLoggedIn = isAdminLoggedInRaw === "true"; // <– explizit Boolean
|
||||||
|
return { isAdminLoggedIn };
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user