You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/10/18 03:04:22 UTC
(airavata-custos) 03/12: end the identity provider session when switching users
This is an automated email from the ASF dual-hosted git repository.
yasithdev pushed a commit to branch stack-bugfixes
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit 84d0e182d4c51eade9b5ee3c4020c51dd3b8ae80
Author: Yasith Jayawardana <ya...@icloud.com>
AuthorDate: Sat Oct 17 22:52:29 2026 -0400
end the identity provider session when switching users
---
web/src/shared/auth/useAuthErrorHandler.ts | 7 +++++--
web/src/shared/layout/NoAccessNotice.tsx | 12 +++++++++---
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/web/src/shared/auth/useAuthErrorHandler.ts b/web/src/shared/auth/useAuthErrorHandler.ts
index 2404e2f91..4dca8fc3b 100644
--- a/web/src/shared/auth/useAuthErrorHandler.ts
+++ b/web/src/shared/auth/useAuthErrorHandler.ts
@@ -20,6 +20,7 @@
import { signOut } from "next-auth/react";
import { useCallback } from "react";
import { ApiError } from "@/shared/api/client";
+import { useSignOut } from "./useSignOut";
function readCode(body: unknown): string | null {
if (!body || typeof body !== "object" || !("code" in body)) return null;
@@ -27,6 +28,7 @@ function readCode(body: unknown): string | null {
}
export function useAuthErrorHandler() {
+ const { signOut: endSession } = useSignOut();
return useCallback(
(error: unknown) => {
if (!(error instanceof ApiError)) return;
@@ -38,13 +40,14 @@ export function useAuthErrorHandler() {
void signOut({ callbackUrl: "/sign-in?error=session_expired" });
return;
}
+ // Ends the IdP session too, or SSO would sign straight back into the same identity.
if (error.status === 401 && code === "identity_not_linked") {
- void signOut({ callbackUrl: "/sign-in?error=identity_not_linked" });
+ endSession({ callbackUrl: "/sign-in?error=identity_not_linked" });
return;
}
// 403 insufficient_privilege and other codes fall through to the
// query's local ErrorState — no global takeover.
},
- [],
+ [endSession],
);
}
diff --git a/web/src/shared/layout/NoAccessNotice.tsx b/web/src/shared/layout/NoAccessNotice.tsx
index a0f77f71f..3fc05a10d 100644
--- a/web/src/shared/layout/NoAccessNotice.tsx
+++ b/web/src/shared/layout/NoAccessNotice.tsx
@@ -17,9 +17,9 @@
"use client";
-import Link from "next/link";
import * as React from "react";
import { toast } from "sonner";
+import { useSignOut } from "@/shared/auth/useSignOut";
const HEADING = "No portal access";
const BODY = "No account was found for this sign-in. Ask an administrator for access.";
@@ -27,6 +27,7 @@ const BODY = "No account was found for this sign-in. Ask an administrator for ac
// Shown when the sign-in matches no Custos user. The message also stays on
// the page, since a toast alone disappears.
export function NoAccessNotice() {
+ const { signOut, isPending } = useSignOut();
React.useEffect(() => {
toast.error(HEADING, { description: BODY });
}, []);
@@ -34,9 +35,14 @@ export function NoAccessNotice() {
<div className="flex flex-col gap-2">
<h1 className="text-2xl font-bold tracking-tight">{HEADING}</h1>
<p className="text-sm text-muted-foreground">{BODY}</p>
- <Link href="/sign-in" className="mt-2 text-sm font-medium text-brand">
+ <button
+ type="button"
+ disabled={isPending}
+ onClick={() => signOut({ callbackUrl: "/sign-in" })}
+ className="mt-2 self-start text-sm font-medium text-brand"
+ >
Sign in as a different user
- </Link>
+ </button>
</div>
);
}