Skip to content

Commit

Permalink
Fix logout issue on pages without user context (#678)
Browse files Browse the repository at this point in the history
### Summary & Motivation

Fix an issue where logging out from a page without user context did not
immediately redirect the user. While the authentication cookies were
removed, the logout was only detected after an authenticated API request
failed with a `401 Unauthorized` response.

Now, the logout logic immediately redirects the browser to the
`loginPath`, ensuring an instant logout experience rather than waiting
for a failed request. This makes the logout process more seamless and
responsive.

### Checklist

- [x] I have added tests, or done manual regression tests
- [x] I have updated the documentation, if necessary
  • Loading branch information
tjementum authored Jan 25, 2025
2 parents 92889b8 + 65fe4f7 commit 21810c8
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useUserInfo } from "@repo/infrastructure/auth/hooks";
import { api } from "@/shared/lib/api/client";
import { t } from "@lingui/core/macro";
import { Trans } from "@lingui/react/macro";
import { createLoginUrlWithReturnPath } from "@repo/infrastructure/auth/util";
import { loginPath } from "@repo/infrastructure/auth/constants";

export default function AvatarButton() {
const [isProfileModalOpen, setIsProfileModalOpen] = useState(false);
Expand All @@ -27,7 +29,7 @@ export default function AvatarButton() {

async function logout() {
await api.post("/api/account-management/authentication/logout");
window.location.reload();
window.location.href = createLoginUrlWithReturnPath(loginPath);
}

return (
Expand Down

0 comments on commit 21810c8

Please sign in to comment.