From ffafcbdb435e4185a39887113296954838143359 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:43:15 +0700 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Bump=20vitest=20from=202.1?= =?UTF-8?q?.1=20to=202.1.9=20(#1548)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dependabot[bot] Co-authored-by: Luke Vella Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- apps/web/.env.test | 2 +- apps/web/declarations/next-auth.d.ts | 1 + apps/web/i18next-scanner.config.js | 2 +- apps/web/package.json | 6 +- apps/web/public/locales/en/app.json | 7 +- .../profile/delete-account-dialog.tsx | 2 +- .../auth/login/components/login-page.tsx | 16 +- .../src/app/[locale]/(auth)/login/actions.ts | 22 +- .../login/components/login-email-form.tsx | 8 +- .../login/components/login-with-oidc.tsx | 6 +- .../(auth)/login/components/sso-provider.tsx | 8 +- .../src/app/[locale]/(auth)/login/page.tsx | 38 +- .../login/verify/components/otp-form.tsx | 2 +- .../register/verify/components/otp-form.tsx | 2 +- apps/web/src/app/[locale]/layout.tsx | 4 +- .../src/app/api/auth/[...nextauth]/route.ts | 6 + .../api/notifications/unsubscribe/route.ts | 4 +- apps/web/src/app/api/stripe/checkout/route.ts | 4 +- apps/web/src/app/api/stripe/portal/route.ts | 4 +- apps/web/src/app/api/trpc/[trpc]/route.ts | 4 +- .../app/api/user/verify-email-change/route.ts | 6 +- apps/web/src/auth.ts | 371 ------------------ .../prisma.ts} | 21 +- apps/web/src/auth/get-optional-providers.ts | 11 + apps/web/src/auth/is-email-blocked.ts | 19 + apps/web/src/auth/providers/email.ts | 41 ++ apps/web/src/auth/providers/google.ts | 11 + apps/web/src/auth/providers/guest.ts | 14 + apps/web/src/auth/providers/microsoft.ts | 17 + apps/web/src/auth/providers/oidc.ts | 34 ++ .../src/auth/providers/registration-token.ts | 47 +++ apps/web/src/components/login-link.tsx | 2 +- .../src/components/poll/language-selector.tsx | 2 +- apps/web/src/components/register-link.tsx | 2 +- .../quick-create/lib/get-guest-polls.ts | 4 +- apps/web/src/middleware.ts | 108 ++--- apps/web/src/next-auth.config.ts | 50 +++ apps/web/src/next-auth.ts | 169 ++++++++ apps/web/src/pages/api/auth/[...nextauth].ts | 14 - apps/web/src/trpc/routers/auth.ts | 2 +- apps/web/src/trpc/server/create-ssr-helper.ts | 4 +- apps/web/tests/create-delete-poll.spec.ts | 2 +- package.json | 5 +- packages/posthog/src/server/index.ts | 8 + packages/utils/package.json | 2 +- yarn.lock | 357 ++++++++--------- 46 files changed, 731 insertions(+), 740 deletions(-) create mode 100644 apps/web/src/app/api/auth/[...nextauth]/route.ts delete mode 100644 apps/web/src/auth.ts rename apps/web/src/auth/{custom-prisma-adapter.ts => adapters/prisma.ts} (69%) create mode 100644 apps/web/src/auth/get-optional-providers.ts create mode 100644 apps/web/src/auth/is-email-blocked.ts create mode 100644 apps/web/src/auth/providers/email.ts create mode 100644 apps/web/src/auth/providers/google.ts create mode 100644 apps/web/src/auth/providers/guest.ts create mode 100644 apps/web/src/auth/providers/microsoft.ts create mode 100644 apps/web/src/auth/providers/oidc.ts create mode 100644 apps/web/src/auth/providers/registration-token.ts create mode 100644 apps/web/src/next-auth.config.ts create mode 100644 apps/web/src/next-auth.ts delete mode 100644 apps/web/src/pages/api/auth/[...nextauth].ts diff --git a/apps/web/.env.test b/apps/web/.env.test index 10a8391217d..211b6be2742 100644 --- a/apps/web/.env.test +++ b/apps/web/.env.test @@ -4,6 +4,6 @@ NEXTAUTH_URL=$NEXT_PUBLIC_BASE_URL SECRET_PASSWORD=abcdef1234567890abcdef1234567890 DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly SUPPORT_EMAIL=support@rallly.co -SMTP_HOST=localhost +SMTP_HOST=0.0.0.0 SMTP_PORT=1025 QUICK_CREATE_ENABLED=true \ No newline at end of file diff --git a/apps/web/declarations/next-auth.d.ts b/apps/web/declarations/next-auth.d.ts index cfcdd3bfaee..9f5f276a164 100644 --- a/apps/web/declarations/next-auth.d.ts +++ b/apps/web/declarations/next-auth.d.ts @@ -20,6 +20,7 @@ declare module "next-auth" { } interface User extends DefaultUser { + id: string; locale?: string | null; timeZone?: string | null; timeFormat?: TimeFormat | null; diff --git a/apps/web/i18next-scanner.config.js b/apps/web/i18next-scanner.config.js index 04cb299b958..51accfa191c 100644 --- a/apps/web/i18next-scanner.config.js +++ b/apps/web/i18next-scanner.config.js @@ -1,7 +1,7 @@ const typescriptTransform = require("i18next-scanner-typescript"); module.exports = { - input: ["src/**/*.{ts,tsx}", "!src/auth.ts"], + input: ["src/**/*.{ts,tsx}", "!src/next-auth*.ts"], options: { nsSeparator: false, defaultNs: "app", diff --git a/apps/web/package.json b/apps/web/package.json index 8632f442eb6..67a292e2692 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -18,7 +18,7 @@ "docker:start": "./scripts/docker-start.sh" }, "dependencies": { - "@auth/prisma-adapter": "^1.0.3", + "@auth/prisma-adapter": "^2.7.4", "@aws-sdk/client-s3": "^3.645.0", "@aws-sdk/s3-request-presigner": "^3.645.0", "@hookform/resolvers": "^3.3.1", @@ -67,7 +67,7 @@ "lucide-react": "^0.387.0", "micro": "^10.0.1", "nanoid": "^5.0.9", - "next-auth": "^4.24.5", + "next-auth": "^5.0.0-beta.25", "next-i18next": "^13.0.3", "php-serialize": "^4.1.1", "postcss": "^8.4.31", @@ -95,7 +95,7 @@ "cross-env": "^7.0.3", "i18next-scanner": "^4.2.0", "i18next-scanner-typescript": "^1.1.1", - "vitest": "^2.1.1", + "vitest": "^2.1.9", "wait-on": "^6.0.1" } } diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json index 39c7aa7e146..262a80ef210 100644 --- a/apps/web/public/locales/en/app.json +++ b/apps/web/public/locales/en/app.json @@ -32,7 +32,6 @@ "emailNotAllowed": "This email is not allowed.", "emailPlaceholder": "jessie.smith@example.com", "exportToCsv": "Export to CSV", - "forgetMe": "Forget me", "guest": "Guest", "ifNeedBe": "If need be", "location": "Location", @@ -199,9 +198,6 @@ "pollStatusFinalized": "Finalized", "share": "Share", "noParticipants": "No participants", - "userId": "User ID", - "aboutGuest": "Guest User", - "aboutGuestDescription": "Profile settings are not available for guest users. <0>Sign in to your existing account or <1>create a new account to customize your profile.", "logoutDescription": "Sign out of your existing session", "events": "Events", "inviteParticipantsDescription": "Copy and share the invite link to start gathering responses from your participants.", @@ -305,5 +301,6 @@ "registerVerifyDescription": "Check your email for the verification code", "loginVerifyTitle": "Finish Logging In", "loginVerifyDescription": "Check your email for the verification code", - "createAccount": "Create Account" + "createAccount": "Create Account", + "loginMagicLinkError": "This link is invalid or expired. Please request a new link." } diff --git a/apps/web/src/app/[locale]/(admin)/settings/profile/delete-account-dialog.tsx b/apps/web/src/app/[locale]/(admin)/settings/profile/delete-account-dialog.tsx index b4503d09760..a291862414b 100644 --- a/apps/web/src/app/[locale]/(admin)/settings/profile/delete-account-dialog.tsx +++ b/apps/web/src/app/[locale]/(admin)/settings/profile/delete-account-dialog.tsx @@ -38,7 +38,7 @@ export function DeleteAccountDialog({ onSuccess() { posthog?.capture("delete account"); signOut({ - callbackUrl: "/login", + redirectTo: "/login", }); }, }); diff --git a/apps/web/src/app/[locale]/(auth)/auth/login/components/login-page.tsx b/apps/web/src/app/[locale]/(auth)/auth/login/components/login-page.tsx index 04ed2e88414..ecf276892f4 100644 --- a/apps/web/src/app/[locale]/(auth)/auth/login/components/login-page.tsx +++ b/apps/web/src/app/[locale]/(auth)/auth/login/components/login-page.tsx @@ -4,10 +4,12 @@ import { Button } from "@rallly/ui/button"; import { useMutation } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; import { useSession } from "next-auth/react"; +import React from "react"; import { OptimizedAvatarImage } from "@/components/optimized-avatar-image"; import { Skeleton } from "@/components/skeleton"; import { Trans } from "@/components/trans"; +import { useTranslation } from "@/i18n/client"; import { trpc } from "@/trpc/client"; type PageProps = { magicLink: string; email: string }; @@ -15,6 +17,9 @@ type PageProps = { magicLink: string; email: string }; export const LoginPage = ({ magicLink, email }: PageProps) => { const session = useSession(); const posthog = usePostHog(); + const { t } = useTranslation(); + const [error, setError] = React.useState(null); + const magicLinkFetch = useMutation({ mutationFn: async () => { const res = await fetch(magicLink); @@ -31,9 +36,15 @@ export const LoginPage = ({ magicLink, email }: PageProps) => { name: updatedSession.user.name, }); } + router.push(data.url); + } else { + setError( + t("loginMagicLinkError", { + defaultValue: + "This link is invalid or expired. Please request a new link.", + }), + ); } - - router.push(data.url); }, }); const { data } = trpc.user.getByEmail.useQuery({ email }); @@ -72,6 +83,7 @@ export const LoginPage = ({ magicLink, email }: PageProps) => { + {error &&

{error}

} ); diff --git a/apps/web/src/app/[locale]/(auth)/login/actions.ts b/apps/web/src/app/[locale]/(auth)/login/actions.ts index b7b7281d254..86f18197e6f 100644 --- a/apps/web/src/app/[locale]/(auth)/login/actions.ts +++ b/apps/web/src/app/[locale]/(auth)/login/actions.ts @@ -4,18 +4,24 @@ import { prisma } from "@rallly/database"; import { cookies } from "next/headers"; export async function setVerificationEmail(email: string) { - const count = await prisma.user.count({ + const user = await prisma.user.findUnique({ where: { email, }, + select: { + email: true, + }, }); - cookies().set("verification-email", email, { - httpOnly: true, - secure: process.env.NODE_ENV === "production", - sameSite: "lax", - maxAge: 15 * 60, - }); + if (user) { + cookies().set("verification-email", user.email, { + httpOnly: true, + secure: process.env.NODE_ENV === "production", + sameSite: "lax", + maxAge: 15 * 60, + }); + return true; + } - return count > 0; + return false; } diff --git a/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx b/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx index b0e4e9de238..5c8a2692058 100644 --- a/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx +++ b/apps/web/src/app/[locale]/(auth)/login/components/login-email-form.tsx @@ -53,13 +53,13 @@ export function LoginWithEmailForm() { if (doesExist) { await signIn("email", { email: identifier, - callbackUrl: searchParams?.get("callbackUrl") ?? undefined, + redirectTo: searchParams?.get("redirectTo") ?? undefined, redirect: false, }); - // redirect to verify page with callbackUrl + // redirect to verify page with redirectTo router.push( - `/login/verify?callbackUrl=${encodeURIComponent( - searchParams?.get("callbackUrl") ?? "", + `/login/verify?redirectTo=${encodeURIComponent( + searchParams?.get("redirectTo") ?? "", )}`, ); } else { diff --git a/apps/web/src/app/[locale]/(auth)/login/components/login-with-oidc.tsx b/apps/web/src/app/[locale]/(auth)/login/components/login-with-oidc.tsx index 67f9bd237f5..ebe251b2831 100644 --- a/apps/web/src/app/[locale]/(auth)/login/components/login-with-oidc.tsx +++ b/apps/web/src/app/[locale]/(auth)/login/components/login-with-oidc.tsx @@ -6,16 +6,16 @@ import { Trans } from "@/components/trans"; export async function LoginWithOIDC({ name, - callbackUrl, + redirectTo, }: { name: string; - callbackUrl?: string; + redirectTo?: string; }) { return (