33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { redirect, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
|
|
|
import { safeRedirectPath } from "~/utils/app/RedirectSafety";
|
|
|
|
const DEFAULT_ADMIN_PATH = "/dashboard";
|
|
|
|
function authentikLoginPath(redirectTo: FormDataEntryValue | string | null | undefined): string {
|
|
const returnTo = safeRedirectPath(typeof redirectTo === "string" ? redirectTo : null, {
|
|
fallbackPath: DEFAULT_ADMIN_PATH,
|
|
});
|
|
return `/auth/admin/login?${new URLSearchParams({ returnTo }).toString()}`;
|
|
}
|
|
|
|
/**
|
|
* Legacy route retained as a compatibility redirect only.
|
|
*
|
|
* Productive admin MFA assurance belongs exclusively to Authentik. HiveGrid
|
|
* therefore never renders or verifies its former User/TOTP challenge here.
|
|
*/
|
|
export async function loader({ request }: LoaderFunctionArgs): Promise<Response> {
|
|
const url = new URL(request.url);
|
|
throw redirect(authentikLoginPath(url.searchParams.get("redirectTo")));
|
|
}
|
|
|
|
export async function action({ request }: ActionFunctionArgs): Promise<Response> {
|
|
const form = await request.formData();
|
|
throw redirect(authentikLoginPath(form.get("redirectTo") ?? new URL(request.url).searchParams.get("redirectTo")));
|
|
}
|
|
|
|
export default function AuthentikMfaCompatibilityRedirect() {
|
|
return null;
|
|
}
|