Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useNavigate, type LoaderFunctionArgs } from "react-router";
|
||||
import { redirect, useNavigate, type LoaderFunctionArgs } from "react-router";
|
||||
import { useLoaderData } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherAlertTriangle, FeatherArrowLeft, FeatherWand2 } from "@subframe/core";
|
||||
@@ -8,12 +8,23 @@ import { createUserSession, getUserInfo, setLoggedUser } from "~/utils/session.s
|
||||
import { AuthStatus } from "~/components/auth/AuthShell";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { LinkButton } from "~/ui/components/LinkButton";
|
||||
import { beginAlternativeLoginMfa, LOGIN_MFA_CHALLENGE_PATH } from "~/services/auth/alternative-login-mfa.server";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import {
|
||||
AdminFallbackLoginRejected,
|
||||
assertAdminFallbackLoginAllowedForIdentity,
|
||||
isCompletedAdminFallbackLoginResponse,
|
||||
} from "~/services/auth/admin-fallback.server";
|
||||
import { writeAdminSsoAuditEvent } from "~/modules/admin-sso/audit.server";
|
||||
|
||||
type LoaderData = {
|
||||
status: "invalid" | "expired" | "replayed" | "not-found" | "purpose-mismatch";
|
||||
};
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs): Promise<Response | LoaderData> {
|
||||
if (!loadRequiredWebConfig().magicLink.enabled) {
|
||||
return { status: "invalid" };
|
||||
}
|
||||
const url = new URL(request.url);
|
||||
const token = url.searchParams.get("token");
|
||||
if (!token) {
|
||||
@@ -27,20 +38,48 @@ export async function loader({ request }: LoaderFunctionArgs): Promise<Response
|
||||
if (!user) {
|
||||
return { status: "not-found" };
|
||||
}
|
||||
try {
|
||||
assertAdminFallbackLoginAllowedForIdentity(user);
|
||||
} catch (error) {
|
||||
if (!(error instanceof AdminFallbackLoginRejected)) {
|
||||
throw error;
|
||||
}
|
||||
await writeAdminSsoAuditEvent({
|
||||
action: "admin.login.fallback.failure",
|
||||
actorAdminUserId: user.admin?.userId,
|
||||
request,
|
||||
meta: { reason: error.reason, email: user.email, method: "magic-link", stage: "consume" },
|
||||
});
|
||||
return { status: "invalid" };
|
||||
}
|
||||
const mfa = await beginAlternativeLoginMfa({ request, userId: user.id, redirectTo: "/", primaryMethod: "magic-link" });
|
||||
if (mfa.required) {
|
||||
return redirect(LOGIN_MFA_CHALLENGE_PATH, { headers: { "Set-Cookie": mfa.setCookie } });
|
||||
}
|
||||
const userInfo = await getUserInfo(request);
|
||||
const userSession = await setLoggedUser({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
defaultTenantId: user.defaultTenantId,
|
||||
});
|
||||
return createUserSession(
|
||||
const response = await createUserSession(
|
||||
{
|
||||
...userInfo,
|
||||
...userSession,
|
||||
lng: user.locale ?? userInfo.lng,
|
||||
},
|
||||
"/"
|
||||
"/",
|
||||
{ request, rotate: true },
|
||||
);
|
||||
if (user.admin && isCompletedAdminFallbackLoginResponse(response)) {
|
||||
await writeAdminSsoAuditEvent({
|
||||
action: "admin.login.fallback.success",
|
||||
actorAdminUserId: user.admin.userId,
|
||||
request,
|
||||
meta: { email: user.email, severity: "warn", method: "magic-link" },
|
||||
});
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
const REASON_MESSAGE_KEYS: Record<LoaderData["status"], { title: string; description: string }> = {
|
||||
|
||||
Reference in new issue
Block a user