Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logout from both idp and app #60

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ export default function Header({
}) {
const { logout, session } = useContext(SessionContext);

const isUrl = (candidateUrl: string | URL) => {
try {
// If url is not URL-shaped, this will throw.
// eslint-disable-next-line no-new
new URL(candidateUrl);
return true;
} catch (_e) {
return false;
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try removing this, and using a call to URL.canParse instead? It's a fairly recent addition to browsers, but I think because we are transpiling the code targeting an older EcmaScript version we should be good there and not become unaccessible for older browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not having any problems locally either when running the tests nor the app itself, but URL.canParse is causing some failures on the Vercel deployment as well as in the e2e execution. Do you have any ideas on how to fix that?


const handleLogout = async () => {
if (
garciafdezpatricia marked this conversation as resolved.
Show resolved Hide resolved
session.info.clientAppId !== undefined &&
isUrl(session.info.clientAppId)
) {
await logout({
logoutType: "idp",
postLogoutUrl: new URL("/", window.location.href).toString(),
garciafdezpatricia marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
await logout({ logoutType: "app" });
}
};

return (
<header className={styles.header}>
<div className={styles["header-top"]}>
Expand All @@ -44,12 +69,7 @@ export default function Header({
<Button
variant="text"
data-testid="logout-button"
onClick={() =>
logout({
logoutType: "idp",
postLogoutUrl: new URL("/", window.location.href).toString(),
})
}
onClick={() => handleLogout()}
garciafdezpatricia marked this conversation as resolved.
Show resolved Hide resolved
className={styles["logout-button"]}
>
Logout
Expand Down
Loading