feat: add password reset email

This commit is contained in:
gosangam
2026-06-02 18:37:38 +05:30
parent dc01d09f09
commit cb70a84dd5
12 changed files with 662 additions and 88 deletions
+34
View File
@@ -1,13 +1,47 @@
"use client";
/**
* Shared layout for the auth pages (login, signup, forgot-password,
* reset-password). Provides the centered card frame so each page only
* has to render its own form.
*
* Also gates the routes: a signed-in user landing on any /login, /signup,
* etc. URL is bounced to /u/me (or the `next` query param if present).
* The check happens client-side because auth state lives in
* AuthProvider — there's no server-side cookie inspection here yet, and
* the redirect is purely cosmetic (logged-in users don't gain anything
* from re-seeing these forms, and signing in over an existing session
* would just no-op).
*/
import { useEffect } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { useAuth } from "@/components/auth/auth-provider";
export default function AuthLayout({
children,
}: {
children: React.ReactNode;
}) {
const { user, loading } = useAuth();
const router = useRouter();
const params = useSearchParams();
useEffect(() => {
if (loading || !user) return;
const next = params.get("next");
router.replace(next && next.startsWith("/") ? next : "/u/me");
}, [loading, user, router, params]);
// Don't flash the form for an instant before the redirect fires.
if (!loading && user) {
return (
<main className="flex items-center justify-center px-4 py-12 min-h-[90vh]">
<p className="text-sm text-muted-foreground">Redirecting…</p>
</main>
);
}
return (
<main className="flex items-center justify-center px-4 py-12 min-h-[90vh]">
<div className="w-full max-w-md">{children}</div>
-2
View File
@@ -37,8 +37,6 @@ function LoginContent() {
function oauthErrorMessage(code: string): string {
switch (code) {
case "email_required":
return "We couldn't sign you in because the provider didn't share an email. Please use the email/password form below.";
case "invalid_state":
case "missing_state":
return "Your sign-in link expired. Please try again.";
+218
View File
@@ -0,0 +1,218 @@
"use client";
/**
* /settings — the top-level user-settings screen.
*
* Lives outside the /u/me profile layout so it doesn't carry the
* ProfileHeader + tabs that frame the profile views. It sits directly
* under (app)/, which gives it the default site chrome (sidebar, header,
* etc.) without the profile-specific frame on top.
*
* Sections are stacked plain — no per-section card chrome — so the page
* reads as a single ordered list of preferences rather than a dashboard
* of widgets. To add a new section, drop another <Section> in the
* `<main>` below.
*/
import { useState } from "react";
import Link from "next/link";
import { ChevronLeft, ChevronRight } from "lucide-react";
import { ChangePasswordModal } from "@/components/auth/change-password-modal";
import { ReadingSettings } from "@/components/reading-settings";
const BFF_BASE =
process.env.NEXT_PUBLIC_BFF_URL || "http://localhost:8080";
export default function SettingsPage() {
return (
<main className="flex-1 max-w-3xl w-full mx-auto px-4 sm:px-6 py-6 space-y-10">
<header className="space-y-1">
<Link
href="/u/me"
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
>
<ChevronLeft className="size-4" />
Back to profile
</Link>
<h1 className="font-[family-name:var(--font-title)] text-3xl font-semibold text-foreground pt-2">
Settings
</h1>
</header>
<Section
title="Reading preferences"
description="Theme, palette, font, and size — synced across your devices."
>
<ReadingSettings variant="bare" />
</Section>
<Section title="Authentication">
<AuthenticationSection />
</Section>
<Section title="Legal">
<LegalSection />
</Section>
</main>
);
}
function Section({
title,
description,
children,
}: {
title: string;
description?: string;
children: React.ReactNode;
}) {
return (
<section className="space-y-4">
<div className="border-b border-border pb-3">
<h2 className="font-[family-name:var(--font-title)] text-xl font-semibold text-foreground">
{title}
</h2>
{description ? (
<p className="text-sm text-muted-foreground mt-1">{description}</p>
) : null}
</div>
<div>{children}</div>
</section>
);
}
// ─── Authentication ────────────────────────────────────────────────────
function AuthenticationSection() {
const [pwModalOpen, setPwModalOpen] = useState(false);
const next = "/settings";
function startOAuth(provider: "facebook" | "google") {
const u = new URL(`${BFF_BASE}/api/v1/auth/oauth/${provider}/start`);
u.searchParams.set("next", next);
return u.toString();
}
return (
<>
<ul className="divide-y divide-border">
{/* Google sign-in — uncomment once the Google OAuth app clears review.
<Row
label="Connect your Google account"
action={
<a
href={startOAuth("google")}
className="text-sm font-medium text-primary hover:underline"
>
Connect
</a>
}
/>
*/}
<Row
icon={<FacebookGlyph />}
label="Connect your Facebook account"
action={
<a
href={startOAuth("facebook")}
className="text-sm font-medium text-primary hover:underline"
>
Connect
</a>
}
/>
<Row
label="Change your password"
description="Update the password you use to sign in."
action={
<button
type="button"
onClick={() => setPwModalOpen(true)}
className="text-sm font-medium text-primary hover:underline"
>
Change
</button>
}
/>
</ul>
<ChangePasswordModal
open={pwModalOpen}
onClose={() => setPwModalOpen(false)}
/>
</>
);
}
// ─── Legal ─────────────────────────────────────────────────────────────
function LegalSection() {
return (
<ul className="divide-y divide-border">
<LegalLink href="/terms" label="Terms of Service" />
<LegalLink href="/privacy" label="Privacy Policy" />
<LegalLink href="/data-deletion" label="Steps for data deletion" />
</ul>
);
}
function LegalLink({ href, label }: { href: string; label: string }) {
return (
<li>
<Link
href={href}
className="flex items-center justify-between py-3 group"
>
<span className="text-sm text-foreground group-hover:text-primary transition-colors">
{label}
</span>
<ChevronRight className="size-4 text-muted-foreground group-hover:text-foreground transition-colors" />
</Link>
</li>
);
}
// ─── Row helper ────────────────────────────────────────────────────────
function FacebookGlyph() {
return (
<svg
className="size-4"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
aria-hidden
>
<path
fill="#1877F2"
d="M24 12a12 12 0 1 0-13.88 11.85V15.47H7.08V12h3.04V9.36c0-3 1.79-4.67 4.53-4.67 1.31 0 2.69.24 2.69.24v2.96H15.83c-1.49 0-1.95.92-1.95 1.87V12h3.32l-.53 3.47h-2.79v8.38A12 12 0 0 0 24 12Z"
/>
</svg>
);
}
function Row({
icon,
label,
description,
action,
}: {
icon?: React.ReactNode;
label: string;
description?: string;
action: React.ReactNode;
}) {
return (
<li className="flex items-center justify-between gap-4 py-3">
<div className="min-w-0">
<div className="flex items-center gap-2">
{icon ? <span className="shrink-0">{icon}</span> : null}
<span className="text-sm text-foreground truncate">{label}</span>
</div>
{description ? (
<p className="text-xs text-muted-foreground mt-0.5">{description}</p>
) : null}
</div>
<div className="shrink-0">{action}</div>
</li>
);
}
+4 -9
View File
@@ -14,7 +14,7 @@
*/
import { Suspense, useEffect } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useRouter, useSearchParams } from "next/navigation";
import {
AtSign,
Bookmark,
@@ -102,13 +102,8 @@ export default function MeLayout({ children }: { children: React.ReactNode }) {
function ConditionalTabs({ tabs }: { tabs: ProfileTab[] }) {
const searchParams = useSearchParams();
const pathname = usePathname();
// Hide tabs when the user is in a focused subview:
// • /u/me?edit=1 — the inline profile-edit form
// • /u/me/settings — the reading-prefs page
// In either case the strip is visual noise that distracts from the
// task they navigated in to do.
// Hide tabs when the user is editing their profile inline — the strip
// is visual noise that distracts from the task they navigated in to do.
const editMode = searchParams.get("edit") === "1";
const settingsMode = pathname.startsWith("/u/me/settings");
return editMode || settingsMode ? null : <ProfileTabs tabs={tabs} />;
return editMode ? null : <ProfileTabs tabs={tabs} />;
}
-43
View File
@@ -1,43 +0,0 @@
"use client";
/**
* /u/me/settings — dedicated reading-preferences screen for auth users.
*
* Mirrors the Edit Profile pattern: a focused subview of /u/me that
* trades the tab strip for a back link + the settings form. We send
* users here instead of opening the popover because the popover, when
* triggered from ProfileHeader's centred action row, can spill off the
* left edge of narrow viewports. Anonymous users still get the popover
* in SiteHeader — that trigger sits at right-2 so it doesn't overflow.
*
* The /u/me layout's ConditionalTabs detects this path and hides the
* Posts/Collections/Bookmarks/Mentions strip while the user is editing
* settings.
*/
import Link from "next/link";
import { ChevronLeft } from "lucide-react";
import { ReadingSettings } from "@/components/reading-settings";
export default function ReadingSettingsPage() {
return (
<div className="space-y-6">
<Link
href="/u/me"
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
>
<ChevronLeft className="size-4" />
Back to profile
</Link>
<div>
<h1 className="font-[family-name:var(--font-title)] text-2xl font-semibold text-foreground">
Reading settings
</h1>
<p className="text-sm text-muted-foreground mt-1">
Theme, palette, font, and size — synced across your devices.
</p>
</div>
<ReadingSettings variant="inline" />
</div>
);
}