Skip to content

Commit 8cf1ce7

Browse files
committed
Remove email-code sign-in; sign in with Google or GitHub only
There is no domain for a production email sender, so email codes are dropped. The sign-in page and dialog now offer only Google and GitHub (the first sign-in still creates the account). - Remove the email form, the passwordless Server Actions and their tests, the email schemas in @foliomind/contracts/forms (ActionResult stays) and lib/rate-limit.ts, whose only user was email sign-in - Settings lists Google and GitHub as sign-in methods - The Auth0 setup guide now asks to turn the database and passwordless connections off for the application; the passwordless routes stay closed in the proxy
1 parent 8f85741 commit 8cf1ce7

13 files changed

Lines changed: 80 additions & 728 deletions

File tree

‎apps/web/components/foliomind/screens/settings.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { Link2, LogOut, Mail, Monitor, Moon, Sun, Trash2 } from "lucide-react";
3+
import { Link2, LogOut, Monitor, Moon, Sun, Trash2 } from "lucide-react";
44
import Link from "next/link";
55
import { useTheme } from "next-themes";
66
import { useSyncExternalStore, type ReactNode } from "react";
@@ -91,7 +91,6 @@ export function SettingsScreen() {
9191
<ul className="divide-y rounded-lg border">
9292
<MethodRow icon={<GoogleMark className="size-5" />} name="Google" />
9393
<MethodRow icon={<GitHubMark className="size-5 text-foreground" />} name="GitHub" />
94-
<MethodRow icon={<Mail className="size-5" aria-hidden="true" />} name="Email code" />
9594
</ul>
9695
</Panel>
9796

‎apps/web/components/foliomind/sign-in-panel.test.tsx‎

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
import { render, screen } from "@testing-library/react";
2-
import userEvent from "@testing-library/user-event";
3-
import { beforeEach, describe, expect, it, vi } from "vitest";
4-
import { startEmailSignIn, verifyEmailCode } from "@/lib/auth/email-sign-in";
1+
import { render, screen, within } from "@testing-library/react";
2+
import { afterEach, describe, expect, it } from "vitest";
53
import { SignInPanel } from "./sign-in-panel";
64

7-
vi.mock("@/lib/auth/email-sign-in", () => ({
8-
startEmailSignIn: vi.fn(),
9-
verifyEmailCode: vi.fn(),
10-
}));
11-
12-
const start = vi.mocked(startEmailSignIn);
13-
const verify = vi.mocked(verifyEmailCode);
14-
155
describe("SignInPanel", () => {
16-
beforeEach(() => {
17-
start.mockReset();
18-
verify.mockReset();
6+
afterEach(() => {
7+
document.cookie = "fm_last_signin=; Max-Age=0; Path=/";
198
});
209

2110
it("sends Google and GitHub straight to their connections, never to Auth0's page", () => {
@@ -34,52 +23,24 @@ describe("SignInPanel", () => {
3423
}
3524
});
3625

37-
it("validates the email address before calling the server", async () => {
38-
const user = userEvent.setup();
26+
it("offers only Google and GitHub", () => {
3927
render(<SignInPanel returnTo="/dashboard" />);
40-
await user.type(screen.getByLabelText("Email address"), "not-an-email");
41-
await user.click(screen.getByRole("button", { name: "Email me a sign-in code" }));
42-
expect(await screen.findByText("Enter a valid email address.")).toBeInTheDocument();
43-
expect(start).not.toHaveBeenCalled();
28+
expect(screen.queryByRole("textbox")).not.toBeInTheDocument();
29+
expect(screen.queryByRole("button")).not.toBeInTheDocument();
4430
});
4531

46-
it("asks for the code after sending it, and shows server errors on the field", async () => {
47-
const user = userEvent.setup();
48-
start.mockResolvedValue({ ok: true, data: undefined });
49-
verify.mockResolvedValue({
50-
ok: false,
51-
code: "invalid_grant",
52-
fieldErrors: { code: ["That code didn't work. Check it, or send a new code."] },
53-
});
32+
it("marks the last used provider", () => {
33+
document.cookie = "fm_last_signin=github; Path=/";
5434
render(<SignInPanel returnTo="/dashboard" />);
55-
56-
await user.type(screen.getByLabelText("Email address"), " Ada@Example.com ");
57-
await user.click(screen.getByRole("button", { name: "Email me a sign-in code" }));
58-
expect(start).toHaveBeenCalledWith({ email: "ada@example.com" });
59-
expect(await screen.findByText("Check your email")).toBeInTheDocument();
60-
expect(screen.getByText("ada@example.com")).toBeInTheDocument();
61-
62-
await user.type(screen.getByLabelText("6-digit code"), "123456");
63-
await user.click(screen.getByRole("button", { name: "Sign in" }));
64-
expect(verify).toHaveBeenCalledWith({ email: "ada@example.com", code: "123456" });
65-
expect(
66-
await screen.findByText("That code didn't work. Check it, or send a new code."),
67-
).toBeInTheDocument();
68-
expect(screen.getByRole("button", { name: /Send a new code in \d+s/ })).toBeDisabled();
35+
const github = screen.getByRole("link", { name: /Continue with GitHub/ });
36+
expect(within(github).getByText("Last used")).toBeInTheDocument();
37+
expect(screen.getAllByText("Last used")).toHaveLength(1);
6938
});
7039

71-
it("shows a form-level message when email sign-in is unavailable", async () => {
72-
const user = userEvent.setup();
73-
start.mockResolvedValue({
74-
ok: false,
75-
code: "not_configured",
76-
formError:
77-
"Email sign-in isn't available right now. Try Google or GitHub, or try again later.",
78-
});
40+
it("ignores a last used value that is no longer offered", () => {
41+
document.cookie = "fm_last_signin=email; Path=/";
7942
render(<SignInPanel returnTo="/dashboard" />);
80-
await user.type(screen.getByLabelText("Email address"), "ada@example.com");
81-
await user.click(screen.getByRole("button", { name: "Email me a sign-in code" }));
82-
expect(await screen.findByText(/Email sign-in isn't available right now/)).toBeInTheDocument();
43+
expect(screen.queryByText("Last used")).not.toBeInTheDocument();
8344
});
8445

8546
it("shows sign-in errors passed from the callback", () => {

0 commit comments

Comments
 (0)