The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update app.ts
Kiran K4209ca929eaa
diff --git a/apps/web/lib/middleware/app.ts b/apps/web/lib/middleware/app.tsindex 7bfac37d12..dbff5f41e5 100644--- a/apps/web/lib/middleware/app.ts+++ b/apps/web/lib/middleware/app.ts@@ -1,3 +1,4 @@+import { prismaEdge } from "@dub/prisma/edge";import { NextRequest, NextResponse } from "next/server";import {ONBOARDING_WINDOW_SECONDS,@@ -114,44 +115,44 @@ export async function AppMiddleware(req: NextRequest) {);}- // if (path.startsWith("/onboarding/welcome")) {- // // Redirect users with pending workspace invites away from onboarding- // // to accept their invitation instead of creating a new workspace- // const pendingInvite = await prismaEdge.projectInvite.findFirst({- // where: {- // email: user.email,- // },- // select: {- // project: {- // select: {- // slug: true,- // },- // },- // },- // });-- // if (pendingInvite) {- // return NextResponse.redirect(- // new URL(`/${pendingInvite.project.slug}?invite=1`, req.url),- // );- // }-- // // If user already has a workspace, redirect them away from onboarding- // // to their workspaces page instead of allowing them to create a new one- // const existingWorkspace = await prismaEdge.project.findFirst({- // where: {- // users: {- // some: {- // userId: user.id,- // },- // },- // },- // });-- // if (existingWorkspace) {- // return NextResponse.redirect(new URL("/workspaces", req.url));- // }- // }+ if (path.startsWith("/onboarding")) {+ // Redirect users with pending workspace invites away from onboarding+ // to accept their invitation instead of creating a new workspace+ const pendingInvite = await prismaEdge.projectInvite.findFirst({+ where: {+ email: user.email,+ },+ select: {+ project: {+ select: {+ slug: true,+ },+ },+ },+ });++ if (pendingInvite) {+ return NextResponse.redirect(+ new URL(`/${pendingInvite.project.slug}?invite=1`, req.url),+ );+ }++ // If user already has a workspace, redirect them away from onboarding+ // to their workspaces page instead of allowing them to create a new one+ const existingWorkspace = await prismaEdge.project.findFirst({+ where: {+ users: {+ some: {+ userId: user.id,+ },+ },+ },+ });++ if (existingWorkspace) {+ return NextResponse.redirect(new URL("/workspaces", req.url));+ }+ }}// otherwise, rewrite the path to /app