feat(validation): complete validation editor and master data modules

This commit is contained in:
Schubert Ferenc 2026-07-10 22:42:03 +02:00
parent 2b5c765e41
commit f73a24df13
73 changed files with 10194 additions and 0 deletions

View file

@ -0,0 +1,51 @@
"use client";
import { useRouter } from "next/navigation";
import { createContext, useContext, useEffect, useMemo, useState } from "react";
type AuthContextValue = {
token: string | null;
setToken: (value: string | null) => void;
logout: () => void;
};
const AuthContext = createContext<AuthContextValue | null>(null);
export function AuthProvider({ children }: { children: React.ReactNode }) {
const router = useRouter();
const [token, setTokenState] = useState<string | null>(null);
useEffect(() => {
setTokenState(window.localStorage.getItem("atlas_token"));
}, []);
const value = useMemo<AuthContextValue>(() => {
const setToken = (next: string | null) => {
setTokenState(next);
if (next) {
window.localStorage.setItem("atlas_token", next);
} else {
window.localStorage.removeItem("atlas_token");
}
};
return {
token,
setToken,
logout: () => {
setToken(null);
router.push("/login");
}
};
}, [router, token]);
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
export function useAuth() {
const value = useContext(AuthContext);
if (!value) {
throw new Error("useAuth must be used inside AuthProvider");
}
return value;
}