From 7d3d68cd0b8a78b7bf8d8a0ab3dee4bbe06c1ce4 Mon Sep 17 00:00:00 2001 From: Adam Soffer Date: Wed, 1 May 2024 14:18:32 -0400 Subject: [PATCH] move auth routes to /dashboard (#2157) --- packages/api/src/controllers/user.ts | 12 +- packages/www/components/Login/index.tsx | 2 +- packages/www/components/Plans/index.tsx | 6 +- packages/www/components/Site/Compare/Hero.tsx | 2 +- packages/www/components/Site/Footer/index.tsx | 2 +- .../www/components/Site/HomeHero/index.tsx | 2 +- .../www/components/Site/Navigation/base.tsx | 4 +- .../Site/Navigation/mobile/authButtons.tsx | 2 +- .../www/components/Site/Prefooter/index.tsx | 2 +- .../Site/PricingCalculator/Calculator.tsx | 4 +- packages/www/hooks/use-logged-in.tsx | 2 +- packages/www/next.config.js | 67 ++ .../pages/{ => dashboard}/forgot-password.tsx | 0 packages/www/pages/{ => dashboard}/login.tsx | 4 +- .../www/pages/{ => dashboard}/register.tsx | 10 +- .../pages/{ => dashboard}/reset-password.tsx | 0 .../{ => dashboard}/verify-new-email.tsx | 0 packages/www/pages/{ => dashboard}/verify.tsx | 0 packages/www/pages/use-cases/[slug].tsx | 4 +- yarn.lock | 1005 ++++++++++++++++- 20 files changed, 1102 insertions(+), 28 deletions(-) rename packages/www/pages/{ => dashboard}/forgot-password.tsx (100%) rename packages/www/pages/{ => dashboard}/login.tsx (95%) rename packages/www/pages/{ => dashboard}/register.tsx (94%) rename packages/www/pages/{ => dashboard}/reset-password.tsx (100%) rename packages/www/pages/{ => dashboard}/verify-new-email.tsx (100%) rename packages/www/pages/{ => dashboard}/verify.tsx (100%) diff --git a/packages/api/src/controllers/user.ts b/packages/api/src/controllers/user.ts index de3bca2e65..ff04179c44 100644 --- a/packages/api/src/controllers/user.ts +++ b/packages/api/src/controllers/user.ts @@ -554,7 +554,7 @@ app.patch("/:id/email", authorizer({}), async (req, res) => { buttonText: "Verify Email", buttonUrl: frontendUrl( req, - `/verify-new-email?${qs.stringify({ + `/dashboard/verify-new-email?${qs.stringify({ emailValidToken, email: lowerCaseEmail, })}` @@ -905,7 +905,7 @@ app.post("/verify", validatePost("user-verification"), async (req, res) => { subject: `User ${user.email} signed up with Livepeer!`, preheader: "We have a new verified user", buttonText: "Log into livepeer", - buttonUrl: frontendUrl(req, "/login"), + buttonUrl: frontendUrl(req, "/dashboard/login"), unsubscribe: unsubscribeUrl(req), text: [ `User ${user.email} has signed up and verified their email with Livepeer!`, @@ -979,7 +979,11 @@ async function sendVerificationEmail(req: Request, user: User, selectedPlan) { buttonText: "Verify Email", buttonUrl: frontendUrl( req, - `/verify?${qs.stringify({ email, emailValidToken, selectedPlan })}` + `/dashboard/verify?${qs.stringify({ + email, + emailValidToken, + selectedPlan, + })}` ), unsubscribe: unsubscribeUrl(req), text: [ @@ -1068,7 +1072,7 @@ app.post( buttonText: "Reset Password", buttonUrl: frontendUrl( req, - `/reset-password?${qs.stringify({ email, resetToken })}` + `/dashboard/reset-password?${qs.stringify({ email, resetToken })}` ), unsubscribe: unsubscribeUrl(req), text: [ diff --git a/packages/www/components/Login/index.tsx b/packages/www/components/Login/index.tsx index 7a8cfc1bdc..696c9ec952 100644 --- a/packages/www/components/Login/index.tsx +++ b/packages/www/components/Login/index.tsx @@ -122,7 +122,7 @@ const Login = ({ id, buttonText, onSubmit, loading, errors }) => { transform: "translateY(-50%)", top: "50%", }}> - + { stripeProductId="prod_O9XuIjn7EqYRVW" onClick={() => { if (!dashboard) { - router.push("/register"); + router.push("/dashboard/register"); } }} /> @@ -349,7 +349,7 @@ const Plans = ({ dashboard = false, stripeProductId }: PlanProps) => { if (dashboard) { setIsTourOpen(false); } else { - router.push("/register?selectedPlan=1"); + router.push("/dashboard/register?selectedPlan=1"); } }} /> @@ -511,7 +511,7 @@ const Plans = ({ dashboard = false, stripeProductId }: PlanProps) => { if (dashboard) { setIsTourOpen(false); } else { - router.push("/register?selectedPlan=2"); + router.push("/dashboard/register?selectedPlan=2"); } }} /> diff --git a/packages/www/components/Site/Compare/Hero.tsx b/packages/www/components/Site/Compare/Hero.tsx index c27d3c323a..5bc5cf850e 100644 --- a/packages/www/components/Site/Compare/Hero.tsx +++ b/packages/www/components/Site/Compare/Hero.tsx @@ -43,7 +43,7 @@ const CompareHero = ({ how its features and pricing compare to {comparison}. - + - + diff --git a/packages/www/hooks/use-logged-in.tsx b/packages/www/hooks/use-logged-in.tsx index 2f607571a9..383908feae 100644 --- a/packages/www/hooks/use-logged-in.tsx +++ b/packages/www/hooks/use-logged-in.tsx @@ -29,7 +29,7 @@ export default function useLoggedIn(shouldBeLoggedIn = true) { useEffect(() => { if (shouldBeLoggedIn === true) { if (!token) { - router.replace("/login"); + router.replace("/dashboard/login"); } else if (emailVerificationMode && user?.emailValid === false) { router.replace("/verify"); } diff --git a/packages/www/next.config.js b/packages/www/next.config.js index 119f8c246d..8e442446fb 100644 --- a/packages/www/next.config.js +++ b/packages/www/next.config.js @@ -188,6 +188,73 @@ let config = { destination: "https://livepeer.canny.io", permanent: false, }, + { + source: "/register", + destination: "/dashboard/register", + permanent: false, + }, + { + source: "/login", + destination: "/dashboard/login", + permanent: false, + }, + { + source: "/verify", + destination: + "/dashboard/verify?email=:email&emailValidToken=:emailValidToken&selectedPlan=:selectedPlan", + permanent: false, + has: [ + { + type: "query", + key: "email", + }, + { + type: "query", + key: "emailValidToken", + }, + { + type: "query", + key: "selectedPlan", + }, + ], + }, + { + source: "/verify-new-email", + destination: + "/dashboard/verify-new-email?email=:email&emailValidToken=:emailValidToken", + permanent: false, + has: [ + { + type: "query", + key: "email", + }, + { + type: "query", + key: "emailValidToken", + }, + ], + }, + { + source: "/reset-password", + destination: + "/dashboard/reset-password?email=:email&resetToken=:resetToken", + permanent: false, + has: [ + { + type: "query", + key: "email", + }, + { + type: "query", + key: "resetToken", + }, + ], + }, + { + source: "/forgot-password", + destination: "/dashboard/forgot-password", + permanent: false, + }, ]; }, }; diff --git a/packages/www/pages/forgot-password.tsx b/packages/www/pages/dashboard/forgot-password.tsx similarity index 100% rename from packages/www/pages/forgot-password.tsx rename to packages/www/pages/dashboard/forgot-password.tsx diff --git a/packages/www/pages/login.tsx b/packages/www/pages/dashboard/login.tsx similarity index 95% rename from packages/www/pages/login.tsx rename to packages/www/pages/dashboard/login.tsx index c494cf9b68..98be48730c 100644 --- a/packages/www/pages/login.tsx +++ b/packages/www/pages/dashboard/login.tsx @@ -9,7 +9,7 @@ import { Link as A, } from "@livepeer/design-system"; import { useState } from "react"; -import { useApi, useLoggedIn } from "../hooks"; +import { useApi, useLoggedIn } from "../../hooks"; import Link from "next/link"; import { Home as Content } from "content"; @@ -85,7 +85,7 @@ const LoginPage = () => { "linear-gradient(to right,transparent,rgba(255,255,255,0.1) 50%,transparent)", }} /> - + { useEffect(() => { if (user) { if (emailVerificationMode && user.emailValid === false) { - router.replace("/verify"); + router.replace("/dashboard/verify"); } else { router.replace("/dashboard"); } @@ -143,7 +143,7 @@ const RegisterPage = () => { "linear-gradient(to right,transparent,rgba(255,255,255,0.1) 50%,transparent)", }} /> - +