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]}>
|
<MemoryRouter initialEntries={[initialEntry]}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route element={<AuthGuard />}>
|
<Route element={<AuthGuard />}>
|
||||||
|
<Route path="/chart" element={<div>chart</div>} />
|
||||||
<Route path="/embed/picker" element={<div>picker</div>} />
|
<Route path="/embed/picker" element={<div>picker</div>} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/login" element={<LocationProbe />} />
|
<Route path="/login" element={<LocationProbe />} />
|
||||||
@@ -74,4 +75,11 @@ describe("OrgFront AuthGuard auto login redirects", () => {
|
|||||||
);
|
);
|
||||||
cleanupRendered(rendered.container, rendered.root);
|
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) {
|
if (!auth.isAuthenticated) {
|
||||||
const returnTo = `${location.pathname}${location.search}`;
|
const returnTo = `${location.pathname}${location.search}`;
|
||||||
|
const autoLoginParam = location.pathname.startsWith("/embed/")
|
||||||
|
? "auto=1&"
|
||||||
|
: "";
|
||||||
return (
|
return (
|
||||||
<Navigate
|
<Navigate
|
||||||
to={`/login?auto=1&returnTo=${encodeURIComponent(returnTo)}`}
|
to={`/login?${autoLoginParam}returnTo=${encodeURIComponent(returnTo)}`}
|
||||||
replace
|
replace
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user