mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fix: Multi-tab logout OIDC redirect
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Redirect } from "react-router-dom";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
@@ -16,6 +16,7 @@ const Authenticated = ({ children }: Props) => {
|
||||
const { i18n } = useTranslation();
|
||||
const user = useCurrentUser({ rejectOnEmpty: false });
|
||||
const language = user?.language;
|
||||
const hasLoggedOut = useRef(false);
|
||||
|
||||
// Watching for language changes here as this is the earliest point we might have the user
|
||||
// available and means we can start loading translations faster
|
||||
@@ -23,23 +24,36 @@ const Authenticated = ({ children }: Props) => {
|
||||
void changeLanguage(language, i18n);
|
||||
}, [i18n, language]);
|
||||
|
||||
const shouldLogout = !auth.authenticated && !auth.isFetching;
|
||||
|
||||
// Passive logout when we land here without an authenticated session – note we
|
||||
// intentionally do not revoke the server-side token, as that would clobber
|
||||
// the session in any other tab that may have already re-authenticated.
|
||||
useEffect(() => {
|
||||
if (shouldLogout && !hasLoggedOut.current) {
|
||||
hasLoggedOut.current = true;
|
||||
void auth.logout({
|
||||
savePath: true,
|
||||
clearCache: false,
|
||||
revokeToken: false,
|
||||
});
|
||||
}
|
||||
}, [shouldLogout, auth]);
|
||||
|
||||
useEffect(() => {
|
||||
if (auth.logoutRedirectUri) {
|
||||
window.location.href = auth.logoutRedirectUri;
|
||||
}
|
||||
}, [auth.logoutRedirectUri]);
|
||||
|
||||
if (auth.authenticated) {
|
||||
return children;
|
||||
}
|
||||
|
||||
if (auth.isFetching) {
|
||||
if (auth.isFetching || auth.logoutRedirectUri) {
|
||||
return <LoadingIndicator />;
|
||||
}
|
||||
|
||||
void auth.logout({
|
||||
savePath: true,
|
||||
clearCache: false,
|
||||
});
|
||||
|
||||
if (auth.logoutRedirectUri) {
|
||||
window.location.href = auth.logoutRedirectUri;
|
||||
return null;
|
||||
}
|
||||
return <Redirect to="/" />;
|
||||
};
|
||||
|
||||
|
||||
@@ -118,7 +118,6 @@ export default class AuthStore extends Store<Team> {
|
||||
savePath: false,
|
||||
clearCache: false,
|
||||
revokeToken: false,
|
||||
userInitiated: true,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user