The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix new account creation flow via an invite
Kiran K1445aa4b7e3a
diff --git a/apps/web/lib/api/users.ts b/apps/web/lib/api/users.tsindex 6f6f724a9c..74a431e237 100644--- a/apps/web/lib/api/users.ts+++ b/apps/web/lib/api/users.ts@@ -49,7 +49,7 @@ export async function inviteUser({});const params = new URLSearchParams({- callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}`,+ callbackUrl: `${process.env.NEXTAUTH_URL}/${workspace.slug}?invite=true`,email,token,});diff --git a/apps/web/lib/middleware/app.ts b/apps/web/lib/middleware/app.tsindex 73c2c1d538..1a7260f96f 100644--- a/apps/web/lib/middleware/app.ts+++ b/apps/web/lib/middleware/app.ts@@ -7,6 +7,7 @@ import { getUserViaToken } from "./utils/get-user-via-token";export default async function AppMiddleware(req: NextRequest) {const { path, fullPath, searchParamsString } = parse(req);const user = await getUserViaToken(req);+ const isWorkspaceInvite = req.nextUrl.searchParams.get("invite");// if there's no user and the path isn't /login or /register, redirect to /loginif (@@ -34,7 +35,9 @@ export default async function AppMiddleware(req: NextRequest) {user.createdAt &&new Date(user.createdAt).getTime() > Date.now() - 10000 &&// here we include the root page + /new (since they're going through welcome flow already)- path !== "/welcome"+ path !== "/welcome" &&+ // if the user was invited to a workspace, don't show the welcome page+ !isWorkspaceInvite) {return NextResponse.redirect(new URL("/welcome", req.url));