release gate / check (push) Failing after 6m56s
Transactional mail now goes out as the Superbrain HTML design
(internal/mailer/template.html, embedded verbatim) with a plain-text
alternative: multipart/alternative (plain first per RFC 2046), random
boundary, CRLF normalization and SMTP dot-stuffing. Render() fills the
{{placeholders}} with HTML-escaped values and removes optional sections
(CTA + fallback link, note block, footer links, address) when empty;
anchor drift fails the unit tests and degrades to plain text at send
time, never blocking delivery. Password reset gets the headline,
first-name greeting, "Choose a new password" button (Outlook VML
fallback) and expiry/single-use note; notification and agent emails
render title-as-headline with body paragraphs.
The template's footer links are now real pages:
- /help: public help center (10 topic sections + FAQ accordion), linked
from the login page.
- /unsubscribe?token=...: public confirmation page; the HMAC-signed user
id (notify.UnsubscribeToken, domain-separated, stable, no stored row)
IS the credential. POST /api/notifications/unsubscribe accepts the
RFC 8058 one-click shape (token in query, form body ignored) and the
browser JSON shape; it disables the user's enabled email channels and
pauses enabled agent email tasks addressed to their own email
(idempotent, re-enableable, per-client rate limited, audit logged).
- Email preferences deep-links to /settings?tab=notifications; Settings
now honors ?tab=<section> (unknown values fall back to profile).
notify.FooterLinks is the single eligibility point: preferences + help
whenever NEXTAUTH_URL is set; unsubscribe ONLY when the recipient is the
owner's own account email — third-party channel addresses and agent
recipients never receive a link that changes someone else's settings,
and transactional mail (password reset) never carries unsubscribe.
Owner-addressed mail also carries List-Unsubscribe +
List-Unsubscribe-Post headers.
Verified: Go build/vet/unit green; new TestUnsubscribeFlow integration
test pins footer + headers, blast radius (slack channel and third-party
task survive), one-click + JSON paths, idempotence, tampered tokens and
the third-party/transactional exclusions; notifications, phase-2,
password-reset and agent suites green; web lint/SSR-lint/build 0 errors;
full browser regressions pass; live smoke of /help, /unsubscribe states,
the settings deep-link auth gate and bad-token 400 through the proxy.
128 lines
5.1 KiB
TypeScript
128 lines
5.1 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { signIn } from 'next-auth/react'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Input } from '@/components/ui/input'
|
|
import { Link2, Shield, Mail, Lock } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { toast } from 'sonner'
|
|
import { useRouter } from 'next/navigation'
|
|
|
|
export function LoginClient({ oidcEnabled, passwordEnabled }: { oidcEnabled: boolean; passwordEnabled: boolean }) {
|
|
const [email, setEmail] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [loading, setLoading] = useState(false)
|
|
const router = useRouter()
|
|
|
|
const handleEmailLogin = async (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
setLoading(true)
|
|
try {
|
|
// signIn with redirect:false still rejects on network failures.
|
|
const result = await signIn('credentials', { email, password, redirect: false })
|
|
if (result?.ok) {
|
|
router.push('/pages')
|
|
} else if (result?.code === 'throttled') {
|
|
// Review M-8: Go's 429 is propagated as a CredentialsSignin code;
|
|
// do not present throttling as a wrong password.
|
|
toast.error('Too many attempts. Wait a few minutes and try again.')
|
|
} else {
|
|
toast.error('Invalid credentials')
|
|
}
|
|
} catch {
|
|
toast.error('Sign-in failed; check your connection')
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-background p-4">
|
|
<div className="w-full max-w-sm space-y-8">
|
|
<div className="text-center">
|
|
<div className="flex justify-center mb-4">
|
|
<div className="flex h-14 w-14 items-center justify-center rounded-2xl bg-primary text-primary-foreground">
|
|
<Link2 className="h-7 w-7" />
|
|
</div>
|
|
</div>
|
|
<h1 className="font-display text-3xl font-bold tracking-tight">Superbrain</h1>
|
|
<p className="text-sm text-muted-foreground mt-2">Your personal binder of life on the web</p>
|
|
</div>
|
|
|
|
<div className="space-y-4">
|
|
<Button
|
|
onClick={() => oidcEnabled && signIn('authelia', { redirectTo: '/pages' })}
|
|
className="w-full gap-2"
|
|
size="lg"
|
|
variant="default"
|
|
disabled={!oidcEnabled}
|
|
>
|
|
<Shield className="h-5 w-5" />
|
|
Sign in with Authelia
|
|
</Button>
|
|
{!oidcEnabled && passwordEnabled && (
|
|
<p className="text-center text-xs text-muted-foreground -mt-2">
|
|
Authelia single sign-on is not configured. Use email below.
|
|
</p>
|
|
)}
|
|
{!oidcEnabled && !passwordEnabled && (
|
|
<p className="text-center text-xs text-muted-foreground -mt-2">
|
|
This server is configured for Authelia single sign-on only, but
|
|
the OIDC variables are missing or placeholders. Ask the operator
|
|
to check AUTH_MODE / OIDC_* configuration.
|
|
</p>
|
|
)}
|
|
|
|
{passwordEnabled && (
|
|
<>
|
|
<div className="relative">
|
|
<div className="absolute inset-0 flex items-center"><div className="w-full border-t" /></div>
|
|
<div className="relative flex justify-center text-xs"><span className="bg-background px-2 text-muted-foreground">or continue with email</span></div>
|
|
</div>
|
|
|
|
<form onSubmit={handleEmailLogin} className="space-y-3">
|
|
<div className="relative">
|
|
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
<Input
|
|
type="email"
|
|
placeholder="Email"
|
|
value={email}
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)}
|
|
className="pl-10"
|
|
required
|
|
/>
|
|
</div>
|
|
<div className="relative">
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
<Input
|
|
type="password"
|
|
placeholder="Password"
|
|
value={password}
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setPassword(e.target.value)}
|
|
className="pl-10"
|
|
required
|
|
/>
|
|
</div>
|
|
<div className="text-right">
|
|
<Link href="/forgot-password" className="text-xs text-muted-foreground hover:text-primary hover:underline">Forgot password?</Link>
|
|
</div>
|
|
<Button type="submit" variant="outline" className="w-full" loading={loading}>
|
|
Sign in with Email
|
|
</Button>
|
|
</form>
|
|
|
|
<p className="text-center text-xs text-muted-foreground">
|
|
Don't have an account? <Link href="/signup" className="text-primary hover:underline">Sign up</Link>
|
|
</p>
|
|
</>
|
|
)}
|
|
<p className="text-center text-xs text-muted-foreground">
|
|
<Link href="/help" className="hover:text-primary hover:underline">Help center</Link>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|