Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🔥 Remove dead code/templates (#1981)

Luke Vella1b40ee1cda61
diff --git a/apps/web/package.json b/apps/web/package.json
index 0ddb41411..aa03535fb 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -27,7 +27,6 @@
"@hono/zod-validator": "^0.7.2",
"@hookform/resolvers": "^5.2.1",
"@next/env": "^15.3.1",
- "@panva/hkdf": "^1.2.1",
"@prisma/client": "^6.8.2",
"@radix-ui/react-radio-group": "^1.2.3",
"@radix-ui/react-select": "^2.2.2",
@@ -75,7 +74,6 @@
"ics": "^3.1.0",
"intl-messageformat": "^10.7.15",
"iron-session": "^6.3.1",
- "jose": "^5.9.6",
"js-cookie": "^3.0.1",
"linkify-react": "^4.1.3",
"linkifyjs": "^4.1.3",
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 3564371a9..f24c86147 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -154,7 +154,6 @@
"requireParticipantEmailLabel": "Make email address required for participants",
"hideParticipantsLabel": "Hide participant list from other participants",
"hideScoresLabel": "Hide scores until after a participant has voted",
- "continueAs": "Continue as",
"pageMovedDescription": "Redirecting to <a>{newUrl}</a>",
"pollStatusFinalized": "Finalized",
"share": "Share",
@@ -237,11 +236,8 @@
"quickCreateSecurePolls": "Secure access through your account",
"quickCreateGetNotifications": "Get email notifications",
"quickCreateManagePollsFromAnyDevice": "Manage your polls from any device",
- "registerVerifyTitle": "Finish Registering",
- "registerVerifyDescription": "Check your email for the verification code",
"loginVerifyTitle": "Finish Logging In",
"loginVerifyDescription": "Check your email for the verification code",
- "createAccount": "Create Account",
"tooManyRequests": "Too many requests",
"tooManyRequestsDescription": "Please try again later.",
"billingSubscriptionDescription": "Manage your current subscription plan.",
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
deleted file mode 100644
index 66ab50c59..000000000
--- a/apps/web/src/app/[locale]/(auth)/auth/login/components/login-page.tsx
+++ /dev/null
@@ -1,75 +0,0 @@
-"use client";
-import { Button } from "@rallly/ui/button";
-import { useRouter } from "next/navigation";
-import React from "react";
-
-import { Logo } from "@/components/logo";
-import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
-import { Skeleton } from "@/components/skeleton";
-import { Trans } from "@/components/trans";
-import { authClient } from "@/lib/auth-client";
-import { trpc } from "@/trpc/client";
-
-export const LoginPage = ({ email, code }: { email: string; code: string }) => {
- const [error, setError] = React.useState<string | null>(null);
- const [isLoading, setLoading] = React.useState(false);
-
- const { data } = trpc.user.getByEmail.useQuery({ email });
- const router = useRouter();
- return (
- <div className="flex h-full w-full flex-col items-center justify-center">
- <div className="mb-12">
- <Logo className="mx-auto" />
- </div>
- <div className="w-48 space-y-8 text-center">
- <h1 className="font-bold text-xl">
- <Trans i18nKey="continueAs" defaults="Continue as" />
- </h1>
- <div className="flex flex-col items-center gap-4">
- <OptimizedAvatarImage
- src={data?.image ?? undefined}
- name={data?.name ?? ""}
- size="xl"
- />
- <div>
- <div className="mb-1 h-6 font-medium">
- {data?.name ?? <Skeleton className="inline-block h-5 w-16" />}
- </div>
- <div className="h-5 truncate text-muted-foreground text-sm">
- {data?.email ?? <Skeleton className="inline-block h-full w-20" />}
- </div>
- </div>
- </div>
- <div>
- <Button
- size="lg"
- loading={isLoading}
- onClick={async () => {
- setLoading(true);
- setError(null);
-
- try {
- const res = await authClient.signIn.emailOtp({
- email,
- otp: code,
- });
- if (res.error) {
- setError(res.error.message ?? "An error occurred");
- } else {
- router.push("/");
- }
- } finally {
- setLoading(false);
- }
- }}
- variant="primary"
- className="w-full"
- >
- <Trans i18nKey="login" defaults="Login" />
- </Button>
- </div>
- {error && <p className="text-destructive text-sm">{error}</p>}
- </div>
- </div>
- );
-};
diff --git a/apps/web/src/app/[locale]/(auth)/auth/login/page.tsx b/apps/web/src/app/[locale]/(auth)/auth/login/page.tsx
deleted file mode 100644
index 6107b0ba1..000000000
--- a/apps/web/src/app/[locale]/(auth)/auth/login/page.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import type { Metadata } from "next";
-import { notFound } from "next/navigation";
-import { z } from "zod";
-
-import { getTranslation } from "@/i18n/server";
-
-import { LoginPage } from "./components/login-page";
-
-export const dynamic = "force-dynamic";
-
-const searchParamsSchema = z.object({
- email: z.email(),
- code: z.string(),
-});
-
-type SearchParams = z.infer<typeof searchParamsSchema>;
-
-export default async function Page(props: {
- searchParams: Promise<SearchParams>;
-}) {
- const searchParams = await props.searchParams;
- const parse = searchParamsSchema.safeParse(searchParams);
-
- if (!parse.success) {
- return notFound();
- }
-
- const { email, code } = parse.data;
-
- return <LoginPage email={email} code={code} />;
-}
-
-export async function generateMetadata(props: {
- params: Promise<{ locale: string }>;
-}): Promise<Metadata> {
- const params = await props.params;
- const { t } = await getTranslation(params.locale);
- return {
- title: t("login"),
- };
-}
diff --git a/apps/web/src/app/[locale]/(auth)/register/verify/components/otp-form.tsx b/apps/web/src/app/[locale]/(auth)/register/verify/components/otp-form.tsx
deleted file mode 100644
index 5520ec165..000000000
--- a/apps/web/src/app/[locale]/(auth)/register/verify/components/otp-form.tsx
+++ /dev/null
@@ -1,121 +0,0 @@
-"use client";
-
-import { zodResolver } from "@hookform/resolvers/zod";
-import { Button } from "@rallly/ui/button";
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormMessage,
-} from "@rallly/ui/form";
-import { useSearchParams } from "next/navigation";
-import { signIn } from "next-auth/react";
-import { useForm } from "react-hook-form";
-import { z } from "zod";
-
-import { InputOTP } from "@/components/input-otp";
-import { Trans } from "@/components/trans";
-import { useTranslation } from "@/i18n/client";
-import { trpc } from "@/trpc/client";
-import { useDayjs } from "@/utils/dayjs";
-
-const otpFormSchema = z.object({
- otp: z.string().length(6),
-});
-
-type OTPFormValues = z.infer<typeof otpFormSchema>;
-
-export function OTPForm({ token }: { token: string }) {
- const { t, i18n } = useTranslation();
- const form = useForm<OTPFormValues>({
- defaultValues: {
- otp: "",
- },
- resolver: zodResolver(otpFormSchema),
- });
-
- const { timeZone, weekStart, timeFormat } = useDayjs();
-
- const locale = i18n.language;
-
- const queryClient = trpc.useUtils();
- const authenticateRegistration =
- trpc.auth.authenticateRegistration.useMutation();
- const searchParams = useSearchParams();
- const handleSubmit = form.handleSubmit(async (data) => {
- // get user's time zone
- const res = await authenticateRegistration.mutateAsync({
- token,
- timeZone,
- locale,
- weekStart,
- timeFormat,
- code: data.otp,
- });
-
- if (!res.user) {
- form.setError("otp", {
- message: t("wrongVerificationCode"),
- });
- return;
- }
-
- queryClient.invalidate();
-
- signIn("registration-token", {
- token,
- redirectTo: searchParams?.get("redirectTo") ?? "/",
- });
- });
-
- const isLoading =
- form.formState.isSubmitting ||
- form.formState.isSubmitSuccessful ||
- authenticateRegistration.isPending;
-
- return (
- <Form {...form}>
- <form className="space-y-6" onSubmit={handleSubmit}>
- <FormField
- control={form.control}
- name="otp"
- render={({ field }) => {
- return (
- <FormItem>
- <FormControl>
- <InputOTP
- size="lg"
- placeholder={t("verificationCodePlaceholder", {
- ns: "app",
- })}
- disabled={isLoading}
- autoFocus={true}
- onValidCode={() => {
- handleSubmit();
- }}
- {...field}
- />
- </FormControl>
- <FormDescription>
- <Trans i18nKey="verificationCodeHelp" />
- </FormDescription>
- <FormMessage />
- </FormItem>
- );
- }}
- />
- <Button
- className="w-full"
- variant="primary"
- type="submit"
- size="lg"
- disabled={isLoading}
- >
- <Trans i18nKey="createAccount" defaults="Create Account" />
- </Button>
- </form>
- </Form>
- );
-}
diff --git a/apps/web/src/app/[locale]/(auth)/register/verify/page.tsx b/apps/web/src/app/[locale]/(auth)/register/verify/page.tsx
deleted file mode 100644
index 2b0ab3580..000000000
--- a/apps/web/src/app/[locale]/(auth)/register/verify/page.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { Button } from "@rallly/ui/button";
-import type { Metadata } from "next";
-import { cookies } from "next/headers";
-import Link from "next/link";
-import { redirect } from "next/navigation";
-import { Trans } from "react-i18next/TransWithoutContext";
-
-import { getTranslation } from "@/i18n/server";
-
-import {
- AuthPageContainer,
- AuthPageContent,
- AuthPageDescription,
- AuthPageHeader,
- AuthPageTitle,
-} from "../../components/auth-page";
-import { OTPForm } from "./components/otp-form";
-
-export default async function VerifyPage(props: {
- params: Promise<{ locale: string }>;
-}) {
- const params = await props.params;
-
- const { locale } = params;
-
- const { t } = await getTranslation(locale);
- const token = (await cookies()).get("registration-token")?.value;
-
- if (!token) {
- redirect("/register");
- }
-
- return (
- <AuthPageContainer>
- <AuthPageHeader>
- <AuthPageTitle>
- <Trans
- t={t}
- ns="app"
- i18nKey="registerVerifyTitle"
- defaults="Finish Registering"
- />
- </AuthPageTitle>
- <AuthPageDescription>
- <Trans
- t={t}
- ns="app"
- i18nKey="registerVerifyDescription"
- defaults="Check your email for the verification code"
- />
- </AuthPageDescription>
- </AuthPageHeader>
- <AuthPageContent>
- <OTPForm token={token} />
- <Button size="lg" variant="link" className="w-full" asChild>
- <Link href="/register">
- <Trans t={t} ns="app" i18nKey="back" defaults="Back" />
- </Link>
- </Button>
- </AuthPageContent>
- </AuthPageContainer>
- );
-}
-
-export async function generateMetadata(props: {
- params: Promise<{ locale: string }>;
-}): Promise<Metadata> {
- const params = await props.params;
- const { t } = await getTranslation(params.locale);
- return {
- title: t("verifyEmail", {
- ns: "app",
- defaultValue: "Verify your email",
- }),
- };
-}
diff --git a/apps/web/src/app/api/auth/[...nextauth]/route.ts b/apps/web/src/app/api/auth/[...nextauth]/route.ts
index 76810f7cd..4b6eabc11 100644
--- a/apps/web/src/app/api/auth/[...nextauth]/route.ts
+++ b/apps/web/src/app/api/auth/[...nextauth]/route.ts
@@ -1,20 +1,5 @@
-import type { NextRequest } from "next/server";
-import { rateLimit } from "@/lib/rate-limit";
import { handlers } from "@/next-auth";
import { withPosthog } from "@/utils/posthog";
-export const GET = withPosthog(async (req: NextRequest) => {
- if (req.nextUrl.pathname.includes("callback/email")) {
- const { success } = await rateLimit("login_otp_attempt", 20, "15m");
-
- if (!success) {
- return new Response("Too many requests", {
- status: 429,
- });
- }
- }
-
- return handlers.GET(req);
-});
-
+export const GET = withPosthog(handlers.GET);
export const POST = withPosthog(handlers.POST);
diff --git a/apps/web/src/auth/providers/email.ts b/apps/web/src/auth/providers/email.ts
deleted file mode 100644
index 444a6dbdb..000000000
--- a/apps/web/src/auth/providers/email.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { prisma } from "@rallly/database";
-import { absoluteUrl } from "@rallly/utils/absolute-url";
-import { generateOtp } from "@rallly/utils/nanoid";
-import NodemailerProvider from "next-auth/providers/nodemailer";
-
-import { getEmailClient } from "@/utils/emails";
-
-export const EmailProvider = () => {
- if (process.env.EMAIL_LOGIN_ENABLED === "false") {
- return null;
- }
-
- return NodemailerProvider({
- server: "none", // This value is required even though we don't need it
- from: process.env.NOREPLY_EMAIL,
- id: "email",
- maxAge: 15 * 60,
- generateVerificationToken() {
- return generateOtp();
- },
- async sendVerificationRequest({ identifier: email, token, url }) {
- const user = await prisma.user.findUnique({
- where: {
- email,
- },
- select: {
- name: true,
- locale: true,
- },
- });
-
- if (user) {
- await getEmailClient(user.locale ?? undefined).sendTemplate(
- "LoginEmail",
- {
- to: email,
- props: {
- magicLink: absoluteUrl("/auth/login", {
- magicLink: url,
- }),
- code: token,
- },
- },
- );
- }
- },
- });
-};
diff --git a/apps/web/src/auth/providers/google.ts b/apps/web/src/auth/providers/google.ts
deleted file mode 100644
index d344aae9c..000000000
--- a/apps/web/src/auth/providers/google.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import BaseGoogleProvider from "next-auth/providers/google";
-
-export function GoogleProvider() {
- if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET) {
- return BaseGoogleProvider({
- clientId: process.env.GOOGLE_CLIENT_ID,
- clientSecret: process.env.GOOGLE_CLIENT_SECRET,
- allowDangerousEmailAccountLinking: true,
- });
- }
-}
diff --git a/apps/web/src/auth/providers/microsoft.ts b/apps/web/src/auth/providers/microsoft.ts
deleted file mode 100644
index d0c18caa0..000000000
--- a/apps/web/src/auth/providers/microsoft.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import MicrosoftEntraID from "next-auth/providers/microsoft-entra-id";
-
-export function MicrosoftProvider() {
- if (process.env.MICROSOFT_CLIENT_ID && process.env.MICROSOFT_CLIENT_SECRET) {
- return MicrosoftEntraID({
- name: "Microsoft",
- clientId: process.env.MICROSOFT_CLIENT_ID,
- clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
- issuer: `https://login.microsoftonline.com/${process.env.MICROSOFT_TENANT_ID || "common"}/v2.0`,
- });
- }
-}
diff --git a/apps/web/src/auth/providers/oidc.ts b/apps/web/src/auth/providers/oidc.ts
deleted file mode 100644
index 7c5c7d2db..000000000
--- a/apps/web/src/auth/providers/oidc.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import type { User } from "next-auth";
-import type { OIDCConfig } from "next-auth/providers/index";
-
-import { env } from "@/env";
-import { getValueByPath } from "@/utils/get-value-by-path";
-
-export const OIDCProvider = () => {
- if (env.OIDC_DISCOVERY_URL && env.OIDC_CLIENT_ID && env.OIDC_CLIENT_SECRET) {
- if (!env.OIDC_ISSUER_URL) {
- console.warn(
- "OIDC_ISSUER_URL is not set. Please set it to the issuer URL of your OpenID Connect provider.",
- );
- return;
- }
- return {
- id: "oidc",
- name: env.OIDC_NAME ?? "OpenID Connect",
- type: "oidc",
- wellKnown: env.OIDC_DISCOVERY_URL,
- authorization: {
- params: {
- scope: "openid email profile",
- },
- },
- issuer: env.OIDC_ISSUER_URL,
- clientId: env.OIDC_CLIENT_ID,
- clientSecret: env.OIDC_CLIENT_SECRET,
- idToken: true,
- checks: ["pkce", "state"],
- allowDangerousEmailAccountLinking: true,
- profile(profile) {
- return {
- id: profile.sub,
- name: getValueByPath(profile, env.OIDC_NAME_CLAIM_PATH),
- email: getValueByPath(profile, env.OIDC_EMAIL_CLAIM_PATH),
- image: getValueByPath(profile, env.OIDC_PICTURE_CLAIM_PATH),
- } as User;
- },
- } satisfies OIDCConfig<Record<string, unknown>>;
- }
-};
diff --git a/apps/web/src/auth/providers/registration-token.ts b/apps/web/src/auth/providers/registration-token.ts
deleted file mode 100644
index f0a9ebc44..000000000
--- a/apps/web/src/auth/providers/registration-token.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { prisma } from "@rallly/database";
-import CredentialsProvider from "next-auth/providers/credentials";
-
-import type { RegistrationTokenPayload } from "@/trpc/types";
-import { decryptToken } from "@/utils/session";
-
-// When a user registers, we don't want to go through the email verification process
-// so this provider allows us exchange the registration token for a session token
-export const RegistrationTokenProvider = CredentialsProvider({
- id: "registration-token",
- name: "Registration Token",
- credentials: {
- token: {
- label: "Token",
- type: "text",
- },
- },
- async authorize(credentials) {
- if (credentials?.token) {
- const payload = await decryptToken<RegistrationTokenPayload>(
- credentials.token as string,
- );
- if (payload) {
- const user = await prisma.user.findUnique({
- where: {
- email: payload.email,
- },
- select: {
- id: true,
- email: true,
- name: true,
- locale: true,
- timeFormat: true,
- timeZone: true,
- image: true,
- },
- });
-
- if (user) {
- return user;
- }
- }
- }
-
- return null;
- },
-});
diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts
index ca52eee57..faa2948f0 100644
--- a/apps/web/src/lib/auth.ts
+++ b/apps/web/src/lib/auth.ts
@@ -112,13 +112,9 @@ export const authLib = betterAuth({
// We're not actually using the sign-in type anymore since we just we have `autoSignInAfterVerification` enabled.
// This lets us keep things a bit simpler since we share the same verification flow for both login and registration.
case "sign-in":
- await emailClient.sendTemplate("LoginEmail", {
+ await emailClient.sendTemplate("RegisterEmail", {
to: email,
props: {
- magicLink: absoluteUrl("/auth/login", {
- code: otp,
- email,
- }),
code: otp,
},
});
diff --git a/apps/web/src/next-auth.config.ts b/apps/web/src/next-auth.config.ts
deleted file mode 100644
index 955de2ebb..000000000
--- a/apps/web/src/next-auth.config.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import type { NextAuthConfig } from "next-auth";
-
-import { env } from "@/env";
-
-/**
- * We split the next-auth config so that we can create an edge compatible instance that is
- * used in middleware.
- */
-export const nextAuthConfig = {
- session: {
- strategy: "jwt",
- },
- secret: env.SECRET_PASSWORD,
- providers: [],
- callbacks: {
- async session({ session, token }) {
- session.user.id = token.sub as string;
- session.user.email = token.email as string;
- session.user.timeFormat = token.timeFormat;
- session.user.timeZone = token.timeZone;
- session.user.weekStart = token.weekStart;
- return session;
- },
- },
-} satisfies NextAuthConfig;
diff --git a/apps/web/src/next-auth.ts b/apps/web/src/next-auth.ts
index 1d0271b2e..2441ae9ab 100644
--- a/apps/web/src/next-auth.ts
+++ b/apps/web/src/next-auth.ts
@@ -1,39 +1,21 @@
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@rallly/database";
-import { posthog } from "@rallly/posthog/server";
import NextAuth from "next-auth";
-import type { Provider } from "next-auth/providers";
-import { isEmailBanned, isEmailBlocked } from "./auth/helpers/is-email-blocked";
-import { mergeGuestsIntoUser } from "./auth/helpers/merge-user";
-import { EmailProvider } from "./auth/providers/email";
-import { GoogleProvider } from "./auth/providers/google";
+import { env } from "@/env";
import { GuestProvider } from "./auth/providers/guest";
-import { MicrosoftProvider } from "./auth/providers/microsoft";
-import { OIDCProvider } from "./auth/providers/oidc";
-import { RegistrationTokenProvider } from "./auth/providers/registration-token";
-import { nextAuthConfig } from "./next-auth.config";
const { auth, handlers, signIn, signOut } = NextAuth({
- ...nextAuthConfig,
+ session: {
+ strategy: "jwt",
+ },
+ secret: env.SECRET_PASSWORD,
adapter: PrismaAdapter(prisma),
- providers: [
- RegistrationTokenProvider,
- GuestProvider,
- ...([
- EmailProvider(),
- GoogleProvider(),
- OIDCProvider(),
- MicrosoftProvider(),
- ].filter(Boolean) as Provider[]),
- ],
+ providers: [GuestProvider],
pages: {
signIn: "/login",
verifyRequest: "/login/verify",
error: "/auth/error",
},
- session: {
- strategy: "jwt",
- },
jwt: {
maxAge: 60 * 60 * 24 * 60,
},
@@ -44,84 +26,10 @@ const { auth, handlers, signIn, signOut } = NextAuth({
},
},
},
- events: {
- createUser({ user }) {
- if (user.id) {
- posthog?.capture({
- distinctId: user.id,
- event: "register",
- properties: {
- method: "sso",
- $set: {
- name: user.name,
- email: user.email,
- tier: "hobby",
- timeZone: user.timeZone ?? undefined,
- locale: user.locale ?? undefined,
- },
- },
- });
- }
- },
- signIn({ user, account }) {
- if (user.id) {
- posthog?.capture({
- distinctId: user.id,
- event: "login",
- properties: {
- method: account?.provider,
- $set: {
- name: user.name,
- email: user.email,
- timeZone: user.timeZone ?? undefined,
- locale: user.locale ?? undefined,
- },
- },
- });
- }
- },
- },
callbacks: {
- ...nextAuthConfig.callbacks,
- async signIn({ user, email, profile }) {
- if (email?.verificationRequest) {
- const isRegisteredUser =
- (await prisma.user.count({
- where: {
- email: user.email as string,
- },
- })) > 0;
- if (!isRegisteredUser) {
- return "/login?error=EmailNotVerified";
- }
- }
-
- if (user.banned) {
- return "/login?error=Banned";
- }
-
- // Make sure email is allowed
- const emailToTest = user.email || profile?.email;
- if (emailToTest) {
- if (isEmailBlocked(emailToTest) || (await isEmailBanned(emailToTest))) {
- return "/login?error=EmailBlocked";
- }
- }
-
- // If this is an existing registered user
- if (user.id && user.role && user.email) {
- // merge guest user into existing user
- const session = await auth();
- if (session?.user && !session.user.email) {
- await mergeGuestsIntoUser(user.id, [session.user.id]);
- }
- }
-
- return true;
- },
async jwt({ token }) {
const userId = token.sub;
- const isGuest = userId?.startsWith("guest-");
+ const isGuest = !token.email;
if (userId && !isGuest) {
const user = await prisma.user.findUnique({
diff --git a/apps/web/tests/helpers/next-auth-v4.ts b/apps/web/tests/helpers/next-auth-v4.ts
deleted file mode 100644
index bd48d65aa..000000000
--- a/apps/web/tests/helpers/next-auth-v4.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import hkdf from "@panva/hkdf";
-import { EncryptJWT } from "jose";
-import type { JWT } from "next-auth/jwt";
-
-const now = () => (Date.now() / 1000) | 0;
-export async function getDerivedEncryptionKey(
- keyMaterial: string | Uint8Array,
- salt: string,
-) {
- return await hkdf(
- "sha256",
- keyMaterial,
- salt,
- `NextAuth.js Generated Encryption Key${salt ? ` (${salt})` : ""}`,
- 32,
- );
-}
-
-interface JWTEncodeParams {
- token?: JWT;
- salt?: string;
- secret: string | Uint8Array;
- maxAge?: number;
-}
-
-export async function encode(params: JWTEncodeParams) {
- /** @note empty `salt` means a session token. See {@link JWTEncodeParams.salt}. */
- const { token = {}, secret, maxAge = 30 * 24 * 60 * 60, salt = "" } = params;
- const encryptionSecret = await getDerivedEncryptionKey(secret, salt);
- return await new EncryptJWT(token)
- .setProtectedHeader({ alg: "dir", enc: "A256GCM" })
- .setIssuedAt()
- .setExpirationTime(now() + maxAge)
- .setJti("some-random-id")
- .encrypt(encryptionSecret);
-}
diff --git a/packages/emails/locales/en/emails.json b/packages/emails/locales/en/emails.json
index 022e7d0cc..318b54c80 100644
--- a/packages/emails/locales/en/emails.json
+++ b/packages/emails/locales/en/emails.json
@@ -12,13 +12,7 @@
"finalizeParticipant_heading": "Final date booked!",
"finalizeParticipant_content2": "Please find attached a calendar invite for this event.",
"finalizeParticipant_subject": "Date booked for {title}",
- "login_button": "Log in to {domain}",
"login_content2": "You're receiving this email because a request was made to login to <domain />. If this wasn't you contact <a>{supportEmail}</a>.",
- "login_preview": "Use this link to log in on this device.",
- "login_heading": "Login",
- "login_content": "Enter this one-time 6-digit verification code:",
- "login_codeValid": "This code is valid for 15 minutes",
- "login_subject": "{code} is your 6-digit code",
"newComment_content": "<b>{authorName}</b> has commented on <b>{title}</b>.",
"newComment_subject": "{authorName} has commented on {title}",
"newParticipantConfirmation_content": "Your response to <b>{title}</b> has been submitted.",
diff --git a/packages/emails/src/previews/login.tsx b/packages/emails/src/previews/login.tsx
deleted file mode 100644
index 4fa39089e..000000000
--- a/packages/emails/src/previews/login.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { previewEmailContext } from "../components/email-context";
-import { LoginEmail } from "../templates/login";
-
-export default function LoginPreview() {
- return (
- <LoginEmail
- code="123456"
- magicLink="https://rallly.co"
- ctx={previewEmailContext}
- />
- );
-}
diff --git a/packages/emails/src/templates.ts b/packages/emails/src/templates.ts
index 67c04e3a4..9f37deeaa 100644
--- a/packages/emails/src/templates.ts
+++ b/packages/emails/src/templates.ts
@@ -4,7 +4,6 @@ import { EventCanceledEmail } from "./templates/event-canceled";
import { FinalizeHostEmail } from "./templates/finalized-host";
import { FinalizeParticipantEmail } from "./templates/finalized-participant";
import { LicenseKeyEmail } from "./templates/license-key";
-import { LoginEmail } from "./templates/login";
import { NewCommentEmail } from "./templates/new-comment";
import { NewParticipantEmail } from "./templates/new-participant";
import { NewParticipantConfirmationEmail } from "./templates/new-participant-confirmation";
@@ -17,7 +16,6 @@ import type { TemplateName } from "./types";
const templates = {
FinalizeHostEmail,
FinalizeParticipantEmail,
- LoginEmail,
NewCommentEmail,
NewParticipantEmail,
NewParticipantConfirmationEmail,
diff --git a/packages/emails/src/templates/login.tsx b/packages/emails/src/templates/login.tsx
deleted file mode 100644
index 54e2b2f54..000000000
--- a/packages/emails/src/templates/login.tsx
+++ /dev/null
@@ -1,97 +0,0 @@
-import { Section } from "@react-email/components";
-import { Trans } from "react-i18next/TransWithoutContext";
-
-import { EmailLayout } from "../components/email-layout";
-import {
- Button,
- Card,
- Domain,
- Heading,
- Link,
- Text,
- trackingWide,
-} from "../components/styled-components";
-import type { EmailContext } from "../types";
-
-interface LoginEmailProps {
- code: string;
- magicLink: string;
- ctx: EmailContext;
-}
-
-export const LoginEmail = ({ code, magicLink, ctx }: LoginEmailProps) => {
- return (
- <EmailLayout
- ctx={ctx}
- preview={ctx.t("login_preview", {
- defaultValue: "Use this link to log in on this device.",
- ns: "emails",
- })}
- >
- <Heading>
- {ctx.t("login_heading", { defaultValue: "Login", ns: "emails" })}
- </Heading>
- <Text>
- {ctx.t("login_content", {
- defaultValue: "Enter this one-time 6-digit verification code:",
- ns: "emails",
- })}
- </Text>
- <Card style={{ textAlign: "center" }}>
- <Text
- style={{
- ...trackingWide,
- textAlign: "center",
- fontSize: "32px",
- fontWeight: "bold",
- }}
- id="code"
- >
- {code}
- </Text>
- <Text style={{ textAlign: "center" }} light={true}>
- {ctx.t("login_codeValid", {
- defaultValue: "This code is valid for 15 minutes",
- ns: "emails",
- })}
- </Text>
- </Card>
- <Section style={{ marginBottom: 32 }}>
- <Button href={magicLink} id="magicLink">
- <Trans
- i18n={ctx.i18n}
- t={ctx.t}
- i18nKey="login_button"
- defaults="Log in to {domain}"
- values={{ domain: ctx.domain }}
- ns="emails"
- />
- </Button>
- </Section>
- <Text light>
- <Trans
- i18n={ctx.i18n}
- t={ctx.t}
- i18nKey="login_content2"
- defaults="You're receiving this email because a request was made to login to <domain />. If this wasn't you contact <a>{supportEmail}</a>."
- values={{ supportEmail: ctx.supportEmail }}
- components={{
- domain: <Domain ctx={ctx} />,
- a: <Link href={`mailto:${ctx.supportEmail}`} />,
- }}
- ns="emails"
- />
- </Text>
- </EmailLayout>
- );
-};
-
-LoginEmail.getSubject = (props: LoginEmailProps, ctx: EmailContext) => {
- return ctx.t("login_subject", {
- defaultValue: "{code} is your 6-digit code",
- code: props.code,
- ns: "emails",
- });
-};
-
-export default LoginEmail;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 49dc88a1d..a30568d0c 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -196,9 +196,6 @@ importers:
'@next/env':
specifier: ^15.3.1
version: 15.4.6
- '@panva/hkdf':
- specifier: ^1.2.1
- version: 1.2.1
'@prisma/client':
specifier: ^6.8.2
@@ -340,9 +337,6 @@ importers:
iron-session:
specifier: ^6.3.1
- jose:
- specifier: ^5.9.6
- version: 5.10.0
js-cookie:
specifier: ^3.0.1
version: 3.0.5