21 lines
561 B
TypeScript
21 lines
561 B
TypeScript
import { navigateTo, useBrowserLocation } from "@metis/core/client";
|
|
import type { SessionResponseDTO } from "@metis/identity/common";
|
|
import { useEffect } from "react";
|
|
|
|
import { appRedirect } from "./app-redirect";
|
|
|
|
export function useAppNavigation(session: SessionResponseDTO | undefined) {
|
|
const location = useBrowserLocation();
|
|
|
|
useEffect(() => {
|
|
if (!session) {
|
|
return;
|
|
}
|
|
const destination = appRedirect(location, session);
|
|
|
|
if (destination) {
|
|
navigateTo(destination, { replace: true });
|
|
}
|
|
}, [location, session]);
|
|
}
|