Settings -> Sign-in: check, move (everyone into Accounts with their password hashes and authenticator apps, count/hash check, then switch) and undo for 14 days. Sign-in through auth-client with a one-time handoff to Events' own token; staff roles stepped up to mfa; sign-out and back-channel logout; user.updated/export/deleted; admin 2FA reset, unlock and profile changes via Accounts; /login, /register, /forgot-password forward once moved; Events' own sign-in endpoints answer SIGN_IN_MOVED. User.accountId, AccountsSignIn. npm run test:accounts runs Events' code against the real Accounts app (11 tests); 5 new Jest tests. MIGRATING-TO-3.md, plan "Changes while building". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.3 KiB
TypeScript
55 lines
2.3 KiB
TypeScript
"use client";
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
import { fetchAuthMode, safePath, signInHref, type AuthMode } from "@/lib/signIn";
|
|
|
|
type Kind = "login" | "register" | "forgot" | "reset" | "activate";
|
|
|
|
/**
|
|
* Cross Events' own sign-in pages (3.0.0). With sign-in through Accounts, the sign-in, sign-up and
|
|
* forgot-password pages forward there (keeping where to come back to), and old reset and activation
|
|
* links say sign-in has moved. Otherwise (`local`, or `?local=1` from the backend) the page as before.
|
|
*/
|
|
export function AccountsGate({ kind, children }: { kind: Kind; children: React.ReactNode }) {
|
|
const [mode, setMode] = useState<AuthMode | null>(null);
|
|
useEffect(() => {
|
|
let alive = true;
|
|
const params = new URLSearchParams(window.location.search);
|
|
if (params.get("local") === "1") {
|
|
setMode("local");
|
|
return;
|
|
}
|
|
fetchAuthMode().then((m) => {
|
|
if (!alive) return;
|
|
if (m === "accounts" && (kind === "login" || kind === "register" || kind === "forgot")) {
|
|
window.location.replace(signInHref(safePath(params.get("redirect")), { signUp: kind === "register" }));
|
|
return;
|
|
}
|
|
setMode(m);
|
|
});
|
|
return () => { alive = false; };
|
|
}, [kind]);
|
|
|
|
if (mode === null) {
|
|
return <div className="min-h-[50vh] flex items-center justify-center text-sm text-gray-500" role="status">Loading…</div>;
|
|
}
|
|
if (mode === "accounts") return <SignInMoved kind={kind} />;
|
|
return <>{children}</>;
|
|
}
|
|
|
|
function SignInMoved({ kind }: { kind: Kind }) {
|
|
return (
|
|
<div className="min-h-[60vh] flex items-center justify-center p-6">
|
|
<div className="w-full max-w-md border rounded-2xl p-8 bg-white shadow-sm">
|
|
<h1 className="text-xl font-semibold text-gray-900 mb-2">Sign-in has moved</h1>
|
|
<p className="text-sm text-gray-600 mb-6">
|
|
{kind === "activate"
|
|
? "You now sign in with your church account. To get started, use “Forgot your password?” there with your email address to choose a password."
|
|
: "You now sign in with your church account, so this link no longer works. Use “Forgot your password?” there to choose a new one."}
|
|
</p>
|
|
<a href={signInHref("/dashboard")} className="inline-block w-full text-center px-4 py-2.5 rounded-lg bg-brand-600 text-white text-sm font-medium">Sign in</a>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|