-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rewrites and upserts for gateway.new
- Loading branch information
Showing
5 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* This route creates a shortcut for onboarding | ||
* | ||
* We need this for compliance of our gateway.new domain. | ||
* 1. A user will enter "gateway.new" in the browser | ||
* 2. Vercel will detect the host and rewrite the request to this page | ||
* 3. A workspace is upserted | ||
* 4. The user is redirected to create their API | ||
*/ | ||
|
||
import { getTenantId } from "@/lib/auth"; | ||
import { db, schema } from "@/lib/db"; | ||
import { newId } from "@unkey/id"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default async function Page() { | ||
const tenantId = getTenantId(); | ||
|
||
const ws = await db.query.workspaces.findFirst({ | ||
where: (table, { eq, isNull, and }) => | ||
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)), | ||
}); | ||
|
||
if (!ws) { | ||
await db.insert(schema.workspaces).values({ | ||
id: newId("workspace"), | ||
name: "Personal Workspace", | ||
tenantId, | ||
betaFeatures: {}, | ||
features: {}, | ||
}); | ||
} | ||
|
||
return redirect("/apis?new=true"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters