From 8c625981f6358ce4ec08702cdf1f6e03dce45f79 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Sun, 25 Aug 2024 11:40:15 -0700 Subject: [PATCH 01/13] Initial work on magic link auth via Cursor --- .cursorrules | 74 ++++++++++++ .vscode/settings.json | 3 +- apps/server/src/lib/auth.ts | 20 ++++ apps/server/src/lib/email.ts | 64 ++++++++--- apps/server/src/lib/scraper.ts | 52 ++++++++- apps/server/src/schemas/index.ts | 1 + apps/server/src/schemas/magicLink.ts | 10 ++ apps/server/src/trpc/router.ts | 6 + .../trpc/routes/authMagicLinkConfirm.test.ts | 106 ++++++++++++++++++ .../src/trpc/routes/authMagicLinkConfirm.ts | 89 +++++++++++++++ .../src/trpc/routes/authMagicLinkSend.test.ts | 67 +++++++++++ .../src/trpc/routes/authMagicLinkSend.ts | 40 +++++++ packages/email/src/components/core.tsx | 20 ++++ .../email/src/templates/magicLinkEmail.tsx | 42 +++++++ .../email/src/templates/newCommentEmail.tsx | 25 +---- 15 files changed, 579 insertions(+), 40 deletions(-) create mode 100644 .cursorrules create mode 100644 apps/server/src/schemas/magicLink.ts create mode 100644 apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts create mode 100644 apps/server/src/trpc/routes/authMagicLinkConfirm.ts create mode 100644 apps/server/src/trpc/routes/authMagicLinkSend.test.ts create mode 100644 apps/server/src/trpc/routes/authMagicLinkSend.ts create mode 100644 packages/email/src/templates/magicLinkEmail.tsx diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 000000000..cf17b097a --- /dev/null +++ b/.cursorrules @@ -0,0 +1,74 @@ +You are a Senior Frontend Developer and an Expert in React, Next.js, tRPC, TypeScript, TailwindCSS, HTML and CSS. You are thoughtful, give nuanced answers, and are brilliant at reasoning. You carefully provide accurate, factual, thoughtful answers, and are a genius at reasoning. + +Follow the user’s requirements carefully & to the letter. + +- First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail. +- Confirm, then write code! +- Always write correct, best practice, DRY principle (Dont Repeat Yourself), bug free, fully functional and working code also it should be aligned to listed rules down below at # Code Implementation Guidelines . +- Focus on easy and readability code, over being performant. +- Fully implement all requested functionality. +- Leave NO todo’s, placeholders or missing pieces. +- Ensure code is complete! Verify thoroughly finalised. +- Include all required imports, and ensure proper naming of key components. +- Be concise Minimize any other prose. +- If you think there might not be a correct answer, you say so. +- If you do not know the answer, say so, instead of guessing + +**Coding Environment** + +The user asks questions about the following coding languages and frameworks: + +- React +- Next.js +- Drizzle +- tRPC +- Vitest +- TypeScript +- TailwindCSS +- HTML +- CSS + +**Code Implementation Guidelines** + +Follow these rules when you write code: + +- Use early returns whenever possible to make the code more readable. +- Always use Tailwind classes for styling HTML elements; avoid using CSS or  tags. +- Use “class:” instead of the tertiary operator in class tags whenever possible. +- Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown. +- Implement accessibility features on elements. For example, a  tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes. +- Usefunctions instead of consts, for example, “function toggle() {}”. Also, define a type if possible. + +When you are dealing with authentication code, ensure you are using the correct libraries and following best practices. + +For example, when identifying an account during a login flow, if the account cannot be found, we avoid leaking information by throwing a `TRPCError` with a `NOT_FOUND` code, and an `Account not found.` message. + +**Test Implementation Guidelines** + +Follow these rules when you write tests: + +- Use Vitest, do not use Jest. +- When you are testing for errors, use `waitError` to wait for the error to be thrown. For example: + +``` +const err = await waitError( + caller.authPasswordResetConfirm({ + token, + password: "testpassword", + }), +); +``` + +- In addition to using `waitError`, utilize snapshots for the resulting error. For example, ```expect(err).toMatchInlineSnapshot();`` +- Prefer dependency injection over mocking when the called functions make it possible. +- When calling tRPC endpoints that are not expected to error, await on the caller. Do not test the Promise directly. For example: + +``` +const caller = createCaller(); + +const data = await caller.authRegister({ + username: "foo", + email: "foo@example.com", + password: "example", +}); +``` diff --git a/.vscode/settings.json b/.vscode/settings.json index 323b75bea..ae59c91e7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,6 @@ "**/app/**/layout.tsx": "${dirname} - Layout", "**/component/**/index.tsx": "${dirname} - Component" }, - "scm.showHistoryGraph": false + "scm.showHistoryGraph": false, + "makefile.configureOnOpen": false } diff --git a/apps/server/src/lib/auth.ts b/apps/server/src/lib/auth.ts index 972ca0825..87aee55df 100644 --- a/apps/server/src/lib/auth.ts +++ b/apps/server/src/lib/auth.ts @@ -11,6 +11,7 @@ import { random } from "../lib/rand"; import { serialize } from "../serializers"; import { UserSerializer } from "../serializers/user"; import { logError } from "./log"; +import { absoluteUrl } from "./urls"; export function signPayload(payload: string | object): Promise { return new Promise((res, rej) => { @@ -116,3 +117,22 @@ export async function createUser( if (!user) throw new Error("Unable to create user"); return user; } + +export async function generateMagicLink(user: User) { + const token = { + id: user.id, + email: user.email, + createdAt: new Date().toISOString(), + }; + + const signedToken = await signPayload(token); + const url = absoluteUrl( + config.URL_PREFIX, + `/auth/magic-link?token=${signedToken}`, + ); + + return { + token: signedToken, + url, + }; +} diff --git a/apps/server/src/lib/email.ts b/apps/server/src/lib/email.ts index 771898218..00e57b379 100644 --- a/apps/server/src/lib/email.ts +++ b/apps/server/src/lib/email.ts @@ -1,4 +1,5 @@ import cuid2 from "@paralleldrive/cuid2"; +import { Template as MagicLinkEmailTemplate } from "@peated/email/templates/magicLinkEmail"; import { Template as NewCommentTemplate } from "@peated/email/templates/newCommentEmail"; import { Template as PasswordResetEmailTemplate } from "@peated/email/templates/passwordResetEmail"; import { Template as VerifyEmailTemplate } from "@peated/email/templates/verifyEmail"; @@ -20,7 +21,8 @@ import { type User, } from "../db/schema"; import type { EmailVerifySchema, PasswordResetSchema } from "../schemas"; -import { signPayload } from "./auth"; +import { generateMagicLink, signPayload } from "./auth"; +import { sendMagicLinkEmail } from "./email"; import { logError } from "./log"; let mailTransport: Transporter; @@ -147,6 +149,7 @@ export async function sendVerificationEmail({ user: User; transport?: Transporter; }) { + // TODO: error out if (!hasEmailSupport()) return; if (!transport) { @@ -187,6 +190,7 @@ export async function sendPasswordResetEmail({ user: User; transport?: Transporter; }) { + // TODO: error out if (!hasEmailSupport()) return; if (!transport) { @@ -210,20 +214,48 @@ export async function sendPasswordResetEmail({ PasswordResetEmailTemplate({ baseUrl: config.URL_PREFIX, resetUrl }), ); - try { - await transport.sendMail({ - from: `"${config.SMTP_FROM_NAME}" <${config.SMTP_FROM}>`, - to: user.email, - subject: "Reset Password", - // TODO: - text: `A password reset was requested for your account.\n\nIf you don't recognize this request, you can ignore this.\n\nTo continue: ${resetUrl}`, - html, - replyTo: `"${config.SMTP_FROM_NAME}" <${config.SMTP_REPLY_TO || config.SMTP_FROM}>`, - headers: { - References: `${cuid2.createId()}@peated.com`, - }, - }); - } catch (err) { - logError(err); + await transport.sendMail({ + from: `"${config.SMTP_FROM_NAME}" <${config.SMTP_FROM}>`, + to: user.email, + subject: "Reset Password", + // TODO: + text: `A password reset was requested for your account.\n\nIf you don't recognize this request, you can ignore this.\n\nTo continue: ${resetUrl}`, + html, + replyTo: `"${config.SMTP_FROM_NAME}" <${config.SMTP_REPLY_TO || config.SMTP_FROM}>`, + headers: { + References: `${cuid2.createId()}@peated.com`, + }, + }); +} + +export async function sendMagicLinkEmail({ + user, + transport = mailTransport, +}: { + user: User; + transport?: Transporter; +}) { + // TODO: error out + if (!hasEmailSupport()) return; + + if (!transport) { + if (!mailTransport) mailTransport = createMailTransport(); + transport = mailTransport; } + + const magicLink = await generateMagicLink(user); + + const html = await render( + MagicLinkEmailTemplate({ + baseUrl: config.URL_PREFIX, + magicLinkUrl: magicLink.url, + }), + ); + + await transport.sendMail({ + to: user.email, + subject: "Magic Link for Peated", + text: `Click the following link to log in to Peated: ${magicLink.url}`, + html: html, + }); } diff --git a/apps/server/src/lib/scraper.ts b/apps/server/src/lib/scraper.ts index 228e6a2da..8752bc9fa 100644 --- a/apps/server/src/lib/scraper.ts +++ b/apps/server/src/lib/scraper.ts @@ -1,9 +1,12 @@ -import { defaultHeaders } from "@peated/server/constants"; +import { + defaultHeaders, + SCRAPER_PRICE_BATCH_SIZE, +} from "@peated/server/constants"; import { ApiClient } from "@peated/server/lib/apiClient"; import { logError } from "@peated/server/lib/log"; import { trpcClient } from "@peated/server/lib/trpc/server"; import { isTRPCClientError } from "@peated/server/trpc/client"; -import type { Currency } from "@peated/server/types"; +import type { Currency, ExternalSiteType } from "@peated/server/types"; import { type Category } from "@peated/server/types"; import axios from "axios"; import { existsSync, mkdirSync, statSync } from "fs"; @@ -11,6 +14,7 @@ import { open } from "fs/promises"; import type { z } from "zod"; import config from "../config"; import type { BottleInputSchema, StorePriceInputSchema } from "../schemas"; +import BatchQueue from "./batchQueue"; const CACHE = ".cache"; @@ -200,3 +204,47 @@ export async function handleBottle( console.log(`Dry Run [${bottle.name}]`); } } + +export default async function scrapePrices( + site: ExternalSiteType, + scrapeProducts: (product: StorePrice) => Promise, +) { + const workQueue = new BatchQueue( + SCRAPER_PRICE_BATCH_SIZE, + async (prices) => { + console.log("Pushing new price data to API"); + await trpcClient.priceCreateBatch.mutate({ + site, + prices, + }); + }, + ); + + const uniqueProducts = new Set(); + + let hasProducts = true; + let page = 1; + while (hasProducts) { + hasProducts = false; + await scrapeProducts( + `https://www.healthyspirits.com/spirits/whiskey/page${page}.html?limit=72`, + async (product) => { + console.log(`${product.name} - ${(product.price / 100).toFixed(2)}`); + if (uniqueProducts.has(product.name)) return; + await workQueue.push(product); + uniqueProducts.add(product.name); + hasProducts = true; + }, + ); + page += 1; + } + + const products = Array.from(uniqueProducts.values()); + if (products.length === 0) { + throw new Error("Failed to scrape any products."); + } + + await workQueue.processRemaining(); + + console.log(`Complete - ${products.length} products found`); +} diff --git a/apps/server/src/schemas/index.ts b/apps/server/src/schemas/index.ts index 98c5c40c4..e575bcc15 100644 --- a/apps/server/src/schemas/index.ts +++ b/apps/server/src/schemas/index.ts @@ -12,6 +12,7 @@ export * from "./externalSites"; export * from "./flights"; export * from "./follows"; export * from "./friends"; +export * from "./magicLink"; export * from "./notifications"; export * from "./regions"; export * from "./reviews"; diff --git a/apps/server/src/schemas/magicLink.ts b/apps/server/src/schemas/magicLink.ts new file mode 100644 index 000000000..816ee7a1d --- /dev/null +++ b/apps/server/src/schemas/magicLink.ts @@ -0,0 +1,10 @@ +import { z } from "zod"; +import { zDatetime } from "./common"; + +export const MagicLinkSchema = z.object({ + id: z.number(), + email: z.string().email(), + createdAt: zDatetime, +}); + +export type MagicLink = z.infer; diff --git a/apps/server/src/trpc/router.ts b/apps/server/src/trpc/router.ts index ca75d386d..558238ae2 100644 --- a/apps/server/src/trpc/router.ts +++ b/apps/server/src/trpc/router.ts @@ -4,6 +4,8 @@ import type { Context } from "./context"; import auth from "./routes/auth"; import authBasic from "./routes/authBasic"; import authGoogle from "./routes/authGoogle"; +import authMagicLinkConfirm from "./routes/authMagicLinkConfirm"; +import authMagicLinkSend from "./routes/authMagicLinkSend"; import authPasswordReset from "./routes/authPasswordReset"; import authPasswordResetConfirm from "./routes/authPasswordResetConfirm"; import authRegister from "./routes/authRegister"; @@ -118,6 +120,8 @@ export const appRouter = router({ auth, authBasic, authGoogle, + authMagicLinkConfirm, + authMagicLinkSend, authRegister, authPasswordReset, authPasswordResetConfirm, @@ -227,6 +231,8 @@ export const appRouter = router({ userTagList, userUpdate, version, + authMagicLinkSend, + authMagicLinkConfirm, }); export type AppRouter = typeof appRouter; diff --git a/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts b/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts new file mode 100644 index 000000000..c575a0540 --- /dev/null +++ b/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts @@ -0,0 +1,106 @@ +import { createAccessToken, verifyPayload } from "@peated/server/lib/auth"; +import waitError from "@peated/server/lib/test/waitError"; +import { beforeEach, describe, expect, test, vi } from "vitest"; +import { createCaller } from "../router"; + +// Mock the auth functions +vi.mock("@peated/server/lib/auth", () => ({ + createAccessToken: vi.fn().mockResolvedValue("mocked-access-token"), + verifyPayload: vi.fn(), +})); + +describe("authMagicLinkConfirm", () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + test("confirms magic link for active user", async ({ fixtures }) => { + const user = await fixtures.User({ active: true, verified: false }); + const caller = createCaller({ user: null }); + const token = "valid-token"; + + vi.mocked(verifyPayload).mockResolvedValue({ + id: user.id, + email: user.email, + createdAt: new Date().toISOString(), + }); + + const result = await caller.authMagicLinkConfirm({ token }); + + expect(result.user.id).toBe(user.id); + expect(result.user.verified).toBe(true); + expect(result.accessToken).toBe("mocked-access-token"); + expect(createAccessToken).toHaveBeenCalledWith( + expect.objectContaining({ id: user.id }), + ); + }); + + test("throws error for invalid token", async ({ fixtures }) => { + const caller = createCaller({ user: null }); + const token = "invalid-token"; + + vi.mocked(verifyPayload).mockRejectedValue(new Error("Invalid token")); + + const error = await waitError(caller.authMagicLinkConfirm({ token })); + + expect(error).toMatchInlineSnapshot( + `[TRPCError: Invalid magic link token.]`, + ); + }); + + test("throws error for expired token", async ({ fixtures }) => { + const user = await fixtures.User({ active: true }); + const caller = createCaller({ user: null }); + const token = "expired-token"; + + const expiredDate = new Date(); + expiredDate.setMinutes(expiredDate.getMinutes() - 11); // 11 minutes ago + + vi.mocked(verifyPayload).mockResolvedValue({ + id: user.id, + email: user.email, + createdAt: expiredDate.toISOString(), + }); + + const error = await waitError(caller.authMagicLinkConfirm({ token })); + + expect(error).toMatchInlineSnapshot( + `[TRPCError: Invalid magic link token.]`, + ); + }); + + test("throws error for inactive user", async ({ fixtures }) => { + const user = await fixtures.User({ active: false }); + const caller = createCaller({ user: null }); + const token = "valid-token"; + + vi.mocked(verifyPayload).mockResolvedValue({ + id: user.id, + email: user.email, + createdAt: new Date().toISOString(), + }); + + const error = await waitError(caller.authMagicLinkConfirm({ token })); + + expect(error).toMatchInlineSnapshot( + `[TRPCError: Invalid magic link token.]`, + ); + }); + + test("throws error for non-existent user", async ({ fixtures }) => { + const caller = createCaller({ user: null }); + const token = "valid-token"; + + vi.mocked(verifyPayload).mockResolvedValue({ + id: "non-existent-id", + email: "nonexistent@example.com", + createdAt: new Date().toISOString(), + }); + + const error = await waitError(caller.authMagicLinkConfirm({ token })); + + expect(error).toMatchInlineSnapshot( + `[TRPCError: Invalid magic link token.]`, + ); + }); +}); diff --git a/apps/server/src/trpc/routes/authMagicLinkConfirm.ts b/apps/server/src/trpc/routes/authMagicLinkConfirm.ts new file mode 100644 index 000000000..7c5f58fd8 --- /dev/null +++ b/apps/server/src/trpc/routes/authMagicLinkConfirm.ts @@ -0,0 +1,89 @@ +import { db } from "@peated/server/db"; +import { users } from "@peated/server/db/schema"; +import { createAccessToken, verifyPayload } from "@peated/server/lib/auth"; +import { MagicLinkSchema } from "@peated/server/schemas/magicLink"; +import { serialize } from "@peated/server/serializers"; +import { UserSerializer } from "@peated/server/serializers/user"; +import { TRPCError } from "@trpc/server"; +import { and, eq, sql } from "drizzle-orm"; +import { z } from "zod"; +import { publicProcedure } from ".."; + +const TOKEN_CUTOFF = 600; // 10 minutes + +export default publicProcedure + .input( + z.object({ + token: z.string(), + }), + ) + .mutation(async function ({ input }) { + let payload; + try { + payload = await verifyPayload(input.token); + } catch (err) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Invalid magic link token.", + cause: err, + }); + } + + let parsedPayload; + try { + parsedPayload = MagicLinkSchema.parse(payload); + } catch (err) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Invalid magic link token.", + cause: err, + }); + } + + if ( + new Date(parsedPayload.createdAt).getTime() < + new Date().getTime() - TOKEN_CUTOFF * 1000 + ) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Invalid magic link token.", + }); + } + + const [user] = await db + .select() + .from(users) + .where( + and( + eq(users.id, parsedPayload.id), + eq(sql`LOWER(${users.email})`, parsedPayload.email.toLowerCase()), + ), + ); + if (!user) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Invalid magic link token.", + }); + } + + if (!user.active) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "Invalid magic link token.", + }); + } + + // Update user as verified + const [updatedUser] = await db + .update(users) + .set({ + verified: true, + }) + .where(eq(users.id, user.id)) + .returning(); + + return { + user: await serialize(UserSerializer, updatedUser, updatedUser), + accessToken: await createAccessToken(updatedUser), + }; + }); diff --git a/apps/server/src/trpc/routes/authMagicLinkSend.test.ts b/apps/server/src/trpc/routes/authMagicLinkSend.test.ts new file mode 100644 index 000000000..424276c84 --- /dev/null +++ b/apps/server/src/trpc/routes/authMagicLinkSend.test.ts @@ -0,0 +1,67 @@ +import { sendMagicLinkEmail } from "@peated/server/lib/email"; +import waitError from "@peated/server/lib/test/waitError"; +import { beforeEach, describe, expect, test, vi } from "vitest"; +import { createCaller } from "../router"; + +// Mock the sendMagicLinkEmail function +vi.mock("@peated/server/lib/email", () => ({ + sendMagicLinkEmail: vi.fn(), +})); + +describe("authMagicLinkSend", () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + test("sends magic link for active user", async ({ fixtures }) => { + const user = await fixtures.User({ active: true }); + const caller = createCaller({ user: null }); + + const result = await caller.authMagicLinkSend({ + email: user.email, + }); + + expect(result).toEqual({}); + expect(sendMagicLinkEmail).toHaveBeenCalledWith({ user }); + }); + + test("throws error when user is not found", async ({ fixtures }) => { + const caller = createCaller({ user: null }); + + const error = await waitError( + caller.authMagicLinkSend({ + email: "nonexistent@example.com", + }), + ); + + expect(error).toMatchInlineSnapshot(`[TRPCError: Account not found.]`); + }); + + test("throws error when user is not active", async ({ fixtures }) => { + const user = await fixtures.User({ active: false }); + const caller = createCaller({ user: null }); + + const error = await waitError( + caller.authMagicLinkSend({ + email: user.email, + }), + ); + + expect(error).toMatchInlineSnapshot(`[TRPCError: Account not found.]`); + }); + + test("is case-insensitive for email", async ({ fixtures }) => { + const user = await fixtures.User({ + active: true, + email: "User@Example.com", + }); + const caller = createCaller({ user: null }); + + const result = await caller.authMagicLinkSend({ + email: "uSER@eXAMPLE.COM", + }); + + expect(result).toEqual({}); + expect(sendMagicLinkEmail).toHaveBeenCalledWith({ user }); + }); +}); diff --git a/apps/server/src/trpc/routes/authMagicLinkSend.ts b/apps/server/src/trpc/routes/authMagicLinkSend.ts new file mode 100644 index 000000000..a6322290b --- /dev/null +++ b/apps/server/src/trpc/routes/authMagicLinkSend.ts @@ -0,0 +1,40 @@ +import { db } from "@peated/server/db"; +import { users } from "@peated/server/db/schema"; +import { sendMagicLinkEmail } from "@peated/server/lib/email"; +import { TRPCError } from "@trpc/server"; +import { eq, sql } from "drizzle-orm"; +import { z } from "zod"; +import { publicProcedure } from ".."; + +export default publicProcedure + .input( + z.object({ + email: z.string().email(), + }), + ) + .mutation(async function ({ input: { email } }) { + const [user] = await db + .select() + .from(users) + .where(eq(sql`LOWER(${users.email})`, email.toLowerCase())); + + if (!user) { + console.log("user not found"); + throw new TRPCError({ + message: "Account not found.", + code: "NOT_FOUND", + }); + } + + if (!user.active) { + console.log("user not active"); + throw new TRPCError({ + message: "Account not found.", + code: "NOT_FOUND", + }); + } + + await sendMagicLinkEmail({ user }); + + return {}; + }); diff --git a/packages/email/src/components/core.tsx b/packages/email/src/components/core.tsx index 0a78568cc..680f7020c 100644 --- a/packages/email/src/components/core.tsx +++ b/packages/email/src/components/core.tsx @@ -1,6 +1,7 @@ import theme from "@peated/design"; import { Button as DefaultButton, + Heading as DefaultHeading, Hr as DefaultHr, Link as DefaultLink, Section as DefaultSection, @@ -99,3 +100,22 @@ export function Link({ /> ); } + +export function Heading({ + style = {}, + ...props +}: ComponentProps) { + return ( + + ); +} diff --git a/packages/email/src/templates/magicLinkEmail.tsx b/packages/email/src/templates/magicLinkEmail.tsx new file mode 100644 index 000000000..37d33e1ec --- /dev/null +++ b/packages/email/src/templates/magicLinkEmail.tsx @@ -0,0 +1,42 @@ +import theme from "@peated/design"; +import { Preview } from "jsx-email"; +import React from "react"; +import { defaulted, object, string, type Infer } from "superstruct"; +import { Button, Section, Text } from "../components/core"; +import Layout from "../components/layout"; + +export const TemplateName = "PasswordResetEmail"; + +export const TemplateStruct = object({ + magicLinkUrl: defaulted(string(), "https://peated.com/magic-link"), + baseUrl: defaulted(string(), "https://peated.com"), +}); +export type TemplateProps = Infer; + +export const Template = ({ magicLinkUrl, baseUrl }: TemplateProps) => { + const previewText = `Login to your Peated account.`; + + return ( + + {previewText} + +
+ A link was requested to log in to your account on Peated. +
+ +
+ +
+ +
+ + If you don't recognize this action, you should ignore this email. + +
+
+ ); +}; diff --git a/packages/email/src/templates/newCommentEmail.tsx b/packages/email/src/templates/newCommentEmail.tsx index a17fc321e..a45d5b020 100644 --- a/packages/email/src/templates/newCommentEmail.tsx +++ b/packages/email/src/templates/newCommentEmail.tsx @@ -1,5 +1,4 @@ -import theme from "@peated/design"; -import { Column, Heading, Img, Preview, Row } from "jsx-email"; +import { Column, Img, Preview, Row } from "jsx-email"; import React from "react"; import { defaulted, @@ -9,7 +8,7 @@ import { string, type Infer, } from "superstruct"; -import { Button, Hr, Link, Section, Text } from "../components/core"; +import { Button, Heading, Hr, Link, Section, Text } from "../components/core"; import Layout from "../components/layout"; import ReasonFooter, { Reason } from "../components/reasonFooter"; @@ -82,15 +81,7 @@ export const Template = ({ comment, baseUrl }: TemplateProps) => { - + { {" "} commented on - + Date: Mon, 26 Aug 2024 15:51:50 -0700 Subject: [PATCH 02/13] Vitest 2.0 --- apps/server/package.json | 2 +- apps/server/tsconfig.json | 7 +- .../{vitest.config.ts => vitest.config.mts} | 20 +- pnpm-lock.yaml | 269 ++++++++---------- pnpm-workspace.yaml | 2 +- 5 files changed, 124 insertions(+), 176 deletions(-) rename apps/server/{vitest.config.ts => vitest.config.mts} (66%) diff --git a/apps/server/package.json b/apps/server/package.json index 15f5373d0..cacfc74e4 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -85,7 +85,7 @@ "axios-mock-adapter": "~1.22.0", "form-data-encoder": "^4.0.2", "formdata-node": "^6.0.3", - "vite-tsconfig-paths": "^4.3.2", + "vite-tsconfig-paths": "^5.0.1", "vitest": "catalog:" }, "volta": { diff --git a/apps/server/tsconfig.json b/apps/server/tsconfig.json index 66ac73a25..80853b135 100644 --- a/apps/server/tsconfig.json +++ b/apps/server/tsconfig.json @@ -1,15 +1,14 @@ { "extends": "@peated/tsconfig/base.json", "compilerOptions": { - "baseUrl": ".", "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json", "types": ["node", "vitest/globals", "./src/global.d.ts"], "moduleResolution": "Node", "composite": true, "paths": { - "@peated/server/*": ["src/*"] + "@peated/server/*": ["./src/*"] } }, - "include": ["src"], - "exclude": ["src/test/setup-test-env.ts", "node_modules"] + "include": ["./src"], + "exclude": ["./src/test/setup-test-env.ts", "node_modules"] } diff --git a/apps/server/vitest.config.ts b/apps/server/vitest.config.mts similarity index 66% rename from apps/server/vitest.config.ts rename to apps/server/vitest.config.mts index c67443621..136d90ae2 100644 --- a/apps/server/vitest.config.ts +++ b/apps/server/vitest.config.mts @@ -5,30 +5,22 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ plugins: [tsconfigPaths()], + server: { + watch: { + ignored: ["/node_modules/", "/dist/", "/postgres-data/"], + }, + }, test: { coverage: { provider: "v8", reporter: ["json"], }, maxConcurrency: 0, - pool: "forks", - poolOptions: { - forks: { - singleFork: true, - }, - threads: { - singleThread: true, - }, - }, fileParallelism: false, globals: true, setupFiles: ["./src/test/setup-test-env.ts"], include: ["./src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], - watchExclude: [ - ".*\\/node_modules\\/.*", - ".*\\/dist\\/.*", - ".*\\/postgres-data\\/.*", - ], + restoreMocks: true, }, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 274f4ad15..e5f61d9b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -103,8 +103,8 @@ catalogs: specifier: ^5.5.4 version: 5.5.4 vitest: - specifier: ~1.4.0 - version: 1.4.0 + specifier: ~2.0.5 + version: 2.0.5 zod: specifier: ^3.23.8 version: 3.23.8 @@ -435,7 +435,7 @@ importers: version: 18.3.3 '@vitest/coverage-v8': specifier: ^1.6.0 - version: 1.6.0(vitest@1.4.0(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6)) + version: 1.6.0(vitest@2.0.5(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6)) ai: specifier: ^3.2.19 version: 3.2.19(openai@4.52.2)(react@18.3.1)(svelte@4.2.18)(vue@3.4.31(typescript@5.5.4))(zod@3.23.8) @@ -549,11 +549,11 @@ importers: specifier: ^6.0.3 version: 6.0.3 vite-tsconfig-paths: - specifier: ^4.3.2 - version: 4.3.2(typescript@5.5.4)(vite@4.5.3(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6)) + specifier: ^5.0.1 + version: 5.0.1(typescript@5.5.4)(vite@4.5.3(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6)) vitest: specifier: 'catalog:' - version: 1.4.0(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6) + version: 2.0.5(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6) apps/web: dependencies: @@ -658,7 +658,7 @@ importers: version: 4.2.1(leaflet@1.9.4)(react-dom@18.2.0(react@18.3.1))(react@18.3.1) react-qr-code: specifier: ^2.0.14 - version: 2.0.14(react-native-svg@15.4.0(react@18.3.1))(react@18.3.1) + version: 2.0.14(react-native-svg@15.4.0(react-native@0.74.3(@babel/core@7.24.9)(@babel/preset-env@7.24.7(@babel/core@7.24.9))(@types/react@18.3.3)(react@18.3.1))(react@18.3.1))(react@18.3.1) recharts: specifier: ^2.12.7 version: 2.12.7(react-dom@18.2.0(react@18.3.1))(react@18.3.1) @@ -4543,20 +4543,23 @@ packages: peerDependencies: vitest: 1.6.0 - '@vitest/expect@1.4.0': - resolution: {integrity: sha512-Jths0sWCJZ8BxjKe+p+eKsoqev1/T8lYcrjavEaz8auEJ4jAVY0GwW3JKmdVU4mmNPLPHixh4GNXP7GFtAiDHA==} + '@vitest/expect@2.0.5': + resolution: {integrity: sha512-yHZtwuP7JZivj65Gxoi8upUN2OzHTi3zVfjwdpu2WrvCZPLwsJ2Ey5ILIPccoW23dd/zQBlJ4/dhi7DWNyXCpA==} - '@vitest/runner@1.4.0': - resolution: {integrity: sha512-EDYVSmesqlQ4RD2VvWo3hQgTJ7ZrFQ2VSJdfiJiArkCerDAGeyF1i6dHkmySqk573jLp6d/cfqCN+7wUB5tLgg==} + '@vitest/pretty-format@2.0.5': + resolution: {integrity: sha512-h8k+1oWHfwTkyTkb9egzwNMfJAEx4veaPSnMeKbVSjp4euqGSbQlm5+6VHwTr7u4FJslVVsUG5nopCaAYdOmSQ==} - '@vitest/snapshot@1.4.0': - resolution: {integrity: sha512-saAFnt5pPIA5qDGxOHxJ/XxhMFKkUSBJmVt5VgDsAqPTX6JP326r5C/c9UuCMPoXNzuudTPsYDZCoJ5ilpqG2A==} + '@vitest/runner@2.0.5': + resolution: {integrity: sha512-TfRfZa6Bkk9ky4tW0z20WKXFEwwvWhRY+84CnSEtq4+3ZvDlJyY32oNTJtM7AW9ihW90tX/1Q78cb6FjoAs+ig==} - '@vitest/spy@1.4.0': - resolution: {integrity: sha512-Ywau/Qs1DzM/8Uc+yA77CwSegizMlcgTJuYGAi0jujOteJOUf1ujunHThYo243KG9nAyWT3L9ifPYZ5+As/+6Q==} + '@vitest/snapshot@2.0.5': + resolution: {integrity: sha512-SgCPUeDFLaM0mIUHfaArq8fD2WbaXG/zVXjRupthYfYGzc8ztbFbu6dUNOblBG7XLMR1kEhS/DNnfCZ2IhdDew==} - '@vitest/utils@1.4.0': - resolution: {integrity: sha512-mx3Yd1/6e2Vt/PUC98DcqTirtfxUyAZ32uK82r8rZzbtBeBo+nqgnjx/LvqQdWsrvNtm14VmurNgcf4nqY5gJg==} + '@vitest/spy@2.0.5': + resolution: {integrity: sha512-c/jdthAhvJdpfVuaexSrnawxZz6pywlTPe84LUB2m/4t3rl2fTo9NFGBG4oWgaD+FTgDDV8hJ/nibT7IfH3JfA==} + + '@vitest/utils@2.0.5': + resolution: {integrity: sha512-d8HKbqIcya+GR67mkZbrzhS5kKhtp8dQLcmRZLGTscGVg7yImT82cIrhtn2L8+VujWcy6KZweApgNmPsTAO/UQ==} '@vue/compiler-core@3.4.31': resolution: {integrity: sha512-skOiodXWTV3DxfDhB4rOf3OGalpITLlgCeOwb+Y9GJpfQ8ErigdBUHomBzvG78JoVE8MJoQsb+qhZiHfKeNeEg==} @@ -4908,8 +4911,9 @@ packages: assert@2.1.0: resolution: {integrity: sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==} - assertion-error@1.1.0: - resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} + assertion-error@2.0.1: + resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} + engines: {node: '>=12'} ast-types-flow@0.0.8: resolution: {integrity: sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==} @@ -5254,9 +5258,9 @@ packages: ccount@2.0.1: resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==} - chai@4.4.1: - resolution: {integrity: sha512-13sOfMv2+DWduEU+/xbun3LScLoqN17nBeTLUsmDfKdoiC1fr0n9PU4guu4AhRcOVFk/sW8LyZWHuhWtQZiF+g==} - engines: {node: '>=4'} + chai@5.1.1: + resolution: {integrity: sha512-pT1ZgP8rPNqUgieVaEY+ryQr6Q4HXNg8Ei9UnLUrjN4IA7dvQC5JB+/kxVcPNDHyBcc/26CXPkbNzq3qwrOEKA==} + engines: {node: '>=12'} chalk@2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} @@ -5291,8 +5295,9 @@ packages: charenc@0.0.2: resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==} - check-error@1.0.3: - resolution: {integrity: sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==} + check-error@2.1.1: + resolution: {integrity: sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==} + engines: {node: '>= 16'} cheerio-select@2.1.0: resolution: {integrity: sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==} @@ -5508,9 +5513,6 @@ packages: resolution: {integrity: sha512-P7X+QL9Hb9B/c8HI5BFFKmjgBu2XpQuF98WZ9XkO+dBGgk5XgwiQz7o1SmpglNWId3581UcS0SFAWfoIhMHPfg==} engines: {node: '>=0.10.0'} - confbox@0.1.7: - resolution: {integrity: sha512-uJcB/FKZtBMCJpK8MQji6bJHgu1tixKPxRLeGkNzBoOZzpnZUJm0jm2/sBDWcuBx1dYgxV4JU+g5hmNxCyAmdA==} - config-chain@1.1.13: resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==} @@ -5822,8 +5824,8 @@ packages: babel-plugin-macros: optional: true - deep-eql@4.1.4: - resolution: {integrity: sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==} + deep-eql@5.0.2: + resolution: {integrity: sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==} engines: {node: '>=6'} deep-extend@0.6.0: @@ -8026,10 +8028,6 @@ packages: resolution: {integrity: sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==} engines: {node: '>=6.11.5'} - local-pkg@0.5.0: - resolution: {integrity: sha512-ok6z3qlYyCDS4ZEU27HaU6x/xZa9Whf8jD4ptH5UZTQYZVYeb9bnZ3ojVhiJNLiXK1Hfc0GNbLXcmZ5plLDDBg==} - engines: {node: '>=14'} - localforage@1.10.0: resolution: {integrity: sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==} @@ -8117,8 +8115,8 @@ packages: resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} hasBin: true - loupe@2.3.7: - resolution: {integrity: sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==} + loupe@3.1.1: + resolution: {integrity: sha512-edNu/8D5MKVfGVFRhFf8aAxiTM6Wumfz5XsaatSxlD3w4R1d/WEKUTydCdPGbl9K7QG/Ca3GnDV2sIKIpXRQcw==} lower-case@2.0.2: resolution: {integrity: sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==} @@ -8448,9 +8446,6 @@ packages: engines: {node: '>=10'} hasBin: true - mlly@1.7.1: - resolution: {integrity: sha512-rrVRZRELyQzrIUAVMHxP97kv+G786pHmOKzuFII8zDYahFBS7qnHh2AlYSl1GAHhaMPCz6/oHjVMcfFYgFYHgA==} - mnemonist@0.39.6: resolution: {integrity: sha512-A/0v5Z59y63US00cRSLiloEIw3t5G+MiKz4BhX21FI+YBJXBOGW0ohFxTxO08dsOYlzxo87T7vGfZKYp2bcAWA==} @@ -8810,10 +8805,6 @@ packages: resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} engines: {node: '>=10'} - p-limit@5.0.0: - resolution: {integrity: sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==} - engines: {node: '>=18'} - p-locate@3.0.0: resolution: {integrity: sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==} engines: {node: '>=6'} @@ -8932,8 +8923,9 @@ packages: pathe@1.1.2: resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==} - pathval@1.1.1: - resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} + pathval@2.0.0: + resolution: {integrity: sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==} + engines: {node: '>= 14.16'} pbkdf2@3.1.2: resolution: {integrity: sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==} @@ -9044,9 +9036,6 @@ packages: resolution: {integrity: sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==} engines: {node: '>=10'} - pkg-types@1.1.1: - resolution: {integrity: sha512-ko14TjmDuQJ14zsotODv7dBlwxKhUKQEhuhmbqo1uCi9BB0Z2alo/wAXg6q1dTR5TyuqYyWhjtfe/Tsh+X28jQ==} - plist@3.1.0: resolution: {integrity: sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==} engines: {node: '>=10.4.0'} @@ -10541,12 +10530,16 @@ packages: tinybench@2.8.0: resolution: {integrity: sha512-1/eK7zUnIklz4JUUlL+658n58XO2hHLQfSk1Zf2LKieUjxidN16eKFEoDEfjHc3ohofSSqK3X5yO6VGb6iW8Lw==} - tinypool@0.8.4: - resolution: {integrity: sha512-i11VH5gS6IFeLY3gMBQ00/MmLncVP7JLXOw1vlgkytLmJK7QnEr7NXf0LBdxfmNPAeyetukOk0bOYrJrFGjYJQ==} + tinypool@1.0.1: + resolution: {integrity: sha512-URZYihUbRPcGv95En+sz6MfghfIc2OJ1sv/RmhWZLouPY0/8Vo80viwPvg3dlaS9fuq7fQMEfgRRK7BBZThBEA==} + engines: {node: ^18.0.0 || >=20.0.0} + + tinyrainbow@1.2.0: + resolution: {integrity: sha512-weEDEq7Z5eTHPDh4xjX789+fHfF+P8boiFB+0vbWzpbnbsEr/GRaohi/uMKxg8RZMXnl1ItAi/IUHWMsjDV7kQ==} engines: {node: '>=14.0.0'} - tinyspy@2.2.1: - resolution: {integrity: sha512-KYad6Vy5VDWV4GH3fjpseMQ/XU2BhIYP7Vzd0LG44qRWm/Yt2WCOTicFdvmgo6gWaqooMQCawTtILVQJupKu7A==} + tinyspy@3.0.0: + resolution: {integrity: sha512-q5nmENpTHgiPVd1cJDDc9cVoYN5x4vCvwT3FMilvKPKneCBZAxn2YWQjDF0UMcE9k0Cay1gBiDfTMU0g+mPMQA==} engines: {node: '>=14.0.0'} titleize@4.0.0: @@ -10774,9 +10767,6 @@ packages: ua-parser-js@1.0.38: resolution: {integrity: sha512-Aq5ppTOfvrCMgAPneW1HfWj66Xi7XL+/mIy996R1/CLS/rcyJQm6QZdsKrUeivDFQ+Oc9Wyuwor8Ze8peEoUoQ==} - ufo@1.5.3: - resolution: {integrity: sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==} - unbox-primitive@1.0.2: resolution: {integrity: sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==} @@ -10978,8 +10968,8 @@ packages: victory-vendor@36.9.2: resolution: {integrity: sha512-PnpQQMuxlwYdocC8fIJqVXvkeViHYzotI+NJrCuav0ZYFoq912ZHBk3mCeuj+5/VpodOjPe1z0Fk2ihgzlXqjQ==} - vite-node@1.4.0: - resolution: {integrity: sha512-VZDAseqjrHgNd4Kh8icYHWzTKSCZMhia7GyHfhtzLW33fZlG9SwsB6CEhgyVOWkJfJ2pFLrp/Gj1FSfAiqH9Lw==} + vite-node@2.0.5: + resolution: {integrity: sha512-LdsW4pxj0Ot69FAoXZ1yTnA9bjGohr2yNBU7QKRxpz8ITSkhuDl6h3zS/tvgz4qrNjeRnvrWeXQ8ZF7Um4W00Q==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true @@ -10988,8 +10978,8 @@ packages: peerDependencies: vite: ^2.0.0 || ^3.0.0 || ^4.0.0 - vite-tsconfig-paths@4.3.2: - resolution: {integrity: sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA==} + vite-tsconfig-paths@5.0.1: + resolution: {integrity: sha512-yqwv+LstU7NwPeNqajZzLEBVpUFU6Dugtb2P84FXuvaoYA+/70l9MHE+GYfYAycVyPSDYZ7mjOFuYBRqlEpTig==} peerDependencies: vite: '*' peerDependenciesMeta: @@ -11052,15 +11042,15 @@ packages: terser: optional: true - vitest@1.4.0: - resolution: {integrity: sha512-gujzn0g7fmwf83/WzrDTnncZt2UiXP41mHuFYFrdwaLRVQ6JYQEiME2IfEjU3vcFL3VKa75XhI3lFgn+hfVsQw==} + vitest@2.0.5: + resolution: {integrity: sha512-8GUxONfauuIdeSl5f9GTgVEpg5BTOlplET4WEDaeY2QBiN8wSm68vxN/tb5z405OwppfoCavnwXafiaYBC/xOA==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: '@edge-runtime/vm': '*' '@types/node': ^18.0.0 || >=20.0.0 - '@vitest/browser': 1.4.0 - '@vitest/ui': 1.4.0 + '@vitest/browser': 2.0.5 + '@vitest/ui': 2.0.5 happy-dom: '*' jsdom: '*' peerDependenciesMeta: @@ -11218,8 +11208,8 @@ packages: engines: {node: '>= 8'} hasBin: true - why-is-node-running@2.2.2: - resolution: {integrity: sha512-6tSwToZxTOcotxHeA+qGCq1mVzKR3CwcJGmVcY+QE8SHy6TnpFnh8PAvPNHYr7EcuVeG0QSMxtYCuO1ta/G/oA==} + why-is-node-running@2.3.0: + resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==} engines: {node: '>=8'} hasBin: true @@ -11374,10 +11364,6 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} - yocto-queue@1.1.1: - resolution: {integrity: sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==} - engines: {node: '>=12.20'} - zod-to-json-schema@3.22.5: resolution: {integrity: sha512-+akaPo6a0zpVCCseDed504KBJUQpEW5QZw7RMneNmKw+fGaML1Z9tUNLnHHAC8x6dzVRO1eB2oEMyZRnuBZg7Q==} peerDependencies: @@ -14920,7 +14906,7 @@ snapshots: dependencies: '@rollup/pluginutils': 5.1.0(rollup@4.18.0) estree-walker: 2.0.2 - magic-string: 0.30.10 + magic-string: 0.30.11 optionalDependencies: rollup: 4.18.0 @@ -15977,7 +15963,7 @@ snapshots: '@unocss/rule-utils@0.58.9': dependencies: '@unocss/core': 0.58.9 - magic-string: 0.30.10 + magic-string: 0.30.11 '@unocss/transformer-compile-class@0.58.9': dependencies: @@ -16021,7 +16007,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@vitest/coverage-v8@1.6.0(vitest@1.4.0(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6))': + '@vitest/coverage-v8@1.6.0(vitest@2.0.5(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 @@ -16036,38 +16022,42 @@ snapshots: std-env: 3.7.0 strip-literal: 2.1.0 test-exclude: 6.0.0 - vitest: 1.4.0(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6) + vitest: 2.0.5(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6) transitivePeerDependencies: - supports-color - '@vitest/expect@1.4.0': + '@vitest/expect@2.0.5': + dependencies: + '@vitest/spy': 2.0.5 + '@vitest/utils': 2.0.5 + chai: 5.1.1 + tinyrainbow: 1.2.0 + + '@vitest/pretty-format@2.0.5': dependencies: - '@vitest/spy': 1.4.0 - '@vitest/utils': 1.4.0 - chai: 4.4.1 + tinyrainbow: 1.2.0 - '@vitest/runner@1.4.0': + '@vitest/runner@2.0.5': dependencies: - '@vitest/utils': 1.4.0 - p-limit: 5.0.0 + '@vitest/utils': 2.0.5 pathe: 1.1.2 - '@vitest/snapshot@1.4.0': + '@vitest/snapshot@2.0.5': dependencies: - magic-string: 0.30.10 + '@vitest/pretty-format': 2.0.5 + magic-string: 0.30.11 pathe: 1.1.2 - pretty-format: 29.7.0 - '@vitest/spy@1.4.0': + '@vitest/spy@2.0.5': dependencies: - tinyspy: 2.2.1 + tinyspy: 3.0.0 - '@vitest/utils@1.4.0': + '@vitest/utils@2.0.5': dependencies: - diff-sequences: 29.6.3 + '@vitest/pretty-format': 2.0.5 estree-walker: 3.0.3 - loupe: 2.3.7 - pretty-format: 29.7.0 + loupe: 3.1.1 + tinyrainbow: 1.2.0 '@vue/compiler-core@3.4.31': dependencies: @@ -16497,7 +16487,7 @@ snapshots: object.assign: 4.1.5 util: 0.12.5 - assertion-error@1.1.0: {} + assertion-error@2.0.1: {} ast-types-flow@0.0.8: {} @@ -16959,15 +16949,13 @@ snapshots: ccount@2.0.1: {} - chai@4.4.1: + chai@5.1.1: dependencies: - assertion-error: 1.1.0 - check-error: 1.0.3 - deep-eql: 4.1.4 - get-func-name: 2.0.2 - loupe: 2.3.7 - pathval: 1.1.1 - type-detect: 4.0.8 + assertion-error: 2.0.1 + check-error: 2.1.1 + deep-eql: 5.0.2 + loupe: 3.1.1 + pathval: 2.0.0 chalk@2.4.2: dependencies: @@ -16997,9 +16985,7 @@ snapshots: charenc@0.0.2: {} - check-error@1.0.3: - dependencies: - get-func-name: 2.0.2 + check-error@2.1.1: {} cheerio-select@2.1.0: dependencies: @@ -17223,8 +17209,6 @@ snapshots: is-whitespace: 0.3.0 kind-of: 3.2.2 - confbox@0.1.7: {} - config-chain@1.1.13: dependencies: ini: 1.3.8 @@ -17538,9 +17522,7 @@ snapshots: dedent@1.5.3: {} - deep-eql@4.1.4: - dependencies: - type-detect: 4.0.8 + deep-eql@5.0.2: {} deep-extend@0.6.0: {} @@ -20522,11 +20504,6 @@ snapshots: loader-runner@4.3.0: {} - local-pkg@0.5.0: - dependencies: - mlly: 1.7.1 - pkg-types: 1.1.1 - localforage@1.10.0: dependencies: lie: 3.1.1 @@ -20605,7 +20582,7 @@ snapshots: dependencies: js-tokens: 4.0.0 - loupe@2.3.7: + loupe@3.1.1: dependencies: get-func-name: 2.0.2 @@ -21018,13 +20995,6 @@ snapshots: mkdirp@1.0.4: {} - mlly@1.7.1: - dependencies: - acorn: 8.12.1 - pathe: 1.1.2 - pkg-types: 1.1.1 - ufo: 1.5.3 - mnemonist@0.39.6: dependencies: obliterator: 2.0.4 @@ -21428,10 +21398,6 @@ snapshots: dependencies: yocto-queue: 0.1.0 - p-limit@5.0.0: - dependencies: - yocto-queue: 1.1.1 - p-locate@3.0.0: dependencies: p-limit: 2.3.0 @@ -21544,7 +21510,7 @@ snapshots: pathe@1.1.2: {} - pathval@1.1.1: {} + pathval@2.0.0: {} pbkdf2@3.1.2: dependencies: @@ -21680,12 +21646,6 @@ snapshots: dependencies: find-up: 5.0.0 - pkg-types@1.1.1: - dependencies: - confbox: 0.1.7 - mlly: 1.7.1 - pathe: 1.1.2 - plist@3.1.0: dependencies: '@xmldom/xmldom': 0.8.10 @@ -22170,7 +22130,7 @@ snapshots: - supports-color - utf-8-validate - react-qr-code@2.0.14(react-native-svg@15.4.0(react@18.3.1))(react@18.3.1): + react-qr-code@2.0.14(react-native-svg@15.4.0(react-native@0.74.3(@babel/core@7.24.9)(@babel/preset-env@7.24.7(@babel/core@7.24.9))(@types/react@18.3.3)(react@18.3.1))(react@18.3.1))(react@18.3.1): dependencies: prop-types: 15.8.1 qr.js: 0.0.0 @@ -23444,9 +23404,11 @@ snapshots: tinybench@2.8.0: {} - tinypool@0.8.4: {} + tinypool@1.0.1: {} - tinyspy@2.2.1: {} + tinyrainbow@1.2.0: {} + + tinyspy@3.0.0: {} titleize@4.0.0: {} @@ -23673,8 +23635,6 @@ snapshots: ua-parser-js@1.0.38: {} - ufo@1.5.3: {} - unbox-primitive@1.0.2: dependencies: call-bind: 1.0.7 @@ -23897,12 +23857,12 @@ snapshots: d3-time: 3.1.0 d3-timer: 3.0.1 - vite-node@1.4.0(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6): + vite-node@2.0.5(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6): dependencies: cac: 6.7.14 debug: 4.3.5 pathe: 1.1.2 - picocolors: 1.0.1 + tinyrainbow: 1.2.0 vite: 5.3.2(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6) transitivePeerDependencies: - '@types/node' @@ -23934,7 +23894,7 @@ snapshots: transitivePeerDependencies: - rollup - vite-tsconfig-paths@4.3.2(typescript@5.5.4)(vite@4.5.3(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6)): + vite-tsconfig-paths@5.0.1(typescript@5.5.4)(vite@4.5.3(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6)): dependencies: debug: 4.3.5 globrex: 0.1.2 @@ -23970,7 +23930,7 @@ snapshots: vite@5.3.2(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6): dependencies: esbuild: 0.21.5 - postcss: 8.4.40 + postcss: 8.4.41 rollup: 4.18.0 optionalDependencies: '@types/node': 20.14.12 @@ -23978,28 +23938,27 @@ snapshots: lightningcss: 1.22.0 terser: 5.31.6 - vitest@1.4.0(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6): + vitest@2.0.5(@types/node@20.14.12)(jsdom@24.1.0)(lightningcss@1.22.0)(terser@5.31.6): dependencies: - '@vitest/expect': 1.4.0 - '@vitest/runner': 1.4.0 - '@vitest/snapshot': 1.4.0 - '@vitest/spy': 1.4.0 - '@vitest/utils': 1.4.0 - acorn-walk: 8.3.3 - chai: 4.4.1 + '@ampproject/remapping': 2.3.0 + '@vitest/expect': 2.0.5 + '@vitest/pretty-format': 2.0.5 + '@vitest/runner': 2.0.5 + '@vitest/snapshot': 2.0.5 + '@vitest/spy': 2.0.5 + '@vitest/utils': 2.0.5 + chai: 5.1.1 debug: 4.3.5 execa: 8.0.1 - local-pkg: 0.5.0 - magic-string: 0.30.10 + magic-string: 0.30.11 pathe: 1.1.2 - picocolors: 1.0.1 std-env: 3.7.0 - strip-literal: 2.1.0 tinybench: 2.8.0 - tinypool: 0.8.4 + tinypool: 1.0.1 + tinyrainbow: 1.2.0 vite: 5.3.2(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6) - vite-node: 1.4.0(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6) - why-is-node-running: 2.2.2 + vite-node: 2.0.5(@types/node@20.14.12)(lightningcss@1.22.0)(terser@5.31.6) + why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 20.14.12 jsdom: 24.1.0 @@ -24187,7 +24146,7 @@ snapshots: dependencies: isexe: 2.0.0 - why-is-node-running@2.2.2: + why-is-node-running@2.3.0: dependencies: siginfo: 2.0.0 stackback: 0.0.2 @@ -24315,8 +24274,6 @@ snapshots: yocto-queue@0.1.0: {} - yocto-queue@1.1.1: {} - zod-to-json-schema@3.22.5(zod@3.23.8): dependencies: zod: 3.23.8 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 719499eaf..0af0e4252 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -31,7 +31,7 @@ catalog: typescript: ^5.5.4 "@types/node": ^20.14.9 "@types/pg": ^8.11.6 - vitest: "~1.4.0" + vitest: "~2.0.5" zod: ^3.23.8 react: ^18.2.0 From 13072cd55bd88421a61b83a274a563841f264699 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 30 Sep 2024 18:10:49 -0700 Subject: [PATCH 03/13] Fix tests --- apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts b/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts index c575a0540..532e052b9 100644 --- a/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts +++ b/apps/server/src/trpc/routes/authMagicLinkConfirm.test.ts @@ -5,7 +5,7 @@ import { createCaller } from "../router"; // Mock the auth functions vi.mock("@peated/server/lib/auth", () => ({ - createAccessToken: vi.fn().mockResolvedValue("mocked-access-token"), + createAccessToken: vi.fn(), verifyPayload: vi.fn(), })); @@ -25,6 +25,8 @@ describe("authMagicLinkConfirm", () => { createdAt: new Date().toISOString(), }); + vi.mocked(createAccessToken).mockResolvedValue("mocked-access-token"); + const result = await caller.authMagicLinkConfirm({ token }); expect(result.user.id).toBe(user.id); From 8d91d3091054581bc4999c02a2c6d59364761bf9 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 30 Sep 2024 18:20:23 -0700 Subject: [PATCH 04/13] Fix html --- apps/web/src/components/loginForm.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/loginForm.tsx b/apps/web/src/components/loginForm.tsx index af2e5df8a..e74f726e8 100644 --- a/apps/web/src/components/loginForm.tsx +++ b/apps/web/src/components/loginForm.tsx @@ -78,7 +78,7 @@ export default function LoginForm() { -

+

Don't have an account yet?{" "} @@ -91,7 +91,7 @@ export default function LoginForm() { Password Reset
-

+
); } From ead2617b0fb735c305229cec9110bb276a35715b Mon Sep 17 00:00:00 2001 From: David Cramer Date: Mon, 30 Sep 2024 18:31:13 -0700 Subject: [PATCH 05/13] I hate server actions this is gross --- apps/web/src/components/loginForm.tsx | 77 +++++++++++++++------------ apps/web/src/lib/auth.actions.ts | 23 +++++++- 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/apps/web/src/components/loginForm.tsx b/apps/web/src/components/loginForm.tsx index e74f726e8..f5f5b8e7f 100644 --- a/apps/web/src/components/loginForm.tsx +++ b/apps/web/src/components/loginForm.tsx @@ -37,13 +37,12 @@ function FormComponent() { label="Password" type="password" autoComplete="current-password" - required - placeholder="************" + helpText="Enter your password, or alternatively continue without and we'll email you a magic link." />
@@ -51,47 +50,57 @@ function FormComponent() { } export default function LoginForm() { - const [error, formAction] = useFormState(authenticateForm, undefined); + const [result, formAction] = useFormState(authenticateForm, undefined); return (
- {error ? {error} : null} + {result?.error ? {result.error} : null} - {config.GOOGLE_CLIENT_ID && ( + {result?.magicLink ? ( +

+ Please check your email address to continue logging in. +

+ ) : ( <> - -
-