Profile accounts: invites, any-Google sign-in, claiming People, visibility, Discord
Migration 076 adds a member role below viewer (the site and its own profile, never the admin: /api/admin now needs viewer), invites, person claims, a Discord link on accounts and people.hide_* switches. Public reads of people go through v_people_public, which nulls hidden fields, and the views that read people are rebuilt over it. Admins invite an email from Data -> Profile accounts (link shown once, emailed on request). The invitee sets a password or signs in with any Google account under that email, asks to claim their People record, and once approved edits it and chooses what shows at /account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0cc2a3f721
commit
e4c7e165d1
34 changed files with 2483 additions and 74 deletions
142
src/pages/AccountWelcome.tsx
Normal file
142
src/pages/AccountWelcome.tsx
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
WELCOME: /account/welcome?token=…, an invite's link (076)
|
||||
|
||||
Who the invite is for, then a password to set, or Google under the
|
||||
invited email. Either takes up the invite: the link stops working
|
||||
and the account is signed in (routes/account.js, routes/auth.js).
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Link, useNavigate, useSearchParams } from 'react-router-dom'
|
||||
|
||||
import PageShell from '../components/PageShell.tsx'
|
||||
import { useAuth } from '../lib/auth.tsx'
|
||||
import { ApiError, get, post } from '../lib/api.ts'
|
||||
import { BRAND } from '../lib/color.ts'
|
||||
import { GoogleButton, fieldClass, primaryButton } from './SignIn.tsx'
|
||||
|
||||
const MIN_PASSWORD = 12
|
||||
|
||||
type Invite = { email: string; name: string | null; google: boolean }
|
||||
|
||||
export default function AccountWelcome() {
|
||||
const [searchParams] = useSearchParams()
|
||||
const token = searchParams.get('token') ?? ''
|
||||
const navigate = useNavigate()
|
||||
const { signedIn } = useAuth()
|
||||
|
||||
const [invite, setInvite] = useState<Invite | null>(null)
|
||||
const [problem, setProblem] = useState<string | null>(null)
|
||||
const [password, setPassword] = useState('')
|
||||
const [again, setAgain] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
setProblem('This page needs the link from your invite email.')
|
||||
return
|
||||
}
|
||||
get(`/account/invite?token=${encodeURIComponent(token)}`, { ttl: 0 })
|
||||
.then((data) => setInvite(data.invite))
|
||||
.catch((err) => setProblem(err instanceof ApiError ? err.message : "Couldn't reach the server. Try again in a moment."))
|
||||
}, [token])
|
||||
|
||||
async function submit(event: React.FormEvent) {
|
||||
event.preventDefault()
|
||||
if (busy) return
|
||||
if (password.length < MIN_PASSWORD) return setError(`Use at least ${MIN_PASSWORD} characters.`)
|
||||
if (password !== again) return setError("The two passwords don't match.")
|
||||
setBusy(true)
|
||||
setError(null)
|
||||
try {
|
||||
const data = await post('/account/accept', { token, password })
|
||||
signedIn(data.user)
|
||||
navigate('/account', { replace: true })
|
||||
} catch (err) {
|
||||
setError(err instanceof ApiError ? err.message : "Couldn't reach the server. Try again in a moment.")
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<PageShell
|
||||
title="Welcome"
|
||||
intro="You've been invited to make a profile account."
|
||||
sections={[
|
||||
{
|
||||
id: 'welcome',
|
||||
title: invite?.name ? `Hi, ${invite.name}` : 'Your account',
|
||||
accent: BRAND,
|
||||
content: (
|
||||
<div className="mx-auto max-w-md px-6">
|
||||
{problem ? (
|
||||
<div className="notice p-5">
|
||||
<p className="text-body">{problem}</p>
|
||||
<p className="mt-2 text-sm text-muted">
|
||||
Already set up? <Link to="/sign-in" className="text-link underline">Sign in</Link>. Otherwise ask whoever invited you for a new link.
|
||||
</p>
|
||||
</div>
|
||||
) : !invite ? (
|
||||
<div className="skeleton !min-h-40" aria-label="Checking your invite" />
|
||||
) : (
|
||||
<form onSubmit={submit} noValidate className="bg-raised p-6 shadow-md sm:p-8">
|
||||
<p className="text-sm text-muted">
|
||||
Your account is <strong className="text-body">{invite.email}</strong>.
|
||||
</p>
|
||||
{invite.google && (
|
||||
<>
|
||||
<div className="mt-5">
|
||||
<GoogleButton label="Continue with Google" />
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-muted">Sign in to Google as {invite.email}.</p>
|
||||
<div className="my-6 flex items-center gap-3 text-xs text-muted">
|
||||
<span className="h-px flex-1 bg-muted/20" />
|
||||
or set a password
|
||||
<span className="h-px flex-1 bg-muted/20" />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<label htmlFor="welcome-password" className={`${invite.google ? '' : 'mt-5 '}block text-sm font-medium text-body`}>
|
||||
Password
|
||||
</label>
|
||||
<input
|
||||
id="welcome-password"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
aria-describedby="welcome-password-help"
|
||||
className={`mt-2 ${fieldClass}`}
|
||||
/>
|
||||
<p id="welcome-password-help" className="mt-1 text-xs text-muted">
|
||||
At least {MIN_PASSWORD} characters.
|
||||
</p>
|
||||
<label htmlFor="welcome-again" className="mt-5 block text-sm font-medium text-body">
|
||||
Password again
|
||||
</label>
|
||||
<input
|
||||
id="welcome-again"
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={again}
|
||||
onChange={(e) => setAgain(e.target.value)}
|
||||
className={`mt-2 ${fieldClass}`}
|
||||
/>
|
||||
{error && (
|
||||
<p role="alert" className="mt-5 border border-danger/30 bg-danger-tint px-4 py-3 text-sm text-danger">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button type="submit" disabled={busy || !password || !again} className={`mt-6 w-full ${primaryButton}`}>
|
||||
{busy ? 'Setting up…' : 'Set password and sign in'}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue