Spend login, invite, and email-change links only after a confirm POST so mail scanners cannot use them up.
GET still shows a one-button page, a used invitation can resend or reopen for the signed-in invitee, and an email-change GET no longer signs the account out.
This commit is contained in:
1 parent
600056499c
commit
a725cf1a32
33 files changed
+1002
-89
No files matched your search
@@ -0,0 +1,107 @@
|
||||
"use client";
|
||||
|
||||
import { useId } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Login from "../../components/modals/Login";
|
||||
import Button from "../../components/buttons/Button";
|
||||
import ContentLockup from "../../components/type/ContentLockup";
|
||||
|
||||
const confirmPageBgClass =
|
||||
"min-h-[100dvh] bg-[var(--color-surface-invert-brand-primary)]";
|
||||
|
||||
export type ConfirmLinkScreenProps = {
|
||||
title: string;
|
||||
description: string;
|
||||
buttonLabel: string;
|
||||
action: string;
|
||||
token: string;
|
||||
backHref: string;
|
||||
backLabel: string;
|
||||
missingTitle: string;
|
||||
missingDescription: string;
|
||||
missingHref: string;
|
||||
missingButtonLabel: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Figma: Overlay / Modal / Login (22078:587823)
|
||||
* One-button confirm so a mail scanner's GET cannot spend a one-time link.
|
||||
*/
|
||||
export function ConfirmLinkScreen({
|
||||
title,
|
||||
description,
|
||||
buttonLabel,
|
||||
action,
|
||||
token,
|
||||
backHref,
|
||||
backLabel,
|
||||
missingTitle,
|
||||
missingDescription,
|
||||
missingHref,
|
||||
missingButtonLabel,
|
||||
}: ConfirmLinkScreenProps) {
|
||||
const router = useRouter();
|
||||
const titleId = useId();
|
||||
const hasToken = token.length >= 10;
|
||||
const heading = hasToken
|
||||
? { title, description }
|
||||
: { title: missingTitle, description: missingDescription };
|
||||
|
||||
return (
|
||||
<div className={confirmPageBgClass}>
|
||||
<Login
|
||||
isOpen
|
||||
usePortal={false}
|
||||
backdropVariant="solid"
|
||||
onClose={() => {
|
||||
router.push(backHref);
|
||||
}}
|
||||
ariaLabelledBy={titleId}
|
||||
belowCard={
|
||||
<Link
|
||||
href={backHref}
|
||||
className="text-small-paragraph text-[var(--color-content-invert-tertiary,#2d2d2d)] text-center hover:opacity-90"
|
||||
>
|
||||
{backLabel}
|
||||
</Link>
|
||||
}
|
||||
>
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6 pt-2">
|
||||
<ContentLockup
|
||||
titleId={titleId}
|
||||
title={heading.title}
|
||||
description={heading.description}
|
||||
variant="login"
|
||||
alignment="left"
|
||||
/>
|
||||
{hasToken ? (
|
||||
<form method="POST" action={action} className="mt-auto flex flex-col gap-4">
|
||||
<input type="hidden" name="token" value={token} />
|
||||
<Button
|
||||
type="submit"
|
||||
size="large"
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
autoFocus
|
||||
className="w-full !justify-center text-center px-[var(--space-400)] py-[var(--space-300)]"
|
||||
>
|
||||
{buttonLabel}
|
||||
</Button>
|
||||
</form>
|
||||
) : (
|
||||
<Button
|
||||
href={missingHref}
|
||||
size="large"
|
||||
buttonType="filled"
|
||||
palette="default"
|
||||
className="mt-auto w-full !justify-center text-center px-[var(--space-400)] py-[var(--space-300)]"
|
||||
>
|
||||
{missingButtonLabel}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Login>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { Metadata } from "next";
|
||||
import type { ReactNode } from "react";
|
||||
import messages from "../../../../messages/en/index";
|
||||
import { NO_INDEX_ROBOTS, routeMetadata } from "../../../../lib/siteMetadata";
|
||||
|
||||
export const metadata: Metadata = routeMetadata("/email-change/confirm", {
|
||||
title: messages.metadata.emailChangeConfirm.title,
|
||||
description: messages.metadata.emailChangeConfirm.description,
|
||||
robots: NO_INDEX_ROBOTS,
|
||||
});
|
||||
|
||||
export default function EmailChangeConfirmLayout({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return children;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "../../../contexts/MessagesContext";
|
||||
import { emailChangeVerifyPath } from "../../../../lib/create/confirmLinkPaths";
|
||||
import { ConfirmLinkScreen } from "../../_components/ConfirmLinkScreen";
|
||||
|
||||
function EmailChangeConfirmFallback() {
|
||||
const t = useTranslation("pages.profile");
|
||||
return (
|
||||
<div className="flex min-h-[100dvh] items-center justify-center bg-[var(--color-surface-invert-brand-primary)]">
|
||||
<p className="text-[14px] text-[var(--color-content-default-primary)]">
|
||||
{t("loading")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function EmailChangeConfirmWithParams() {
|
||||
const t = useTranslation("pages.profile");
|
||||
const tLogin = useTranslation("pages.login");
|
||||
const searchParams = useSearchParams();
|
||||
const token = searchParams.get("token") ?? "";
|
||||
|
||||
return (
|
||||
<ConfirmLinkScreen
|
||||
title={t("emailChangeConfirmTitle")}
|
||||
description={t("emailChangeConfirmDescription")}
|
||||
buttonLabel={t("emailChangeConfirmButton")}
|
||||
action={emailChangeVerifyPath(token)}
|
||||
token={token}
|
||||
backHref="/"
|
||||
backLabel={tLogin("backToHome")}
|
||||
missingTitle={t("emailChangeConfirmMissingTitle")}
|
||||
missingDescription={t("emailChangeConfirmMissingDescription")}
|
||||
missingHref="/profile"
|
||||
missingButtonLabel={t("emailChangeConfirmMissingButton")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function EmailChangeConfirmPage() {
|
||||
return (
|
||||
<Suspense fallback={<EmailChangeConfirmFallback />}>
|
||||
<EmailChangeConfirmWithParams />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { Metadata } from "next";
|
||||
import type { ReactNode } from "react";
|
||||
import messages from "../../../../messages/en/index";
|
||||
import { NO_INDEX_ROBOTS, routeMetadata } from "../../../../lib/siteMetadata";
|
||||
|
||||
export const metadata: Metadata = routeMetadata("/invite/confirm", {
|
||||
title: messages.metadata.inviteConfirm.title,
|
||||
description: messages.metadata.inviteConfirm.description,
|
||||
robots: NO_INDEX_ROBOTS,
|
||||
});
|
||||
|
||||
export default function InviteConfirmLayout({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return children;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "../../../contexts/MessagesContext";
|
||||
import { inviteVerifyPath } from "../../../../lib/create/confirmLinkPaths";
|
||||
import {
|
||||
INVITE_COPY_QUERY,
|
||||
INVITE_COPY_VALUE,
|
||||
} from "../../../../lib/create/invitePaths";
|
||||
import { ConfirmLinkScreen } from "../../_components/ConfirmLinkScreen";
|
||||
|
||||
function InviteConfirmFallback() {
|
||||
const t = useTranslation("pages.invite");
|
||||
return (
|
||||
<div className="flex min-h-[100dvh] items-center justify-center bg-[var(--color-surface-invert-brand-primary)]">
|
||||
<p className="text-[14px] text-[var(--color-content-default-primary)]">
|
||||
{t("loadingFallback")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function InviteConfirmWithParams() {
|
||||
const t = useTranslation("pages.invite");
|
||||
const searchParams = useSearchParams();
|
||||
const token = searchParams.get("token") ?? "";
|
||||
const copy = searchParams.get(INVITE_COPY_QUERY) === INVITE_COPY_VALUE;
|
||||
|
||||
return (
|
||||
<ConfirmLinkScreen
|
||||
title={t("confirmTitle")}
|
||||
description={t("confirmDescription")}
|
||||
buttonLabel={t("confirmButton")}
|
||||
action={inviteVerifyPath(token, { copy })}
|
||||
token={token}
|
||||
backHref="/"
|
||||
backLabel={t("backToHome")}
|
||||
missingTitle={t("confirmMissingTitle")}
|
||||
missingDescription={t("confirmMissingDescription")}
|
||||
missingHref="/"
|
||||
missingButtonLabel={t("backToHome")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function InviteConfirmPage() {
|
||||
return (
|
||||
<Suspense fallback={<InviteConfirmFallback />}>
|
||||
<InviteConfirmWithParams />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Metadata } from "next";
|
||||
import messages from "../../../../messages/en/index";
|
||||
import { NO_INDEX_ROBOTS, routeMetadata } from "../../../../lib/siteMetadata";
|
||||
|
||||
export const metadata: Metadata = routeMetadata("/login/confirm", {
|
||||
title: messages.metadata.loginConfirm.title,
|
||||
description: messages.metadata.loginConfirm.description,
|
||||
robots: NO_INDEX_ROBOTS,
|
||||
});
|
||||
|
||||
export default function LoginConfirmLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return children;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useTranslation } from "../../../contexts/MessagesContext";
|
||||
import { magicLinkVerifyPath } from "../../../../lib/create/confirmLinkPaths";
|
||||
import { ConfirmLinkScreen } from "../../_components/ConfirmLinkScreen";
|
||||
|
||||
function LoginConfirmFallback() {
|
||||
const t = useTranslation("pages.login");
|
||||
return (
|
||||
<div className="flex min-h-[100dvh] items-center justify-center bg-[var(--color-surface-invert-brand-primary)]">
|
||||
<p className="text-[14px] text-[var(--color-content-default-primary)]">
|
||||
{t("loadingFallback")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LoginConfirmWithParams() {
|
||||
const t = useTranslation("pages.login");
|
||||
const searchParams = useSearchParams();
|
||||
const token = searchParams.get("token") ?? "";
|
||||
|
||||
return (
|
||||
<ConfirmLinkScreen
|
||||
title={t("confirmTitle")}
|
||||
description={t("confirmDescription")}
|
||||
buttonLabel={t("confirmButton")}
|
||||
action={magicLinkVerifyPath(token)}
|
||||
token={token}
|
||||
backHref="/"
|
||||
backLabel={t("backToHome")}
|
||||
missingTitle={t("confirmMissingTitle")}
|
||||
missingDescription={t("confirmMissingDescription")}
|
||||
missingHref="/login"
|
||||
missingButtonLabel={t("confirmMissingButton")}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function LoginConfirmPage() {
|
||||
return (
|
||||
<Suspense fallback={<LoginConfirmFallback />}>
|
||||
<LoginConfirmWithParams />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user