diff --git a/src/app/auth/permission/denied/page.tsx b/src/app/auth/permission/denied/page.tsx index 66e5f3d..de6e0ce 100644 --- a/src/app/auth/permission/denied/page.tsx +++ b/src/app/auth/permission/denied/page.tsx @@ -2,6 +2,7 @@ import { Alert, AlertTitle, Card, Container } from "@mui/material"; import { Box } from "@mui/system"; import { Metadata } from "next"; +import AuthAutoLogout from "@/components/AuthLogoutComponent"; import DynamicLink from "@/components/DynamicLink"; export const metadata: Metadata = { @@ -32,6 +33,7 @@ export default function PermissionDeniedPage() { Tilbake til innloggingssiden + diff --git a/src/components/AuthLinker.tsx b/src/components/AuthLinker.tsx index db589c6..006920f 100644 --- a/src/components/AuthLinker.tsx +++ b/src/components/AuthLinker.tsx @@ -8,7 +8,7 @@ import { } from "next/navigation"; import { ReactNode, useEffect, useState } from "react"; -import { isLoggedIn } from "@/api/auth"; +import { isEmployee, isLoggedIn } from "@/api/auth"; import { addAccessToken, addRefreshToken, @@ -42,7 +42,9 @@ export function executeReturnRedirect( if (caller === "bl-web") { target = `${BL_CONFIG.blWeb.basePath}auth/gateway?redirect=${redirect}`; } else if (caller === "bl-admin") { - target = `${BL_CONFIG.blAdmin.basePath}auth/gateway`; + target = isEmployee() + ? `${BL_CONFIG.blAdmin.basePath}auth/gateway` + : "/auth/permission/denied"; } else { target = `/${redirect ?? ""}`; } diff --git a/src/components/AuthLogoutComponent.tsx b/src/components/AuthLogoutComponent.tsx new file mode 100644 index 0000000..211be48 --- /dev/null +++ b/src/components/AuthLogoutComponent.tsx @@ -0,0 +1,11 @@ +"use client"; +import { useEffect } from "react"; + +import { logout } from "@/api/auth"; + +export default function AuthLogoutComponent() { + useEffect(() => { + logout(); + }, []); + return null; +}