create-ailk 0.35.1 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/component-catalog.json +12 -1
- package/component-catalog.md +6 -5
- package/dist/lib/env-catalog.js +8 -0
- package/dist/surfaces.js +6 -3
- package/dist/topology.d.ts +4 -4
- package/dist/topology.js +104 -60
- package/package.json +3 -3
- package/templates/.env.example +21 -0
- package/templates/apps/api/.env.example +7 -0
- package/templates/apps/api/CLAUDE.md +9 -4
- package/templates/apps/mcp/CLAUDE.md +4 -2
- package/templates/apps/web/.env.example +16 -0
- package/templates/apps/web/CLAUDE.md +46 -5
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
- package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
- package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
- package/templates/apps/web/app/[locale]/layout.tsx +24 -75
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
- package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
- package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
- package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
- package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
- package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
- package/templates/apps/web/auth.ts +133 -6
- package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
- package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
- package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
- package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
- package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
- package/templates/apps/web/lib/auth-email.ts +62 -6
- package/templates/apps/web/lib/auth-env.ts +13 -0
- package/templates/apps/web/lib/auth-sms.ts +180 -0
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
- package/templates/apps/web/lib/hub-session/config.ts +7 -1
- package/templates/apps/web/lib/hub-session/entry.ts +238 -0
- package/templates/apps/web/lib/hub-session/index.ts +1 -4
- package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
- package/templates/apps/web/lib/hub-session/session.ts +120 -2
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
- package/templates/apps/web/lib/site-header.ts +14 -1
- package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
- package/templates/apps/web/lib/topology.generated.ts +39 -0
- package/templates/apps/web/messages/en.json +112 -20
- package/templates/apps/web/middleware.ts +34 -2
- package/templates/apps/web/security-headers.config.ts +21 -0
- package/versions.json +47 -47
- package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
- package/templates/apps/web/components/signed-in-nav.tsx +0 -79
- package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
- package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* account/invitations/[invitationId]/actions.ts — the invitee's two calls
|
|
5
|
+
* (#11106, spec docs/specs/11106-the-workforce-foundation-roles-by-spec.md
|
|
6
|
+
* D5): read the invitation, and accept it.
|
|
7
|
+
*
|
|
8
|
+
* GET /v1/invitations/:invitationId → `readInvitation`
|
|
9
|
+
* POST /v1/invitations/:invitationId/accept → `acceptInvitation`
|
|
10
|
+
*
|
|
11
|
+
* Both are server-side fetches carrying the person's own session
|
|
12
|
+
* (`forwardedCookieInit()`: the cookie and, on the POST, the request's
|
|
13
|
+
* `Origin` the API's CSRF check needs). The API answers only the invited,
|
|
14
|
+
* verified address — the invitation id is the only input, never an email.
|
|
15
|
+
* `@working-theory/api-client` carries no invitation namespace, so the call is
|
|
16
|
+
* a bare `fetch` to its `getApiBase()` (the `app/openapi.json/route.ts`
|
|
17
|
+
* precedent).
|
|
18
|
+
*
|
|
19
|
+
* Accepting is a form POST to `acceptInvitation`, bound to the id and locale
|
|
20
|
+
* by the page; it redirects back to the page with `?joined=1` or `?error=<code>`
|
|
21
|
+
* — a GET of the page never writes. Logs carry a status or a code only.
|
|
22
|
+
*
|
|
23
|
+
* Not a `*.actions.ts` file and no `*Action`-suffixed export: accepting is a
|
|
24
|
+
* person's own act with no MCP twin (apps/mcp's parity test reads that
|
|
25
|
+
* suffix).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { getApiBase } from "@working-theory/api-client";
|
|
29
|
+
import { localeHref } from "@working-theory/ui";
|
|
30
|
+
import { invitationDetailSchema, type InvitationDetail } from "@working-theory/validation";
|
|
31
|
+
import { redirect } from "next/navigation";
|
|
32
|
+
|
|
33
|
+
import { forwardedCookieInit } from "../../../../../../lib/server-api";
|
|
34
|
+
|
|
35
|
+
import { isInvitationId } from "./invitation-id";
|
|
36
|
+
|
|
37
|
+
/** Bounds the call so a hung apps/api cannot pin a render. */
|
|
38
|
+
const CALL_TIMEOUT_MS = 10_000;
|
|
39
|
+
|
|
40
|
+
export type InvitationRead =
|
|
41
|
+
| { kind: "ok"; invitation: InvitationDetail }
|
|
42
|
+
| { kind: "not_found" }
|
|
43
|
+
| { kind: "other_address" }
|
|
44
|
+
| { kind: "failed" };
|
|
45
|
+
|
|
46
|
+
function errorCode(body: unknown): string | null {
|
|
47
|
+
const code = (body as { error?: { code?: unknown } } | null)?.error?.code;
|
|
48
|
+
return typeof code === "string" ? code : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function call(
|
|
52
|
+
method: "GET" | "POST",
|
|
53
|
+
path: string,
|
|
54
|
+
): Promise<{ status: number; body: unknown }> {
|
|
55
|
+
const { headers } = await forwardedCookieInit();
|
|
56
|
+
const res = await fetch(`${getApiBase()}${path}`, {
|
|
57
|
+
method,
|
|
58
|
+
headers: { ...headers, ...(method === "POST" ? { "content-type": "application/json" } : {}) },
|
|
59
|
+
...(method === "POST" ? { body: "{}" } : {}),
|
|
60
|
+
cache: "no-store",
|
|
61
|
+
signal: AbortSignal.timeout(CALL_TIMEOUT_MS),
|
|
62
|
+
});
|
|
63
|
+
const body: unknown = await res.json().catch(() => null);
|
|
64
|
+
return { status: res.status, body };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The invitation, for the signed-in person the API matches to it. */
|
|
68
|
+
export async function readInvitation(invitationId: string): Promise<InvitationRead> {
|
|
69
|
+
if (!isInvitationId(invitationId)) return { kind: "not_found" };
|
|
70
|
+
try {
|
|
71
|
+
const { status, body } = await call("GET", `/v1/invitations/${invitationId}`);
|
|
72
|
+
if (status === 404) return { kind: "not_found" };
|
|
73
|
+
if (status === 403 && errorCode(body) === "invitation_for_another_address") {
|
|
74
|
+
return { kind: "other_address" };
|
|
75
|
+
}
|
|
76
|
+
const data = (body as { ok?: unknown; data?: unknown } | null)?.data;
|
|
77
|
+
const parsed = invitationDetailSchema.safeParse(data);
|
|
78
|
+
if (status === 200 && parsed.success) return { kind: "ok", invitation: parsed.data };
|
|
79
|
+
console.error(`[account-invitation] read status=${status}`);
|
|
80
|
+
return { kind: "failed" };
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(
|
|
83
|
+
`[account-invitation] read errName=${err instanceof Error ? err.name : "unknown"}`,
|
|
84
|
+
);
|
|
85
|
+
return { kind: "failed" };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The refusal codes the page has a line for; anything else is `failed`. */
|
|
90
|
+
const KNOWN_REFUSALS = new Set([
|
|
91
|
+
"invitation_for_another_address",
|
|
92
|
+
"invitation_not_pending",
|
|
93
|
+
"invitation_expired",
|
|
94
|
+
"invitation_void",
|
|
95
|
+
"already_member",
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
/** Accept — a form POST, bound to the invitation id and locale by the page. */
|
|
99
|
+
export async function acceptInvitation(invitationId: string, locale: string): Promise<void> {
|
|
100
|
+
const page = localeHref(locale, `/account/invitations/${invitationId}`);
|
|
101
|
+
if (!isInvitationId(invitationId)) redirect(`${page}?error=failed`);
|
|
102
|
+
let outcome: string;
|
|
103
|
+
try {
|
|
104
|
+
const { status, body } = await call("POST", `/v1/invitations/${invitationId}/accept`);
|
|
105
|
+
const code = errorCode(body);
|
|
106
|
+
outcome =
|
|
107
|
+
status === 200 ? "joined" : code !== null && KNOWN_REFUSALS.has(code) ? code : "failed";
|
|
108
|
+
if (outcome === "failed") console.error(`[account-invitation] accept status=${status}`);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.error(
|
|
111
|
+
`[account-invitation] accept errName=${err instanceof Error ? err.name : "unknown"}`,
|
|
112
|
+
);
|
|
113
|
+
outcome = "failed";
|
|
114
|
+
}
|
|
115
|
+
redirect(outcome === "joined" ? `${page}?joined=1` : `${page}?error=${outcome}`);
|
|
116
|
+
}
|
package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The invitation id check the page and `actions.ts` run before any call
|
|
3
|
+
* (#11141). Not in `actions.ts`: Next.js makes every runtime export of a
|
|
4
|
+
* "use server" file a Server Action and fails the build on a synchronous one.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** `invite_` + a uuid — the table's id format, checked before any call. */
|
|
8
|
+
const INVITATION_ID = /^invite_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
9
|
+
|
|
10
|
+
export function isInvitationId(value: string): boolean {
|
|
11
|
+
return INVITATION_ID.test(value);
|
|
12
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /[locale]/account/invitations/[invitationId] — accept an invitation to an
|
|
3
|
+
* organization (#11106, spec
|
|
4
|
+
* docs/specs/11106-the-workforce-foundation-roles-by-spec.md D5; AC-3).
|
|
5
|
+
*
|
|
6
|
+
* The mailed link is `/sign-in?next=/account/invitations/<id>&email=<address>`:
|
|
7
|
+
* a signed-out visitor lands on `/sign-in` with the invited address already
|
|
8
|
+
* filled, and this page sits under `(authed)`, whose gate redirects any other
|
|
9
|
+
* signed-out visit to `/sign-in?next=…`. Signed in, the page reads the
|
|
10
|
+
* invitation (`readInvitation`), which the API answers only for the invited,
|
|
11
|
+
* VERIFIED address:
|
|
12
|
+
*
|
|
13
|
+
* - pending: the organization, the inviter and the role, and Accept — a
|
|
14
|
+
* form POST to `acceptInvitation`, which creates the Membership and
|
|
15
|
+
* returns here with `?joined=1`. A GET of this page writes nothing;
|
|
16
|
+
* - another address: "This invitation is for a different email address.
|
|
17
|
+
* Sign out and sign in with the invited address.";
|
|
18
|
+
* - no such invitation, or a build without the invitation routes (404):
|
|
19
|
+
* `notFound()`;
|
|
20
|
+
* - accepted, expired or no longer open: one line saying so.
|
|
21
|
+
*
|
|
22
|
+
* After joining, the person reaches the Admin through its own sign-in, which
|
|
23
|
+
* now admits them. Every string is an `account.invitation.*` message.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Button, Container, Heading, InlineMessage, Text } from "@working-theory/ui/primitives";
|
|
27
|
+
import type { Metadata } from "next";
|
|
28
|
+
import { notFound } from "next/navigation";
|
|
29
|
+
import { getTranslations } from "next-intl/server";
|
|
30
|
+
import type { ReactElement, ReactNode } from "react";
|
|
31
|
+
|
|
32
|
+
import { acceptInvitation, readInvitation } from "./actions";
|
|
33
|
+
import { isInvitationId } from "./invitation-id";
|
|
34
|
+
|
|
35
|
+
interface Props {
|
|
36
|
+
params: Promise<{ locale: string; invitationId: string }>;
|
|
37
|
+
searchParams: Promise<{ joined?: string | string[]; error?: string | string[] }>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
41
|
+
const { locale } = await params;
|
|
42
|
+
const t = await getTranslations({ locale, namespace: "account" });
|
|
43
|
+
return { title: t("invitation.accept"), robots: { index: false, follow: false } };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `?error=` → its line's key; an unknown value is the generic failure. */
|
|
47
|
+
const ERROR_KEYS = {
|
|
48
|
+
invitation_for_another_address: "invitation.otherAddress",
|
|
49
|
+
invitation_not_pending: "invitation.notPending",
|
|
50
|
+
invitation_expired: "invitation.expired",
|
|
51
|
+
invitation_void: "invitation.void",
|
|
52
|
+
already_member: "invitation.alreadyMember",
|
|
53
|
+
} as const;
|
|
54
|
+
|
|
55
|
+
function errorKeyFor(
|
|
56
|
+
error: string | string[] | undefined,
|
|
57
|
+
): (typeof ERROR_KEYS)[keyof typeof ERROR_KEYS] | "invitation.failed" | null {
|
|
58
|
+
if (typeof error !== "string") return null;
|
|
59
|
+
return Object.hasOwn(ERROR_KEYS, error)
|
|
60
|
+
? ERROR_KEYS[error as keyof typeof ERROR_KEYS]
|
|
61
|
+
: "invitation.failed";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function Frame({ children }: { children: ReactNode }): ReactElement {
|
|
65
|
+
return (
|
|
66
|
+
<Container className="py-section">
|
|
67
|
+
<div className="flex max-w-prose flex-col gap-4" data-testid="account-invitation">
|
|
68
|
+
{children}
|
|
69
|
+
</div>
|
|
70
|
+
</Container>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default async function AccountInvitationPage({
|
|
75
|
+
params,
|
|
76
|
+
searchParams,
|
|
77
|
+
}: Props): Promise<ReactElement> {
|
|
78
|
+
const { locale, invitationId } = await params;
|
|
79
|
+
const { joined, error } = await searchParams;
|
|
80
|
+
if (!isInvitationId(invitationId)) notFound();
|
|
81
|
+
const t = await getTranslations({ locale, namespace: "account" });
|
|
82
|
+
const read = await readInvitation(invitationId);
|
|
83
|
+
|
|
84
|
+
if (read.kind === "not_found") notFound();
|
|
85
|
+
if (read.kind === "other_address" || read.kind === "failed") {
|
|
86
|
+
return (
|
|
87
|
+
<Frame>
|
|
88
|
+
<InlineMessage
|
|
89
|
+
variant="error"
|
|
90
|
+
role="alert"
|
|
91
|
+
data-testid={read.kind === "other_address" ? "account-invitation-other-address" : "account-invitation-failed"}
|
|
92
|
+
>
|
|
93
|
+
{t(read.kind === "other_address" ? "invitation.otherAddress" : "invitation.failed")}
|
|
94
|
+
</InlineMessage>
|
|
95
|
+
</Frame>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const { invitation } = read;
|
|
100
|
+
const organization = invitation.organizationName;
|
|
101
|
+
|
|
102
|
+
if (invitation.status === "accepted" && joined === "1") {
|
|
103
|
+
return (
|
|
104
|
+
<Frame>
|
|
105
|
+
<div data-testid="account-invitation-joined">
|
|
106
|
+
<Heading level={1} visual={3}>
|
|
107
|
+
{t("invitation.joined", { organization })}
|
|
108
|
+
</Heading>
|
|
109
|
+
</div>
|
|
110
|
+
<Text as="p" variant="body" tone="muted">
|
|
111
|
+
{t("invitation.joinedLead")}
|
|
112
|
+
</Text>
|
|
113
|
+
</Frame>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const expired =
|
|
118
|
+
invitation.expiresAt !== null && Date.parse(invitation.expiresAt) <= Date.now();
|
|
119
|
+
if (invitation.status !== "pending" || expired) {
|
|
120
|
+
return (
|
|
121
|
+
<Frame>
|
|
122
|
+
<InlineMessage variant="default" role="status" data-testid="account-invitation-closed">
|
|
123
|
+
{t(expired && invitation.status === "pending" ? "invitation.expired" : "invitation.notPending")}
|
|
124
|
+
</InlineMessage>
|
|
125
|
+
</Frame>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const role = t(`invitation.roles.${invitation.role}`);
|
|
130
|
+
const errorKey = errorKeyFor(error);
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Frame>
|
|
134
|
+
<Heading level={1} visual={3}>
|
|
135
|
+
{t("invitation.title", { organization })}
|
|
136
|
+
</Heading>
|
|
137
|
+
<Text as="p" variant="body" data-testid="account-invitation-lead">
|
|
138
|
+
{invitation.inviterName
|
|
139
|
+
? t("invitation.lead", { inviter: invitation.inviterName, organization, role })
|
|
140
|
+
: t("invitation.leadNoInviter", { organization, role })}
|
|
141
|
+
</Text>
|
|
142
|
+
{errorKey ? (
|
|
143
|
+
<InlineMessage variant="error" role="alert" data-testid="account-invitation-error">
|
|
144
|
+
{t(errorKey)}
|
|
145
|
+
</InlineMessage>
|
|
146
|
+
) : null}
|
|
147
|
+
<form action={acceptInvitation.bind(null, invitationId, locale)} data-testid="account-invitation-form">
|
|
148
|
+
<Button type="submit" size="big" data-testid="account-invitation-accept">
|
|
149
|
+
{t("invitation.accept")}
|
|
150
|
+
</Button>
|
|
151
|
+
</form>
|
|
152
|
+
</Frame>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -18,8 +18,10 @@
|
|
|
18
18
|
* the Inbox's phone For you tab); with no items there is no aside.
|
|
19
19
|
*
|
|
20
20
|
* #8465 — `SIGN_OUT_ENDPOINT` (set only on a spoke that signs in through its
|
|
21
|
-
* hub)
|
|
22
|
-
*
|
|
21
|
+
* hub) rides down as a prop; the client frame cannot import the generated
|
|
22
|
+
* seam. After that sign-out the frame lands on the site's home (#11095 D4):
|
|
23
|
+
* the spoke's `/account` would sign the person straight back in while their
|
|
24
|
+
* hub session lives.
|
|
23
25
|
*
|
|
24
26
|
* The `(authed)` layout above owns the signed-out gate, so a missing session
|
|
25
27
|
* here is a race (it expired between the two layouts): the page renders
|
|
@@ -41,7 +43,7 @@ import { getTranslations } from "next-intl/server";
|
|
|
41
43
|
import type { ReactElement, ReactNode } from "react";
|
|
42
44
|
|
|
43
45
|
import { siteLogo } from "../../../../lib/site-logo";
|
|
44
|
-
import {
|
|
46
|
+
import { SIGN_OUT_ENDPOINT } from "../../../../lib/topology.generated";
|
|
45
47
|
|
|
46
48
|
import { accountSession, loadForYou } from "./account-data";
|
|
47
49
|
import { AccountFrame } from "./account-frame";
|
|
@@ -76,7 +78,7 @@ export default async function AccountLayout({
|
|
|
76
78
|
const signOutProps = SIGN_OUT_ENDPOINT
|
|
77
79
|
? {
|
|
78
80
|
signOutEndpoint: SIGN_OUT_ENDPOINT,
|
|
79
|
-
signInHref: localeHref(locale,
|
|
81
|
+
signInHref: localeHref(locale, "/"),
|
|
80
82
|
}
|
|
81
83
|
: {};
|
|
82
84
|
|
|
@@ -107,7 +107,9 @@ export default async function AccountSecurityPage({ params }: Props): Promise<Re
|
|
|
107
107
|
// `(auth)/forgot-password/page.tsx` derivation.
|
|
108
108
|
resetUrl={`${process.env.BETTER_AUTH_URL ?? ""}${localeHref(locale, "/reset-password")}`}
|
|
109
109
|
signOutEndpoint={SIGN_OUT_ENDPOINT}
|
|
110
|
-
|
|
110
|
+
// A hub-session sign-out lands home: the spoke's /account would sign
|
|
111
|
+
// the person straight back in (#11095 D4). A hub keeps /sign-in.
|
|
112
|
+
signInHref={localeHref(locale, SIGN_OUT_ENDPOINT ? "/" : (SIGN_IN_PATH ?? "/"))}
|
|
111
113
|
labels={{
|
|
112
114
|
methodsHeading: t("settings.security.methodsHeading"),
|
|
113
115
|
passwordLabel: t("settings.security.passwordLabel"),
|
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
* RSC: reads the session through the generated topology seam's `readSession`
|
|
5
5
|
* (#7894 D10) — Better Auth's `auth.api.getSession` on a hub, the sealed
|
|
6
6
|
* hub-session cookie on a spoke that signs in through its hub. With no
|
|
7
|
-
* session it
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
7
|
+
* session it returns the generated gate seam's `SignedOutGate`, which
|
|
8
|
+
* redirects with the requested path as `next` (#11095 D3; the in-place gate
|
|
9
|
+
* page of #4984 is retired). This guard reads no public-route
|
|
10
|
+
* auth-requirement flag (spec Clarifications) — that flag governs whether
|
|
11
|
+
* PUBLIC marketing routes redirect; tenant signup data is never public, so
|
|
12
|
+
* this gate always applies.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* hub,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* Where the gate sends a visitor is the seam's (`signed-out-gate.generated.tsx`):
|
|
15
|
+
* on a hub, `/sign-in?next=<path>` — or, on an account path with no sign-in
|
|
16
|
+
* method on, the "Sign-in isn't available yet" block in place (#7430); on a
|
|
17
|
+
* hub sign-in spoke, `/api/hub-session/sign-in?next=<path>`. This layout
|
|
18
|
+
* therefore imports neither `auth.ts` nor the `(auth)` group, so a spoke that
|
|
19
|
+
* keeps its account area keeps this layout too (spec 7894 D9).
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
import { headers } from "next/headers";
|
|
@@ -38,8 +39,9 @@ export default async function AuthedLayout({
|
|
|
38
39
|
const requestHeaders = await headers();
|
|
39
40
|
const session = await readSession(requestHeaders);
|
|
40
41
|
|
|
41
|
-
//
|
|
42
|
-
// request
|
|
42
|
+
// Called, not rendered as an element: the gate is a server function of the
|
|
43
|
+
// request — its redirect throws from here, and its one in-place block is
|
|
44
|
+
// the element the layout returns.
|
|
43
45
|
if (!session) return SignedOutGate({ locale, requestHeaders });
|
|
44
46
|
|
|
45
47
|
// data-profile="app" puts the Pro-host editor surfaces in this group on
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
// signed-out-gate.generated.tsx — what the (authed) group shows a signed-out visitor.
|
|
2
2
|
//
|
|
3
3
|
// GENERATED by create-ailk for this site's topology and sign-in mode (#7894).
|
|
4
|
-
// Do not edit: every scaffold rewrites it. A hub
|
|
5
|
-
//
|
|
6
|
-
// through its hub (`--hub-sign-in`)
|
|
4
|
+
// Do not edit: every scaffold rewrites it. A hub redirects to its own
|
|
5
|
+
// /sign-in (an account path with no sign-in method on says so in place); a
|
|
6
|
+
// spoke that signs in through its hub (`--hub-sign-in`) redirects to its
|
|
7
|
+
// hub-session sign-in route.
|
|
7
8
|
import { localeHref } from "@working-theory/ui";
|
|
8
9
|
import { Button, Heading, Link, Text } from "@working-theory/ui/primitives";
|
|
9
|
-
import type { AuthPanelProvider } from "@working-theory/ui/sections";
|
|
10
10
|
import { readLocales } from "@working-theory/web-i18n";
|
|
11
|
+
import { redirect } from "next/navigation";
|
|
11
12
|
import { getTranslations } from "next-intl/server";
|
|
12
13
|
import type { ReactElement } from "react";
|
|
13
14
|
|
|
14
|
-
import { legalFootnote } from "../(auth)/legal-footnote";
|
|
15
|
-
import { resolveSignInCardText } from "../(auth)/sign-in/sign-in-text";
|
|
16
15
|
import { getActiveProviderIds } from "../../../lib/auth-env";
|
|
17
16
|
import { isAccountPath } from "../../../lib/auth-routes";
|
|
18
|
-
import { siteLogo } from "../../../lib/site-logo";
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const SUPPORTED_PROVIDERS: readonly AuthPanelProvider[] = ["google", "github"];
|
|
18
|
+
/** The methods a member signs in with on /sign-in's card. */
|
|
19
|
+
const MEMBER_METHODS: readonly string[] = ["google", "github", "magic-link"];
|
|
23
20
|
|
|
24
21
|
export interface SignedOutGateProps {
|
|
25
22
|
locale: string;
|
|
@@ -31,23 +28,17 @@ export async function SignedOutGate({
|
|
|
31
28
|
locale,
|
|
32
29
|
requestHeaders,
|
|
33
30
|
}: SignedOutGateProps): Promise<ReactElement> {
|
|
34
|
-
// No `x-pathname`, no locale read: a render outside the middleware
|
|
35
|
-
// the
|
|
31
|
+
// No `x-pathname`, no locale read: a render outside the middleware
|
|
32
|
+
// redirects to the bare /sign-in without touching the locale config.
|
|
36
33
|
const pathname = requestHeaders.get("x-pathname");
|
|
37
34
|
const isAccount =
|
|
38
35
|
pathname !== null && isAccountPath(pathname, readLocales());
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
namespace: isAccount ? "account.gate" : "waitlistDashboard.gate",
|
|
42
|
-
});
|
|
43
|
-
const active = getActiveProviderIds();
|
|
44
|
-
const emailLink = active.includes("magic-link");
|
|
45
|
-
const providers = active.filter((id): id is AuthPanelProvider =>
|
|
46
|
-
(SUPPORTED_PROVIDERS as readonly string[]).includes(id),
|
|
36
|
+
const hasMemberMethod = getActiveProviderIds().some((id) =>
|
|
37
|
+
MEMBER_METHODS.includes(id),
|
|
47
38
|
);
|
|
48
|
-
const signInPath = localeHref(locale, "/sign-in");
|
|
49
39
|
|
|
50
|
-
if (isAccount &&
|
|
40
|
+
if (isAccount && !hasMemberMethod) {
|
|
41
|
+
const t = await getTranslations({ locale, namespace: "account.gate" });
|
|
51
42
|
return (
|
|
52
43
|
<div
|
|
53
44
|
className="flex min-h-screen flex-col items-center justify-center gap-4 py-section text-center"
|
|
@@ -75,35 +66,12 @@ export async function SignedOutGate({
|
|
|
75
66
|
);
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
text,
|
|
86
|
-
emailLink,
|
|
87
|
-
...(isAccount
|
|
88
|
-
? {
|
|
89
|
-
logo: siteLogo(),
|
|
90
|
-
prospect: { ...text.prospect, href: localeHref(locale, "/sign-up") },
|
|
91
|
-
footnote: legalFootnote(locale, text.acknowledgement),
|
|
92
|
-
}
|
|
93
|
-
: {}),
|
|
94
|
-
}
|
|
95
|
-
: undefined;
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<SignInGate
|
|
99
|
-
labels={{
|
|
100
|
-
emptyHeadline: t("emptyHeadline"),
|
|
101
|
-
emptyDescription: t("emptyDescription"),
|
|
102
|
-
signInLinkLabel: t("signInLink"),
|
|
103
|
-
}}
|
|
104
|
-
signInPath={signInPath}
|
|
105
|
-
providers={providers}
|
|
106
|
-
{...(card ? { card } : {})}
|
|
107
|
-
/>
|
|
69
|
+
// Every other signed-out render is a redirect to the sign-in card, with the
|
|
70
|
+
// requested path as `next` (#11095 D3): `/sign-in` sanitizes it.
|
|
71
|
+
const signInPath = localeHref(locale, "/sign-in");
|
|
72
|
+
redirect(
|
|
73
|
+
pathname === null
|
|
74
|
+
? signInPath
|
|
75
|
+
: `${signInPath}?next=${encodeURIComponent(pathname)}`,
|
|
108
76
|
);
|
|
109
77
|
}
|