Cross Events 3.0.0: sign-in through the church's Accounts
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>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { API_BASE } from "@/lib/api";
|
||||
import { saveToken } from "@/lib/auth";
|
||||
import { safePath, signInHref } from "@/lib/signIn";
|
||||
|
||||
/**
|
||||
* Back from the church's Accounts (3.0.0, docs/EVENTS-3.0-PLAN.md §3): the one-time code in the
|
||||
* address's fragment (never sent to a server or in a Referer) is swapped for Events' own token,
|
||||
* then on to the page the person started on.
|
||||
*/
|
||||
export default function SignInCompletePage() {
|
||||
const [failed, setFailed] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const code = window.location.hash.slice(1);
|
||||
// Out of the address bar and the history straight away.
|
||||
window.history.replaceState(null, "", "/auth/complete");
|
||||
if (!code) {
|
||||
setFailed("This sign-in link has already been used.");
|
||||
return;
|
||||
}
|
||||
fetch(`${API_BASE}/api/auth/handoff`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code }) })
|
||||
.then(async (r) => {
|
||||
const j = await r.json().catch(() => null);
|
||||
if (!r.ok || !j?.data?.token) throw new Error(j?.error?.message || "This sign-in has expired. Please sign in again.");
|
||||
saveToken(j.data.token);
|
||||
// A full page load, so the whole app starts signed in.
|
||||
window.location.replace(safePath(j.data.returnTo));
|
||||
})
|
||||
.catch((e: Error) => setFailed(e.message));
|
||||
}, []);
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-6">
|
||||
{failed ? (
|
||||
<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">We couldn't sign you in</h1>
|
||||
<p className="text-sm text-gray-600 mb-6">{failed}</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 again</a>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-sm text-gray-500" role="status">Signing you in…</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import React, { Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { Navbar } from "@/components/layout/Navbar";
|
||||
import { Footer } from "@/components/layout/Footer";
|
||||
import { safePath, signInHref } from "@/lib/signIn";
|
||||
|
||||
/** When signing in through the church's Accounts didn't work (3.0.0): what happened, and Try again. */
|
||||
const MESSAGES: Record<string, { title: string; text: string; retry?: boolean }> = {
|
||||
EXPIRED: { title: "That sign-in expired", text: "It took too long, or it was opened in another browser. Please try again.", retry: true },
|
||||
ACCOUNTS_UNAVAILABLE: { title: "Sign-in isn’t available right now", text: "We couldn’t reach the church’s sign-in. Please try again in a minute.", retry: true },
|
||||
START_FAILED: { title: "Sign-in isn’t available right now", text: "Please try again in a minute.", retry: true },
|
||||
FINISH_FAILED: { title: "We couldn’t finish signing you in", text: "Please try again.", retry: true },
|
||||
EVENTS_OFF: { title: "Your access to events is turned off", text: "Your church account is fine, but you can’t use this site at the moment. Please ask the church office." },
|
||||
MFA_REQUIRED: { title: "Two-step sign-in is needed", text: "Your role here needs a second step when you sign in. Please try again and set it up when asked.", retry: true },
|
||||
EMAIL_IN_USE: { title: "That email address belongs to someone else here", text: "Please ask the church office to sort it out." },
|
||||
EMAIL_NOT_VERIFIED: { title: "Please confirm your email address", text: "Confirm the email address on your church account, then sign in again.", retry: true },
|
||||
};
|
||||
|
||||
function Problem() {
|
||||
const search = useSearchParams();
|
||||
const m = MESSAGES[search.get("code") || ""] ?? { title: "Something went wrong signing in", text: "Please try again.", retry: true };
|
||||
return (
|
||||
<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">{m.title}</h1>
|
||||
<p className="text-sm text-gray-600 mb-6">{m.text}</p>
|
||||
{m.retry && <a href={signInHref(safePath(search.get("returnTo"), "/"))} className="inline-block w-full text-center px-4 py-2.5 rounded-lg bg-brand-600 text-white text-sm font-medium">Try again</a>}
|
||||
<a href="/" className="block mt-3 text-center text-sm text-gray-500 underline">Home page</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SignInProblemPage() {
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col">
|
||||
<Navbar />
|
||||
<main className="flex-1 flex items-center justify-center p-6">
|
||||
<Suspense fallback={<div />}><Problem /></Suspense>
|
||||
</main>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user