Clean up middleware, add security-headers to non-Zammad pages
This commit is contained in:
parent
027aac3a92
commit
8c6e954fdf
9 changed files with 81 additions and 62 deletions
30
apps/link/app/_components/ZammadLoginProvider.tsx
Normal file
30
apps/link/app/_components/ZammadLoginProvider.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"use client";
|
||||
|
||||
import { FC, PropsWithChildren, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
export const ZammadLoginProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
const { data: session, status, update } = useSession();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const checkSession = async () => {
|
||||
if (status === "authenticated") {
|
||||
const response = await fetch("/api/v1/users/me", {
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
if (response.status !== 200) {
|
||||
window.location.href = "/auth/sso";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const interval = setInterval(checkSession, 15000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [session, status, update, router]);
|
||||
|
||||
return children;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue