Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): add terms page and sign-in agreement (#1067)

Generdaa858adbe5e
diff --git a/src/web/src/app/(auth)/sign-in/sign-in-client.dom.test.ts b/src/web/src/app/(auth)/sign-in/sign-in-client.dom.test.ts
index 17cb1a917..afe7fb2a9 100644
--- a/src/web/src/app/(auth)/sign-in/sign-in-client.dom.test.ts
+++ b/src/web/src/app/(auth)/sign-in/sign-in-client.dom.test.ts
@@ -1,13 +1,16 @@
import { createElement } from "react"
import { beforeEach, describe, expect, it, vi } from "vitest"
-import { act, render, screen, setupUser } from "@/test/react-dom-harness"
+import { act, render, screen, setupUser, waitFor } from "@/test/react-dom-harness"
const mocks = vi.hoisted(() => ({
searchParams: new URLSearchParams(),
capture: vi.fn(),
send: vi.fn(),
verify: vi.fn(),
+ devSignIn: vi.fn(),
+ devSignUp: vi.fn(),
verifyInput: undefined as undefined | ((value: string) => Promise<void>),
+ socialGate: undefined as undefined | ((continuation: () => void) => void),
}))
vi.mock("@/lib/product-analytics", () => ({ captureProductAnalytics: mocks.capture }))
@@ -16,25 +19,27 @@ vi.mock("next/navigation", () => ({
}))
vi.mock("@/lib/auth-client", () => ({
authClient: { emailOtp: { sendVerificationOtp: mocks.send }, signIn: { emailOtp: mocks.verify } },
- signIn: {},
- signUp: {},
+ signIn: { email: mocks.devSignIn },
+ signUp: { email: mocks.devSignUp },
}))
-vi.mock("./sign-in-fields", () => ({
- SignInEmailField: () => null,
+vi.mock("./sign-in-fields", async importOriginal => ({
+ ...await importOriginal<typeof import("./sign-in-fields")>(),
SignInOtpField: ({ onChange }: { onChange: (value: string) => Promise<void> }) => { mocks.verifyInput = onChange; return null },
}))
vi.mock("./social-sign-in", () => ({
SocialSignIn: ({
postLoginUrl,
appleEnabled,
+ requestConsent,
}: {
postLoginUrl: string
appleEnabled: boolean
- }) => createElement("div", {
+ requestConsent: (continuation: () => void) => void
+ }) => { mocks.socialGate = requestConsent; return createElement("div", {
"data-testid": "social-sign-in-props",
"data-post-login-url": postLoginUrl,
"data-apple-enabled": String(appleEnabled),
- }),
+ }) },
}))
vi.mock("@/components/gradient-background", () => ({
GradientBackground: () => null,
@@ -53,7 +58,7 @@ import SignInPageClient from "./sign-in-client"
describe("sign-in client Apple availability", () => {
beforeEach(() => {
- vi.clearAllMocks(); mocks.send.mockResolvedValue({}); mocks.verify.mockResolvedValue({ error: { code: "INVALID_OTP", status: 400 } }); mocks.verifyInput = undefined
+ vi.clearAllMocks(); mocks.send.mockResolvedValue({}); mocks.verify.mockResolvedValue({ error: { code: "INVALID_OTP", status: 400 } }); mocks.verifyInput = undefined; mocks.socialGate = undefined
mocks.searchParams = new URLSearchParams("redirect=%2Fc%2Fme")
window.matchMedia = vi.fn(() => ({
matches: false,
@@ -70,9 +75,191 @@ describe("sign-in client Apple availability", () => {
expect(screen.queryByText("Your account and its data were removed.")).toBeNull()
})
+ it("holds email, verification and the passed social continuation behind the same agreement", async () => {
+ render(createElement(SignInPageClient, { isProd: true, appleEnabled: true }))
+ const user = setupUser()
+ await user.click(screen.getByRole("button", { name: "Send Code" }))
+ expect(mocks.send).not.toHaveBeenCalled()
+ const social = vi.fn()
+ await act(async () => mocks.socialGate!(social))
+ expect(social).not.toHaveBeenCalled()
+ await user.type(screen.getByRole("textbox", { name: "Email" }), "[email protected]")
+ await user.click(screen.getByRole("checkbox"))
+ await user.click(screen.getByRole("button", { name: "Send Code" }))
+ expect(mocks.send).toHaveBeenCalledOnce()
+ await act(async () => mocks.socialGate!(social))
+ expect(social).toHaveBeenCalledOnce()
+ await user.click(screen.getByRole("checkbox"))
+ await act(async () => { await mocks.verifyInput!("123456") })
+ expect(mocks.verify).not.toHaveBeenCalled()
+ await user.click(screen.getByRole("checkbox"))
+ await act(async () => { await mocks.verifyInput!("123456") })
+ expect(mocks.verify).toHaveBeenCalledExactlyOnceWith({ email: "[email protected]", otp: "123456" })
+ })
+
+ it("mobile confirmation starts email once and keeps the existing OTP error flow", async () => {
+ window.matchMedia = vi.fn((query: string) => ({ matches: query.includes("max-width"), addEventListener: vi.fn(), removeEventListener: vi.fn() })) as never
+ render(createElement(SignInPageClient, { isProd: true, appleEnabled: false }))
+ const user = setupUser()
+ await user.type(screen.getByRole("textbox", { name: "Email" }), "[email protected]")
+ await user.click(screen.getByRole("button", { name: "Send Code" }))
+ expect(mocks.send).not.toHaveBeenCalled()
+ await user.click(screen.getByTestId("sign-in-terms-cancel"))
+ expect(mocks.send).not.toHaveBeenCalled()
+ expect(screen.getByRole("textbox", { name: "Email" })).toHaveValue("[email protected]")
+ await user.click(screen.getByRole("button", { name: "Send Code" }))
+ await user.click(screen.getByTestId("sign-in-terms-confirm"))
+ expect(mocks.send).toHaveBeenCalledOnce()
+ expect(mocks.send).toHaveBeenCalledWith(expect.objectContaining({ email: "[email protected]", type: "sign-in" }))
+ expect(screen.getByRole("checkbox")).toBeChecked()
+ await act(async () => { await mocks.verifyInput!("123456") })
+ expect(mocks.verify).toHaveBeenCalledOnce()
+ expect(mocks.capture).toHaveBeenLastCalledWith(expect.objectContaining({ failureStage: "verify_code" }))
+ })
+
+ it("guards development login and preserves its signup fallback after agreement", async () => {
+ mocks.devSignIn.mockResolvedValue({ error: { message: "Account not found" } })
+ mocks.devSignUp.mockResolvedValue({ error: { message: "Try again" } })
+ render(createElement(SignInPageClient, { isProd: false, appleEnabled: false }))
+ const user = setupUser()
+ await user.type(screen.getByRole("textbox", { name: "Email" }), "[email protected]")
+ await user.click(screen.getByRole("button", { name: "Sign in", exact: true }))
+ expect(mocks.devSignIn).not.toHaveBeenCalled()
+ expect(mocks.devSignUp).not.toHaveBeenCalled()
+ await user.click(screen.getByRole("checkbox"))
+ await user.click(screen.getByRole("button", { name: "Sign in", exact: true }))
+ expect(mocks.devSignIn).toHaveBeenCalledOnce()
+ expect(mocks.devSignUp).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ email: "[email protected]", name: "person" }), expect.any(Object))
+ expect(screen.getByRole("button", { name: "Sign in", exact: true })).toBeEnabled()
+ })
+
+ it.each([375, 640].flatMap(width => [true, false].flatMap(isProd => ["", "not-an-email"].map(email => ({ width, isProd, email })))))
+ ("at $width with isProd=$isProd, checks consent before validating email '$email' on button clicks", async ({ width, isProd, email }) => {
+ window.matchMedia = vi.fn((query: string) => ({ matches: query.includes("max-width") && width < 640, addEventListener: vi.fn(), removeEventListener: vi.fn() })) as never
+ mocks.devSignIn.mockResolvedValue({ error: { message: "Account not found" } })
+ mocks.devSignUp.mockResolvedValue({ error: { message: "Try again" } })
+ render(createElement(SignInPageClient, { isProd, appleEnabled: false }))
+ const user = setupUser()
+ const input = screen.getByRole("textbox", { name: "Email" }) as HTMLInputElement
+ const checkbox = screen.getByRole("checkbox") as HTMLInputElement
+ const label = isProd ? "Send Code" : "Sign in"
+ const request = isProd ? mocks.send : mocks.devSignIn
+ const invalidStates: { checked: boolean; dialog: boolean }[] = []
+ input.addEventListener("invalid", () => { invalidStates.push({ checked: checkbox.checked, dialog: screen.queryByRole("dialog") !== null }) })
+ expect(input).toBeRequired()
+ expect(input).toHaveAttribute("type", "email")
+ if (email) await user.type(input, email)
+ expect(input.validity.valid).toBe(false)
+ await user.click(screen.getByRole("button", { name: label }))
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ if (width < 640) {
+ expect(screen.getByRole("dialog")).toBeVisible()
+ await user.click(screen.getByTestId("sign-in-terms-cancel"))
+ }
+ expect(invalidStates).toEqual([])
+ expect(request).not.toHaveBeenCalled()
+ await user.click(checkbox)
+ await user.click(checkbox)
+ await user.click(screen.getByRole("button", { name: label }))
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ expect(request).not.toHaveBeenCalled()
+ if (width < 640) {
+ const confirm = screen.getByRole("button", { name: "Agree" })
+ await user.click(confirm)
+ await act(async () => confirm.click())
+ } else {
+ await user.click(checkbox)
+ await user.click(screen.getByRole("button", { name: label }))
+ }
+ expect(invalidStates).toEqual([{ checked: true, dialog: false }])
+ expect(request).not.toHaveBeenCalled()
+ expect(mocks.devSignUp).not.toHaveBeenCalled()
+ expect(checkbox).toBeChecked()
+ await user.clear(input)
+ await user.type(input, "[email protected]")
+ await user.click(screen.getByRole("button", { name: label }))
+ expect(request).toHaveBeenCalledOnce()
+ expect(request).toHaveBeenCalledWith(expect.objectContaining({ email: "[email protected]" }), ...isProd ? [] : [expect.any(Object)])
+ })
+
+ it.each([375, 640].flatMap(width => [true, false].map(isProd => ({ width, isProd }))))
+ ("at $width with isProd=$isProd, uses the same consent and email validation order on Enter", async ({ width, isProd }) => {
+ window.matchMedia = vi.fn((query: string) => ({ matches: query.includes("max-width") && width < 640, addEventListener: vi.fn(), removeEventListener: vi.fn() })) as never
+ mocks.devSignIn.mockResolvedValue({ error: { message: "Account not found" } })
+ mocks.devSignUp.mockResolvedValue({ error: { message: "Try again" } })
+ render(createElement(SignInPageClient, { isProd, appleEnabled: false }))
+ const user = setupUser()
+ const input = screen.getByRole("textbox", { name: "Email" })
+ const request = isProd ? mocks.send : mocks.devSignIn
+ await user.click(input)
+ await user.keyboard("{Enter}")
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ expect(request).not.toHaveBeenCalled()
+ if (width < 640) await user.click(screen.getByRole("button", { name: "Agree" }))
+ else {
+ await user.click(screen.getByRole("checkbox"))
+ await user.click(input)
+ await user.keyboard("{Enter}")
+ }
+ expect(request).not.toHaveBeenCalled()
+ expect(input).toBeInvalid()
+ await user.type(input, "[email protected]{Enter}")
+ expect(request).toHaveBeenCalledOnce()
+ })
+
+ it.each([true, false])("with isProd=%s, submits the email validated after the dialog finishes closing", async isProd => {
+ window.matchMedia = vi.fn((query: string) => ({ matches: query.includes("max-width"), addEventListener: vi.fn(), removeEventListener: vi.fn() })) as never
+ mocks.devSignIn.mockResolvedValue({ error: { message: "Account not found" } })
+ mocks.devSignUp.mockResolvedValue({ error: { message: "Try again" } })
+ render(createElement(SignInPageClient, { isProd, appleEnabled: false }))
+ const user = setupUser()
+ const input = screen.getByRole("textbox", { name: "Email" })
+ const request = isProd ? mocks.send : mocks.devSignIn
+ await user.type(input, "[email protected]")
+ await user.click(screen.getByRole("button", { name: isProd ? "Send Code" : "Sign in" }))
+ const popup = screen.getByRole("dialog")
+ let finish!: () => void
+ const finished = new Promise<void>(resolve => { finish = resolve })
+ const getAnimations = vi.fn(() => [{ finished }])
+ Object.defineProperty(popup, "getAnimations", { value: getAnimations })
+ await user.click(screen.getByRole("button", { name: "Agree" }))
+ await waitFor(() => expect(getAnimations).toHaveBeenCalled())
+ expect(request).not.toHaveBeenCalled()
+ await user.clear(input)
+ await user.type(input, "[email protected]")
+ await act(async () => { finish(); await finished })
+ await waitFor(() => expect(request).toHaveBeenCalledOnce())
+ expect(request.mock.calls[0][0]).toEqual(expect.objectContaining({ email: "[email protected]" }))
+ })
+
+ it.each([true, false].flatMap(isProd => ["", "not-an-email"].flatMap(email => ["button", "enter"].map(submission => ({ isProd, email, submission })))))("with isProd=$isProd, email='$email' and $submission, preserves native invalid-email focus after the mobile dialog closes", async ({ isProd, email, submission }) => {
+ window.matchMedia = vi.fn((query: string) => ({ matches: query.includes("max-width"), addEventListener: vi.fn(), removeEventListener: vi.fn() })) as never
+ render(createElement(SignInPageClient, { isProd, appleEnabled: false }))
+ const user = setupUser()
+ const input = screen.getByRole("textbox", { name: "Email" })
+ const invalid = vi.fn(() => input.focus())
+ input.addEventListener("invalid", invalid)
+ if (email) await user.type(input, email)
+ if (submission === "button") {
+ await user.click(screen.getByRole("button", { name: isProd ? "Send Code" : "Sign in" }))
+ } else {
+ await user.click(input)
+ await user.keyboard("{Enter}")
+ }
+ await user.click(screen.getByRole("button", { name: "Agree" }))
+ await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull())
+ await act(async () => { await Promise.resolve() })
+ expect(invalid).toHaveBeenCalledOnce()
+ expect(input).toHaveFocus()
+ expect(mocks.send).not.toHaveBeenCalled()
+ expect(mocks.devSignIn).not.toHaveBeenCalled()
+ })
+
it("counts login entry once and records only bounded OTP failure dimensions", async () => {
render(createElement(SignInPageClient, { isProd: true, appleEnabled: false }))
expect(mocks.capture).toHaveBeenCalledWith({ event: "login_page_view" })
+ await setupUser().type(screen.getByRole("textbox", { name: "Email" }), "[email protected]")
+ await setupUser().click(screen.getByRole("checkbox"))
await setupUser().click(screen.getByRole("button", { name: "Send Code" }))
expect(mocks.capture).toHaveBeenCalledTimes(1)
await act(async () => { await mocks.verifyInput!("123456") })
@@ -84,6 +271,8 @@ describe("sign-in client Apple availability", () => {
it("records send-code failure without mistaking it for successful authentication", async () => {
mocks.send.mockResolvedValueOnce({ error: { status: 429 } })
render(createElement(SignInPageClient, { isProd: true, appleEnabled: false }))
+ await setupUser().type(screen.getByRole("textbox", { name: "Email" }), "[email protected]")
+ await setupUser().click(screen.getByRole("checkbox"))
await setupUser().click(screen.getByRole("button", { name: "Send Code" }))
expect(mocks.capture).toHaveBeenLastCalledWith({ event: "sign_in_failed", method: "email_otp", failureStage: "send_code", error: { status: 429 } })
expect(JSON.stringify(mocks.capture.mock.calls)).not.toContain("private detail")
@@ -94,6 +283,8 @@ describe("sign-in client Apple availability", () => {
const error = new TypeError("Failed to fetch")
mocks.send.mockRejectedValueOnce(error)
render(createElement(SignInPageClient, { isProd: true, appleEnabled: false }))
+ await setupUser().type(screen.getByRole("textbox", { name: "Email" }), "[email protected]")
+ await setupUser().click(screen.getByRole("checkbox"))
await setupUser().click(screen.getByRole("button", { name: "Send Code" }))
expect(mocks.capture).toHaveBeenLastCalledWith({ event: "sign_in_failed", method: "email_otp", failureStage: "send_code", error })
await setupUser().click(screen.getByRole("button", { name: "Send Code" }))
diff --git a/src/web/src/app/(auth)/sign-in/sign-in-client.tsx b/src/web/src/app/(auth)/sign-in/sign-in-client.tsx
index 6c07659e2..5bb95879d 100644
--- a/src/web/src/app/(auth)/sign-in/sign-in-client.tsx
+++ b/src/web/src/app/(auth)/sign-in/sign-in-client.tsx
@@ -18,6 +18,7 @@ import {
} from "@/components/ui/field"
import { SignInEmailField, SignInOtpField } from "./sign-in-fields"
import { SocialSignIn } from "./social-sign-in"
+import { useSignInTerms } from "./sign-in-terms"
import { GradientBackground } from "@/components/gradient-background"
import { Logo } from "@/components/logo"
import { LandingShellMotion } from "@/components/home/landing-shell-motion"
@@ -64,6 +65,7 @@ function SignInForm({
const [code, setCode] = useAtom(useCreateAtom(""))
const [step, setStep] = useAtom(useCreateAtom<"email" | "code">("email"))
const [retryAfter, setRetryAfter] = useAtom(useCreateAtom<number | null>(null))
+ const terms = useSignInTerms()
useEffect(() => {
if (retryAfter == null) return
@@ -83,8 +85,19 @@ function SignInForm({
},
}
- async function handleSendCode(e: React.SubmitEvent) {
+ function handleEmailSubmit(e: React.SubmitEvent<HTMLFormElement>) {
e.preventDefault()
+ const form = e.currentTarget
+ terms.requestConsent(() => {
+ if (!form.reportValidity()) return
+ const emailInput = form.elements.namedItem("email")
+ if (!(emailInput instanceof HTMLInputElement)) return
+ if (isProd) void sendCode(emailInput.value)
+ else void devSignIn(emailInput.value)
+ })
+ }
+
+ async function sendCode(email: string) {
if (retryAfter != null) return
const observation = startAction("auth_send_code")
setEmailError("")
@@ -117,6 +130,10 @@ function SignInForm({
setCode(value)
setOtpError("")
if (value.length !== 6) return
+ terms.requestConsent(() => { void verifyCode(value) })
+ }
+
+ async function verifyCode(value: string) {
const observation = startAction("auth_verify_code")
setLoading(true)
@@ -144,8 +161,7 @@ function SignInForm({
setLoading(false)
}
- async function handleDevSignIn(e: React.SubmitEvent) {
- e.preventDefault()
+ async function devSignIn(email: string) {
const observation = startAction("auth_dev_sign_in")
setEmailError("")
setLoading(true)
@@ -215,7 +231,7 @@ function SignInForm({
{isProd ? (
step === "email" ? (
- <form onSubmit={handleSendCode}>
+ <form noValidate onSubmit={handleEmailSubmit}>
<FieldGroup>
<SignInEmailField
email={email}
@@ -264,7 +280,7 @@ function SignInForm({
</>
)
) : (
- <form onSubmit={handleDevSignIn}>
+ <form noValidate onSubmit={handleEmailSubmit}>
<FieldGroup>
<SignInEmailField
email={email}
@@ -289,10 +305,11 @@ function SignInForm({
</form>
)}
+ {terms.control}
<FieldSeparator className="*:data-[slot=field-separator-content]:bg-card">
Or continue with
</FieldSeparator>
- <SocialSignIn postLoginUrl={postLoginUrl} appleEnabled={appleEnabled} />
+ <SocialSignIn postLoginUrl={postLoginUrl} appleEnabled={appleEnabled} requestConsent={terms.requestConsent} />
</FieldGroup>
)
}
diff --git a/src/web/src/app/(auth)/sign-in/sign-in-terms.dom.test.tsx b/src/web/src/app/(auth)/sign-in/sign-in-terms.dom.test.tsx
new file mode 100644
index 000000000..bfdf2269c
--- /dev/null
+++ b/src/web/src/app/(auth)/sign-in/sign-in-terms.dom.test.tsx
@@ -0,0 +1,204 @@
+import { createElement } from "react"
+import { beforeEach, describe, expect, it, vi } from "vitest"
+import { act, render, screen, setupUser, waitFor } from "@/test/react-dom-harness"
+import { useSignInTerms } from "./sign-in-terms"
+
+let width = 640
+let reducedMotion = false
+const continued = vi.fn()
+const animate = vi.fn()
+
+function SignIn() {
+ const terms = useSignInTerms()
+ return <>{terms.control}
+ <button onClick={() => terms.requestConsent(() => continued("email"))}>Email</button>
+ <button onClick={() => terms.requestConsent(() => continued("google"))}>Google</button>
+ </>
+}
+
+beforeEach(() => {
+ vi.clearAllMocks()
+ width = 640
+ reducedMotion = false
+ animate.mockImplementation(() => ({ cancel: vi.fn() }))
+ window.matchMedia = vi.fn((query: string) => ({
+ matches: query.includes("max-width") ? width < 640 : query.includes("reduced-motion") && reducedMotion,
+ addEventListener: vi.fn(), removeEventListener: vi.fn(),
+ })) as never
+ HTMLElement.prototype.animate = animate
+})
+
+const agreement = () => screen.getByRole("checkbox", { name: "I agree to the Terms of Service" })
+
+describe("sign-in agreement", () => {
+ it("starts unchecked and keeps policy links separate from agreement", async () => {
+ render(createElement(SignIn))
+ expect(agreement()).not.toBeChecked()
+ for (const [name, href] of [["Terms of Service", "/terms"], ["Privacy Policy", "/privacy"]]) {
+ const link = screen.getByRole("link", { name })
+ expect(link).toHaveAttribute("href", href)
+ expect(link).toHaveAttribute("target", "_blank")
+ await setupUser().click(link)
+ expect(agreement()).not.toBeChecked()
+ }
+ expect(continued).not.toHaveBeenCalled()
+ })
+
+ it.each([640, 1280])("at %spx focuses and shakes without starting login or opening a dialog", async value => {
+ width = value
+ render(createElement(SignIn))
+ await setupUser().click(screen.getByRole("button", { name: "Google" }))
+ expect(agreement()).toHaveFocus()
+ expect(agreement()).not.toBeChecked()
+ expect(screen.getByRole("alert")).toHaveTextContent("I agree to the Terms of Service")
+ expect(screen.getByRole("alert")).toHaveClass("text-destructive")
+ expect(screen.queryByText("Please agree to the Terms of Service to continue.")).toBeNull()
+ expect(animate).toHaveBeenCalledOnce()
+ expect(screen.queryByRole("dialog")).toBeNull()
+ expect(continued).not.toHaveBeenCalled()
+ })
+
+ it("keeps the desktop reminder and focus without motion when reduced motion is enabled", async () => {
+ reducedMotion = true
+ render(createElement(SignIn))
+ await setupUser().click(screen.getByRole("button", { name: "Email" }))
+ expect(agreement()).toHaveFocus()
+ expect(screen.getByRole("alert")).toHaveTextContent("I agree to the Terms of Service")
+ expect(screen.getByRole("alert")).toHaveClass("text-destructive")
+ expect(animate).not.toHaveBeenCalled()
+ expect(continued).not.toHaveBeenCalled()
+ })
+
+ it("restarts one finite shake for every unchecked attempt and stops it on agreement or unmount", async () => {
+ const result = render(createElement(SignIn))
+ const user = setupUser()
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ const first = animate.mock.results[0].value
+ await user.click(screen.getByRole("button", { name: "Google" }))
+ const second = animate.mock.results[1].value
+ expect(first.cancel).toHaveBeenCalledOnce()
+ expect(second.cancel).not.toHaveBeenCalled()
+ expect(animate).toHaveBeenCalledTimes(2)
+ for (const [frames, options] of animate.mock.calls) {
+ expect(frames[0]).toEqual({ transform: "translateX(0)" })
+ expect(frames.at(-1)).toEqual({ transform: "translateX(0)" })
+ expect(options).toEqual({ duration: 280, easing: "ease-in-out" })
+ }
+ expect(agreement()).toHaveFocus()
+ expect(continued).not.toHaveBeenCalled()
+ await user.click(agreement())
+ expect(second.cancel).toHaveBeenCalledOnce()
+ await user.click(agreement())
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ const third = animate.mock.results[2].value
+ result.unmount()
+ expect(third.cancel).toHaveBeenCalledOnce()
+ expect(continued).not.toHaveBeenCalled()
+ })
+
+ it.each([375, 639])("at %spx cancels without accepting and confirms the selected method only once", async value => {
+ width = value
+ render(createElement(SignIn))
+ const checkbox = agreement()
+ const user = setupUser()
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ expect(screen.getByRole("dialog")).toHaveTextContent("Agree to continue")
+ expect(checkbox).not.toBeChecked()
+ expect(checkbox).toHaveAttribute("aria-invalid", "true")
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ expect(continued).not.toHaveBeenCalled()
+ await user.click(screen.getByTestId("sign-in-terms-cancel"))
+ expect(agreement()).not.toBeChecked()
+ expect(screen.getByRole("button", { name: "Email" })).toHaveFocus()
+ expect(screen.getByRole("alert")).toHaveClass("text-destructive")
+ expect(continued).not.toHaveBeenCalled()
+ await user.click(screen.getByRole("button", { name: "Google" }))
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ const confirm = screen.getByTestId("sign-in-terms-confirm")
+ expect(confirm).toHaveTextContent(/^Agree$/)
+ await user.click(confirm)
+ await act(async () => confirm.click())
+ expect(agreement()).toBeChecked()
+ expect(continued).toHaveBeenCalledExactlyOnceWith("google")
+ expect(animate).not.toHaveBeenCalled()
+ })
+
+ it("discards a pending mobile action when dismissed or unmounted", async () => {
+ width = 375
+ const result = render(createElement(SignIn))
+ const user = setupUser()
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ await user.keyboard("{Escape}")
+ expect(agreement()).not.toBeChecked()
+ expect(screen.getByRole("button", { name: "Email" })).toHaveFocus()
+ expect(continued).not.toHaveBeenCalled()
+ await user.click(screen.getByRole("button", { name: "Google" }))
+ const confirm = screen.getByTestId("sign-in-terms-confirm")
+ result.unmount()
+ await act(async () => confirm.click())
+ expect(continued).not.toHaveBeenCalled()
+ })
+
+ it.each(["replace", "uncheck", "unmount"])("handles %s while the confirmed dialog is still closing", async action => {
+ width = 375
+ const result = render(createElement(SignIn))
+ const user = setupUser()
+ const checkbox = agreement()
+ await user.click(screen.getByRole("button", { name: "Google" }))
+ const popup = screen.getByRole("dialog")
+ let finish!: () => void
+ const finished = new Promise<void>(resolve => { finish = resolve })
+ const getAnimations = vi.fn(() => [{ finished }])
+ Object.defineProperty(popup, "getAnimations", { value: getAnimations })
+ await user.click(screen.getByRole("button", { name: "Agree" }))
+ await waitFor(() => expect(getAnimations).toHaveBeenCalled())
+ expect(continued).not.toHaveBeenCalled()
+ if (action === "replace") {
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ expect(continued).not.toHaveBeenCalled()
+ } else if (action === "uncheck") {
+ await user.click(checkbox)
+ } else result.unmount()
+ await act(async () => { finish(); await finished })
+ if (action === "replace") {
+ await waitFor(() => expect(continued).toHaveBeenCalledExactlyOnceWith("email"))
+ } else {
+ if (action === "uncheck") await user.click(checkbox)
+ expect(continued).not.toHaveBeenCalled()
+ }
+ })
+
+ it.each([375, 639, 640, 1280])("at %spx rechecks current agreement when switching methods after unchecking", async value => {
+ width = value
+ render(createElement(SignIn))
+ const user = setupUser()
+ await user.click(agreement())
+ expect(screen.queryByRole("alert")).toBeNull()
+ expect(document.getElementById("sign-in-terms-copy")).not.toHaveClass("text-destructive")
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ expect(continued).toHaveBeenCalledExactlyOnceWith("email")
+ await user.click(agreement())
+ await user.click(screen.getByRole("button", { name: "Google" }))
+ expect(continued).toHaveBeenCalledOnce()
+ const checkbox = document.getElementById("sign-in-terms-checkbox")
+ expect(checkbox).not.toBeChecked()
+ expect(checkbox).toHaveAttribute("aria-invalid", "true")
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ if (value < 640) {
+ expect(screen.getByRole("dialog")).toBeVisible()
+ await user.click(screen.getByTestId("sign-in-terms-cancel"))
+ await user.click(screen.getByRole("button", { name: "Email" }))
+ expect(document.getElementById("sign-in-terms-copy")).toHaveClass("text-destructive")
+ await user.click(screen.getByRole("button", { name: "Agree" }))
+ expect(continued.mock.calls).toEqual([["email"], ["email"]])
+ expect(agreement()).toBeChecked()
+ expect(screen.queryByRole("alert")).toBeNull()
+ expect(animate).not.toHaveBeenCalled()
+ } else {
+ expect(screen.getByRole("alert")).toBeVisible()
+ expect(screen.queryByRole("dialog")).toBeNull()
+ expect(checkbox).toHaveFocus()
+ expect(animate).toHaveBeenCalledOnce()
+ }
+ })
+})
diff --git a/src/web/src/app/(auth)/sign-in/sign-in-terms.tsx b/src/web/src/app/(auth)/sign-in/sign-in-terms.tsx
new file mode 100644
index 000000000..af03522da
--- /dev/null
+++ b/src/web/src/app/(auth)/sign-in/sign-in-terms.tsx
@@ -0,0 +1,105 @@
+"use client"
+
+import { useEffect, useRef } from "react"
+import { useAtom, useCreateAtom } from "@tanstack/react-store"
+import { useIsMobile } from "@/hooks/use-mobile"
+import { Button } from "@/components/ui/button"
+import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"
+import { handleMessageExternalLinkClick } from "@/components/community/messages/message-external-link"
+
+function PolicyLinks() {
+ const linkClass = "underline underline-offset-3 hover:text-foreground"
+ return <>
+ I agree to the <a href="/terms" target="_blank" rel="noopener noreferrer" className={linkClass} onClick={event => { void handleMessageExternalLinkClick(event, event.currentTarget.href) }}>Terms of Service</a>.
+ {" "}See our <a href="/privacy" target="_blank" rel="noopener noreferrer" className={linkClass} onClick={event => { void handleMessageExternalLinkClick(event, event.currentTarget.href) }}>Privacy Policy</a>.
+ </>
+}
+
+export function useSignInTerms() {
+ const [accepted, setAccepted] = useAtom(useCreateAtom(false))
+ const [open, setOpen] = useAtom(useCreateAtom(false))
+ const [dialogClosed, setDialogClosed] = useAtom(useCreateAtom(true))
+ const [reminder, setReminder] = useAtom(useCreateAtom(false))
+ const pending = useRef<(() => void) | null>(null)
+ const checkbox = useRef<HTMLInputElement>(null)
+ const area = useRef<HTMLDivElement>(null)
+ const shake = useRef<Animation | null>(null)
+ const mobile = useIsMobile()
+
+ useEffect(() => () => { pending.current = null; shake.current?.cancel() }, [])
+ useEffect(() => {
+ if (!accepted || open || !dialogClosed) return
+ const continuation = pending.current
+ pending.current = null
+ continuation?.()
+ }, [accepted, open, dialogClosed])
+
+ const requestConsent = (continueSignIn: () => void) => {
+ if (accepted) {
+ if (!dialogClosed) pending.current = continueSignIn
+ else {
+ pending.current = null
+ continueSignIn()
+ }
+ return
+ }
+ setReminder(true)
+ shake.current?.cancel()
+ shake.current = null
+ if (mobile) {
+ pending.current = continueSignIn
+ setDialogClosed(false)
+ setOpen(true)
+ return
+ }
+ checkbox.current?.focus()
+ if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
+ shake.current = area.current?.animate?.([
+ { transform: "translateX(0)" },
+ { transform: "translateX(-6px)" },
+ { transform: "translateX(6px)" },
+ { transform: "translateX(-4px)" },
+ { transform: "translateX(0)" },
+ ], { duration: 280, easing: "ease-in-out" }) ?? null
+ }
+ }
+
+ const changeOpen = (next: boolean) => {
+ setOpen(next)
+ if (!next) pending.current = null
+ }
+ const confirm = () => {
+ setAccepted(true)
+ setReminder(false)
+ setOpen(false)
+ }
+
+ return {
+ requestConsent,
+ control: <>
+ <div ref={area} className="space-y-2" data-testid="sign-in-terms">
+ <div className="flex items-start gap-2 text-sm text-muted-foreground">
+ <label className="-mx-3.5 grid size-11 shrink-0 cursor-pointer place-items-center" htmlFor="sign-in-terms-checkbox">
+ <input id="sign-in-terms-checkbox" ref={checkbox} type="checkbox" className="size-4 accent-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
+ checked={accepted} onChange={event => { pending.current = null; setAccepted(event.target.checked); setReminder(false); shake.current?.cancel(); shake.current = null }}
+ aria-label="I agree to the Terms of Service" aria-invalid={reminder || undefined}
+ aria-describedby={reminder ? "sign-in-terms-copy" : undefined} />
+ </label>
+ <span id="sign-in-terms-copy" role={reminder ? "alert" : undefined} className={`py-2${reminder ? " text-destructive" : ""}`}><PolicyLinks /></span>
+ </div>
+ </div>
+ <Dialog open={open} onOpenChange={changeOpen} onOpenChangeComplete={next => setDialogClosed(!next)}>
+ <DialogContent showCloseButton={false} finalFocus={!accepted} className="w-[calc(100%-2rem)] max-w-sm">
+ <DialogHeader>
+ <DialogTitle>Agree to continue</DialogTitle>
+ <DialogDescription><PolicyLinks /></DialogDescription>
+ </DialogHeader>
+ <DialogFooter className="flex-row">
+ <Button type="button" variant="outline" className="h-11 flex-1" data-testid="sign-in-terms-cancel" onClick={() => changeOpen(false)}>Cancel</Button>
+ <Button type="button" className="h-11 flex-1" data-testid="sign-in-terms-confirm" onClick={confirm}>Agree</Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </>,
+ }
+}
diff --git a/src/web/src/app/(auth)/sign-in/social-sign-in.dom.test.ts b/src/web/src/app/(auth)/sign-in/social-sign-in.dom.test.ts
index 0103fb722..545dbb6b7 100644
--- a/src/web/src/app/(auth)/sign-in/social-sign-in.dom.test.ts
+++ b/src/web/src/app/(auth)/sign-in/social-sign-in.dom.test.ts
@@ -1,4 +1,4 @@
-import { createElement } from "react"
+import { createElement, type ComponentProps } from "react"
import { createHash } from "node:crypto"
import { existsSync, readFileSync } from "node:fs"
import { resolve } from "node:path"
@@ -42,7 +42,11 @@ vi.mock("@/lib/native-oauth-client", () => ({
},
}))
-import { SocialSignIn } from "./social-sign-in"
+import { SocialSignIn as SocialSignInComponent } from "./social-sign-in"
+
+function SocialSignIn(props: Omit<ComponentProps<typeof SocialSignInComponent>, "requestConsent">) {
+ return createElement(SocialSignInComponent, { ...props, requestConsent: continuation => continuation() })
+}
beforeEach(() => {
mocks.tauri = false
@@ -64,6 +68,19 @@ const attempt = {
}
describe("social sign-in native boundary", () => {
+ it.each([false, true])("holds the selected provider until the shared consent gate admits it, native=%s", async native => {
+ mocks.tauri = native
+ let continuation: (() => void) | undefined
+ const gate = vi.fn((next: () => void) => { continuation = next })
+ render(createElement(SocialSignInComponent, { postLoginUrl: "/c/me?tab=1", appleEnabled: true, requestConsent: gate }))
+ await setupUser().click(button("native-oauth-apple"))
+ expect(gate).toHaveBeenCalledOnce()
+ expect(mocks.social).not.toHaveBeenCalled()
+ expect(mocks.start).not.toHaveBeenCalled()
+ await act(async () => continuation!())
+ if (native) expect(mocks.start).toHaveBeenCalledExactlyOnceWith("apple", "/c/me?tab=1")
+ else expect(mocks.social).toHaveBeenCalledExactlyOnceWith({ provider: "apple", callbackURL: "/c/me?tab=1" })
+ })
it.each(["google", "github"])("forwards %s rejection details and does not count successful starts as failures", async provider => {
const error = { code: "PROVIDER_NOT_FOUND", message: "Provider not found", status: 404 }
mocks.social.mockResolvedValueOnce({ error })
diff --git a/src/web/src/app/(auth)/sign-in/social-sign-in.tsx b/src/web/src/app/(auth)/sign-in/social-sign-in.tsx
index 72f5a4a25..2a24f8fdd 100644
--- a/src/web/src/app/(auth)/sign-in/social-sign-in.tsx
+++ b/src/web/src/app/(auth)/sign-in/social-sign-in.tsx
@@ -32,9 +32,11 @@ const messages = {
export function SocialSignIn({
postLoginUrl,
appleEnabled = false,
+ requestConsent,
}: {
postLoginUrl: string
appleEnabled?: boolean
+ requestConsent: (continuation: () => void) => void
}) {
const observed = useRef<Action | undefined>(undefined)
const controller = useRef<ReturnType<typeof createNativeOauthController> | null>(null)
@@ -50,7 +52,8 @@ export function SocialSignIn({
void instance.connect()
return () => { instance.dispose(); if (controller.current === instance) controller.current = null }
}, [setNative])
- const begin = (provider: NativeOauthProvider) => {
+ const begin = (provider: NativeOauthProvider) => requestConsent(() => start(provider))
+ const start = (provider: NativeOauthProvider) => {
finishAction(observed.current, "superseded")
observed.current = startAction("auth_social", { capability: "limited", phase: "auth" })
lastProvider.current = provider
diff --git a/src/web/src/app/terms/layout.tsx b/src/web/src/app/terms/layout.tsx
new file mode 100644
index 000000000..9a12db6f5
--- /dev/null
+++ b/src/web/src/app/terms/layout.tsx
@@ -0,0 +1,6 @@
+import { ThemeToggle } from "@/components/theme-toggle"
+import { PublicLayout } from "@/components/public-layout"
+
+export default function TermsLayout({ children }: { children: React.ReactNode }) {
+ return <PublicLayout rightSlot={<ThemeToggle />} footer="simple">{children}</PublicLayout>
+}
diff --git a/src/web/src/app/terms/page.tsx b/src/web/src/app/terms/page.tsx
new file mode 100644
index 000000000..50cb20aa2
--- /dev/null
+++ b/src/web/src/app/terms/page.tsx
@@ -0,0 +1,19 @@
+import { ObservedStaticContent } from "@/lib/observability/regions"
+import { buildPublicPageMetadata } from "@/lib/seo/public-page-metadata"
+import { TERMS_OF_SERVICE } from "@/lib/terms"
+import { TermsContent } from "@/components/terms/terms-content"
+
+export const metadata = buildPublicPageMetadata({
+ title: `${TERMS_OF_SERVICE.title} — Alook`,
+ description: "Read Alook’s Terms of Service, including your account responsibilities, content rights and acceptable use.",
+ path: "/terms",
+})
+
+export default function TermsPage() {
+ return (
+ <><ObservedStaticContent /><main className="mx-auto max-w-3xl px-6 pt-12 pb-28 sm:pt-24">
+ <h1 className="mb-4 text-4xl font-semibold tracking-tight sm:text-5xl">{TERMS_OF_SERVICE.title}</h1>
+ <TermsContent />
+ </main></>
+ )
+}
diff --git a/src/web/src/components/community/settings/user-settings.tsx b/src/web/src/components/community/settings/user-settings.tsx
index d8dc0ff72..05dccb371 100644
--- a/src/web/src/components/community/settings/user-settings.tsx
+++ b/src/web/src/components/community/settings/user-settings.tsx
@@ -7,12 +7,13 @@ import { useAtom, useCreateAtom, useCreateStore } from "@tanstack/react-store";
import { useEffect, useLayoutEffect } from "react"
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { toastApiError } from "@/lib/api/client"
-import { User, LogOut, Palette, Sun, Moon, Monitor, Database, Camera, Shield, CreditCard } from "lucide-react"
+import { User, LogOut, Palette, Sun, Moon, Monitor, Database, Camera, Shield, CreditCard, FileText } from "lucide-react"
import { useTheme } from "next-themes"
import { Button } from "@/components/ui/button"
import { AutoResizeTextarea } from "@/components/ui/auto-resize-textarea"
import { ConfirmDialog } from "@/components/ui/confirm-dialog"
import { PrivacyPolicyContent } from "@/components/privacy/privacy-policy-content"
+import { TermsContent } from "@/components/terms/terms-content"
import {
clearAllPersistedCaches,
formatBytes,
@@ -36,7 +37,7 @@ const THEME_OPTIONS = [
{ value: "system", label: "System", icon: Monitor },
] as const
-type UserSettingsTab = "profile" | "appearance" | "advanced" | "privacy" | "billing"
+type UserSettingsTab = "profile" | "appearance" | "advanced" | "privacy" | "terms" | "billing"
const USER_SETTINGS_TABS: SettingsShellTab<UserSettingsTab>[] = [
{ value: "profile", label: "My Profile", icon: User },
@@ -44,6 +45,7 @@ const USER_SETTINGS_TABS: SettingsShellTab<UserSettingsTab>[] = [
{ value: "appearance", label: "Appearance", icon: Palette },
{ value: "advanced", label: "Advanced", icon: Database },
{ value: "privacy", label: "Privacy", icon: Shield },
+ { value: "terms", label: "Terms", icon: FileText },
]
function AppearanceSettings() {
@@ -244,7 +246,7 @@ export function UserSettings({ initialTab = "profile", billingReturn = null, onC
value={tab}
onValueChange={setTab}
label="User Settings"
- title={tab === "billing" ? "Subscription & billing" : deletionOpen ? "Delete account" : tab === "appearance" ? "Appearance" : tab === "advanced" ? "Advanced" : tab === "privacy" ? "Privacy Policy" : "My Profile"}
+ title={tab === "billing" ? "Subscription & billing" : deletionOpen ? "Delete account" : tab === "appearance" ? "Appearance" : tab === "advanced" ? "Advanced" : tab === "privacy" ? "Privacy Policy" : tab === "terms" ? "Terms of Service" : "My Profile"}
tabs={USER_SETTINGS_TABS}
onClose={onClose}
disabled={deletionOpen}
@@ -342,6 +344,11 @@ export function UserSettings({ initialTab = "profile", billingReturn = null, onC
<PrivacyPolicyContent />
</div>
</SettingsShellPanel>
+ <SettingsShellPanel value="terms">
+ <div className="mx-auto w-full max-w-2xl pb-8">
+ <TermsContent />
+ </div>
+ </SettingsShellPanel>
</>
)}
</SettingsShell>
diff --git a/src/web/src/components/public-layout.tsx b/src/web/src/components/public-layout.tsx
index 44a57b604..03ec74327 100644
--- a/src/web/src/components/public-layout.tsx
+++ b/src/web/src/components/public-layout.tsx
@@ -12,6 +12,7 @@ const footerLinks = [
{ href: DISCORD_INVITE_URL, label: "Discord", external: true },
{ href: "https://x.com/alook_ai", label: "X", external: true },
{ href: "/privacy", label: "Privacy" },
+ { href: "/terms", label: "Terms" },
];
export type PublicZone = "main" | "blog";
diff --git a/src/web/src/components/terms/terms-content.test.ts b/src/web/src/components/terms/terms-content.test.ts
new file mode 100644
index 000000000..a95ace666
--- /dev/null
+++ b/src/web/src/components/terms/terms-content.test.ts
@@ -0,0 +1,38 @@
+import { readFileSync } from "node:fs"
+import { createElement } from "react"
+import { renderToStaticMarkup } from "react-dom/server"
+import { describe, expect, it, vi } from "vitest"
+import TermsPage, { metadata } from "@/app/terms/page"
+import { TERMS_OF_SERVICE } from "@/lib/terms"
+import { TermsContent } from "./terms-content"
+
+vi.mock("@/lib/observability/regions", () => ({ ObservedStaticContent: () => null }))
+
+describe("Terms of Service", () => {
+ it("renders public terms with the shared body, company, limited rights and independent privacy link", () => {
+ const body = renderToStaticMarkup(createElement(TermsContent))
+ const page = renderToStaticMarkup(createElement(TermsPage))
+ expect(page).toContain(body)
+ expect(body).toContain(`data-terms-version="${TERMS_OF_SERVICE.version}"`)
+ expect(body).toContain("MEMODB PTE. LTD.")
+ expect(body).toContain('href="mailto:[email protected]"')
+ expect(body).toContain("You keep your rights")
+ expect(body).toContain("does not give")
+ expect(body).toContain("use it to train models")
+ expect(body).toContain("retroactively")
+ expect(body).toContain('href="/privacy"')
+ expect(body).toContain("does not enable optional analytics")
+ expect(body).not.toContain("governing law")
+ expect(body).not.toContain("report button")
+ })
+
+ it("uses the same content in its own Settings tab and keeps public sharing metadata canonical", () => {
+ const settings = readFileSync(new URL("../community/settings/user-settings.tsx", import.meta.url), "utf8")
+ expect(settings).toContain('{ value: "terms", label: "Terms", icon: FileText }')
+ expect(settings).toContain('<SettingsShellPanel value="terms">')
+ expect(settings).toContain("<TermsContent />")
+ expect(settings).toContain("<PrivacyPolicyContent />")
+ expect(metadata.alternates).toMatchObject({ canonical: "https://alook.ai/terms" })
+ expect(metadata.openGraph).toMatchObject({ url: "https://alook.ai/terms", title: `${TERMS_OF_SERVICE.title} — Alook` })
+ })
+})
diff --git a/src/web/src/components/terms/terms-content.tsx b/src/web/src/components/terms/terms-content.tsx
new file mode 100644
index 000000000..18c5ea665
--- /dev/null
+++ b/src/web/src/components/terms/terms-content.tsx
@@ -0,0 +1,83 @@
+import { TERMS_OF_SERVICE } from "@/lib/terms"
+import { cn } from "@/lib/utils"
+
+const linkClass = "underline decoration-foreground/30 underline-offset-3 transition-colors hover:decoration-foreground/60"
+
+export function TermsContent({ className }: { className?: string }) {
+ return (
+ <div className={cn(className)} data-terms-version={TERMS_OF_SERVICE.version}>
+ <p className="mb-12 text-sm text-muted-foreground">Last updated: {TERMS_OF_SERVICE.lastUpdated}</p>
+ <div className="prose prose-neutral max-w-none space-y-8 text-[1.0625rem] leading-relaxed dark:prose-invert">
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">Using Alook</h2>
+ <p className="text-foreground/80">
+ These Terms govern your use of Alook, a service for communication and collaboration
+ with people and agents provided by MEMODB PTE. LTD. (&quot;we&quot;, &quot;us&quot;).
+ By accepting these Terms, you agree to follow them when you use the service.
+ </p>
+ </section>
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">Your account and agents</h2>
+ <p className="text-foreground/80">
+ Keep your account credentials secure. You are responsible for the content and
+ actions you authorize through your account, including those of your agents.
+ Only connect accounts, computers and services that you have permission to use.
+ An agent does not remove your responsibility to have the necessary rights and permissions.
+ </p>
+ </section>
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">Your content and rights</h2>
+ <p className="text-foreground/80">
+ You keep your rights to the content you submit. You must own that content or have
+ the rights and permissions needed to submit it and share it with the audience you
+ choose. Respect other people&apos;s intellectual property, privacy and other rights.
+ </p>
+ <p className="mt-4 text-foreground/80">
+ You give us permission to store, transmit and display your content, and to process
+ it as necessary to provide the service you request. This permission is limited to
+ operating that service and respecting your chosen access settings. It does not give
+ us ownership of your content or permission to sell it, use it to train models, or use
+ it for unrelated marketing. These Terms do not grant us new rights over historical
+ content retroactively.
+ </p>
+ </section>
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">Acceptable use</h2>
+ <p className="text-foreground/80">Do not use Alook to submit or distribute:</p>
+ <ul className="mt-3 list-disc space-y-2 pl-6 text-foreground/80">
+ <li>Unlawful content or content that infringes another person&apos;s rights.</li>
+ <li>Threats, harassment, hateful abuse, or content that promotes violence.</li>
+ <li>Sexual exploitation, child sexual abuse material, or nonconsensual intimate content.</li>
+ <li>Fraud, malware, spam, or attempts to gain unauthorized access or bypass security.</li>
+ </ul>
+ <p className="mt-4 text-foreground/80">These responsibilities also apply to content submitted by your agents.</p>
+ </section>
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">Privacy and your choices</h2>
+ <p className="text-foreground/80">
+ Our <a href="/privacy" className={linkClass}>Privacy Policy</a> explains how we handle
+ personal information. Accepting these Terms does not enable optional analytics or
+ grant access to device permissions. Those choices remain separate.
+ </p>
+ </section>
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">App stores and other services</h2>
+ <p className="text-foreground/80">
+ If you download Alook from an app store, its applicable license terms also apply to
+ your use of the app. These service Terms do not replace Apple&apos;s standard app license
+ agreement or applicable Google Play terms. Apple and Google do not provide the Alook
+ service under these Terms. Other services you connect may have their own terms.
+ </p>
+ </section>
+ <section>
+ <h2 className="mt-10 mb-4 text-xl font-semibold">Changes and contact</h2>
+ <p className="text-foreground/80">
+ We may update these Terms. The version shown on this page identifies the terms
+ presented for acceptance. If you have questions about these Terms or content on
+ Alook, contact <a href="mailto:[email protected]" className={linkClass}>[email protected]</a>.
+ </p>
+ </section>
+ </div>
+ </div>
+ )
+}
diff --git a/src/web/src/lib/observability/coverage.ts b/src/web/src/lib/observability/coverage.ts
index 0c84e9d4a..489ce492e 100644
--- a/src/web/src/lib/observability/coverage.ts
+++ b/src/web/src/lib/observability/coverage.ts
@@ -26,6 +26,7 @@ export const pageRoutes = [
"/sign-in",
"/templates",
"/templates/[id]",
+ "/terms",
] as const
export const apiRoutes = [
diff --git a/src/web/src/lib/terms.ts b/src/web/src/lib/terms.ts
new file mode 100644
index 000000000..bc1cba265
--- /dev/null
+++ b/src/web/src/lib/terms.ts
@@ -0,0 +1,6 @@
+export const TERMS_OF_SERVICE = {
+ title: "Terms of Service",
+ version: "2026-10-25",
+ lastUpdated: "October 25, 2026",
+} as const
+
diff --git a/src/web/src/test/e2e-fixture-isolation.test.ts b/src/web/src/test/e2e-fixture-isolation.test.ts
index fff20dc50..31efa4123 100644
--- a/src/web/src/test/e2e-fixture-isolation.test.ts
+++ b/src/web/src/test/e2e-fixture-isolation.test.ts
@@ -779,6 +779,7 @@ describe("real login helper context exit", () => {
getByRole: vi.fn(() => ({
waitFor: vi.fn().mockResolvedValue(undefined),
fill: vi.fn().mockResolvedValue(undefined),
+ check: vi.fn().mockResolvedValue(undefined),
click: vi.fn().mockResolvedValue(undefined),
})),
}
@@ -881,6 +882,7 @@ describe("real login helper context exit", () => {
expect(result).toMatchObject({ key: "alice", userId: "unit-login-user", storageState: "unit-state.json" })
expect(result.name).toBe(result.email.split("@")[0])
expect(s.page.goto).toHaveBeenCalledWith("http://fixture.test/c", { waitUntil: "load" })
+ expect(s.page.getByRole).toHaveBeenCalledWith("checkbox", { name: "I agree to the Terms of Service" })
expect(s.context.request.get).toHaveBeenCalledWith("http://fixture.test/api/ws/token")
expect(s.context.addCookies).toHaveBeenCalledOnce()
expect(s.context.clearCookies).toHaveBeenCalledWith({ name: /^(?:is_new_signup|is_sign_in)$/ })
diff --git a/src/web/src/test/e2e-public-static-qa.test.ts b/src/web/src/test/e2e-public-static-qa.test.ts
index 8c16cb490..57d92ff62 100644
--- a/src/web/src/test/e2e-public-static-qa.test.ts
+++ b/src/web/src/test/e2e-public-static-qa.test.ts
@@ -75,7 +75,7 @@ describe("public static QA immutable input and phase controls", () => {
const failure = new Error("UI response lost")
const page = {
goto: async (url: string) => { visits.push(url) },
- getByRole: (role: string) => role === "textbox" ? { waitFor: async () => {}, fill: async () => {} } : { click: async () => { throw failure } },
+ getByRole: (role: string) => role === "textbox" ? { waitFor: async () => {}, fill: async () => {} } : role === "checkbox" ? { check: async () => {} } : { click: async () => { throw failure } },
waitForURL: async () => {},
} as unknown as Parameters<typeof signIn>[0]
await expect(signIn(page, "[email protected]", { singleAttempt: true, onSubmission: () => { submits.push(1) } })).rejects.toBe(failure)
diff --git a/src/web/src/test/e2e-ui/01-auth.spec.ts b/src/web/src/test/e2e-ui/01-auth.spec.ts
index 70b3342cf..d686aa866 100644
--- a/src/web/src/test/e2e-ui/01-auth.spec.ts
+++ b/src/web/src/test/e2e-ui/01-auth.spec.ts
@@ -143,6 +143,7 @@ browserTest.describe("production OTP error placement", () => {
browserTest.skip(!(await sendCode.isVisible()), "production Email OTP UI is not active")
await page.getByRole("textbox", { name: "Email" }).fill("[email protected]")
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
await sendCode.click()
const otp = page.getByRole("textbox", { name: "Verification code" })
@@ -230,6 +231,7 @@ browserTest.describe("production OTP error placement", () => {
const email = page.getByRole("textbox", { name: "Email" })
await email.fill("[email protected]")
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
await sendCode.click()
let alert = page.getByRole("alert").filter({ hasText: "Failed to send code" })
@@ -336,6 +338,7 @@ browserTest.describe("native OAuth status actions", () => {
await page.setViewportSize({ width: 390, height: 844 })
await page.goto("/sign-in")
await browserExpect(page.getByRole("button", { name: "GitHub" })).toBeEnabled()
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
await page.getByRole("button", { name: "GitHub" }).click()
await expectCenteredNativeOauthState(page, {
copy: "Opening sign-in in your browser…",
diff --git a/src/web/src/test/e2e-ui/25-community-ws-reconnect-overlay.spec.ts b/src/web/src/test/e2e-ui/25-community-ws-reconnect-overlay.spec.ts
index 60b50c600..687943ac7 100644
--- a/src/web/src/test/e2e-ui/25-community-ws-reconnect-overlay.spec.ts
+++ b/src/web/src/test/e2e-ui/25-community-ws-reconnect-overlay.spec.ts
@@ -272,6 +272,7 @@ let caseJourneyFailure1Present = false
await page.getByRole("textbox", { name: "Email" }).fill(
`guide-reconnect-${process.pid}-${Date.now()}@example.com`,
)
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
await page.getByRole("button", { name: "Sign in", exact: true }).click()
await page.waitForURL("**/c/me/machines", { waitUntil: "commit" })
const onboarding = page.getByTestId(tid.onboardingHarnessDialog)
diff --git a/src/web/src/test/e2e-ui/31-machine-guide-motion.spec.ts b/src/web/src/test/e2e-ui/31-machine-guide-motion.spec.ts
index 8bcfafd21..c9eda67b8 100644
--- a/src/web/src/test/e2e-ui/31-machine-guide-motion.spec.ts
+++ b/src/web/src/test/e2e-ui/31-machine-guide-motion.spec.ts
@@ -7,6 +7,7 @@ test("first-signup mobile starts onboarding once and retains it on desktop", asy
await page.getByRole("textbox", { name: "Email" }).fill(
`direct-onboarding-mobile-${process.pid}-${Date.now()}@example.com`,
)
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
await page.getByRole("button", { name: "Sign in", exact: true }).click()
await page.waitForURL("**/c/me/machines", { waitUntil: "commit" })
@@ -34,6 +35,7 @@ test("first-signup desktop opens onboarding before the empty Machines guide", as
await page.getByRole("textbox", { name: "Email" }).fill(
`direct-onboarding-desktop-${process.pid}-${Date.now()}@example.com`,
)
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
await page.getByRole("button", { name: "Sign in", exact: true }).click()
await page.waitForURL("**/c/me/machines", { waitUntil: "commit" })
diff --git a/src/web/src/test/e2e-ui/_setup/auth.ts b/src/web/src/test/e2e-ui/_setup/auth.ts
index d8bfbdc31..ecdb2bc7e 100644
--- a/src/web/src/test/e2e-ui/_setup/auth.ts
+++ b/src/web/src/test/e2e-ui/_setup/auth.ts
@@ -21,6 +21,7 @@ export async function signIn(page: Page, email: string, options: { singleAttempt
const emailInput = page.getByRole("textbox", { name: "Email" })
await emailInput.waitFor({ state: "visible", timeout: 15_000 })
await emailInput.fill(email)
+ await page.getByRole("checkbox", { name: "I agree to the Terms of Service" }).check()
options.onSubmission?.()
await page.getByRole("button", { name: "Sign in", exact: true }).click()
await page.waitForURL((current) => !current.pathname.startsWith("/sign-in"), {