forked from baron/baron-sso
Show orgfront login page for regular entries
This commit is contained in:
@@ -36,6 +36,7 @@ function renderGuard(initialEntry: string) {
|
||||
<MemoryRouter initialEntries={[initialEntry]}>
|
||||
<Routes>
|
||||
<Route element={<AuthGuard />}>
|
||||
<Route path="/chart" element={<div>chart</div>} />
|
||||
<Route path="/embed/picker" element={<div>picker</div>} />
|
||||
</Route>
|
||||
<Route path="/login" element={<LocationProbe />} />
|
||||
@@ -74,4 +75,11 @@ describe("OrgFront AuthGuard auto login redirects", () => {
|
||||
);
|
||||
cleanupRendered(rendered.container, rendered.root);
|
||||
});
|
||||
|
||||
it("redirects regular app entry to the visible login page", () => {
|
||||
const rendered = renderGuard("/chart");
|
||||
|
||||
expect(rendered.container.textContent).toBe("/login?returnTo=%2Fchart");
|
||||
cleanupRendered(rendered.container, rendered.root);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,9 +29,12 @@ export default function AuthGuard() {
|
||||
|
||||
if (!auth.isAuthenticated) {
|
||||
const returnTo = `${location.pathname}${location.search}`;
|
||||
const autoLoginParam = location.pathname.startsWith("/embed/")
|
||||
? "auto=1&"
|
||||
: "";
|
||||
return (
|
||||
<Navigate
|
||||
to={`/login?auto=1&returnTo=${encodeURIComponent(returnTo)}`}
|
||||
to={`/login?${autoLoginParam}returnTo=${encodeURIComponent(returnTo)}`}
|
||||
replace
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user