Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Markusplay committed Jan 31, 2025
1 parent 918de85 commit 6045ae5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/[locale]/(private)/accept-honor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function CodeOfHonorAlert() {
return;
}
setUser(res);
router.refresh();
router.push('/');
};

return (
Expand Down
21 changes: 12 additions & 9 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,21 @@ const authMiddleware = (request: NextRequest) => {
};

const CoHMiddleware = async (request: NextRequest) => {
const user = await getUserDetails();
const hasAcceptedCoH = Boolean(user?.codeOfHonorSignDate && user?.studentProfile);
try {
const user = await getUserDetails();
const hasAcceptedCoH = !!user?.codeOfHonorSignDate;

if (!hasAcceptedCoH && !isAcceptHonorPath(request)) {
return redirectWithIntl(request, '/accept-honor');
}
if (!hasAcceptedCoH && !isAcceptHonorPath(request)) {
return redirectWithIntl(request, '/accept-honor');
}

if (hasAcceptedCoH && isAcceptHonorPath(request)) {
return redirectWithIntl(request, '/');
if ((!user?.studentProfile || hasAcceptedCoH) && isAcceptHonorPath(request)) {
return redirectWithIntl(request, '/');
}
} catch (error) {
return null;
}

return null;
return intlMiddleware(request);
};

export async function middleware(request: NextRequest) {
Expand Down

0 comments on commit 6045ae5

Please sign in to comment.