Skip to content

Commit

Permalink
fix(AuthLinker): redirect to permission page if not employee in bladmin
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Aug 23, 2024
1 parent fc67ae8 commit 5c17655
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app/auth/permission/denied/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -32,6 +33,7 @@ export default function PermissionDeniedPage() {
<DynamicLink href={"/auth/login"}>
Tilbake til innloggingssiden
</DynamicLink>
<AuthAutoLogout />
</Box>
</Container>
</Card>
Expand Down
6 changes: 4 additions & 2 deletions src/components/AuthLinker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ?? ""}`;
}
Expand Down
11 changes: 11 additions & 0 deletions src/components/AuthLogoutComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client";
import { useEffect } from "react";

import { logout } from "@/api/auth";

export default function AuthLogoutComponent() {
useEffect(() => {
logout();
}, []);
return null;
}

0 comments on commit 5c17655

Please sign in to comment.