File tree Expand file tree Collapse file tree
app/api/workspaces/[idOrSlug]/exists
packages/utils/src/constants Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { withSession } from "@/lib/auth" ;
22import { prisma } from "@dub/prisma" ;
3- import { DEFAULT_REDIRECTS , RESERVED_KEYS } from "@dub/utils" ;
3+ import { DEFAULT_REDIRECTS , RESERVED_SLUGS } from "@dub/utils" ;
44import { NextResponse } from "next/server" ;
55
66// GET /api/workspaces/[idOrSlug]/exists – check if a project exists
77export const GET = withSession ( async ( { params } ) => {
88 const { idOrSlug : slug } = params ;
9- if ( RESERVED_KEYS . includes ( slug ) || DEFAULT_REDIRECTS [ slug ] ) {
9+ if ( RESERVED_SLUGS . includes ( slug ) || DEFAULT_REDIRECTS [ slug ] ) {
1010 return NextResponse . json ( 1 ) ;
1111 }
1212 const project = await prisma . project . findUnique ( {
Original file line number Diff line number Diff line change 66 DEFAULT_REDIRECTS ,
77 isDubDomain ,
88 isReservedKeyGlobal ,
9- RESERVED_KEYS ,
9+ RESERVED_SLUGS ,
1010} from "@dub/utils" ;
1111
1212export async function keyChecks ( {
@@ -43,7 +43,7 @@ export async function keyChecks({
4343
4444 if ( isDubDomain ( domain ) && process . env . NEXT_PUBLIC_IS_DUB ) {
4545 if ( domain === "dub.sh" || domain === "dub.link" ) {
46- if ( DEFAULT_REDIRECTS [ key ] || RESERVED_KEYS . includes ( key ) ) {
46+ if ( DEFAULT_REDIRECTS [ key ] || RESERVED_SLUGS . includes ( key ) ) {
4747 return {
4848 error : "Duplicate key: This short link already exists." ,
4949 code : "conflict" ,
Original file line number Diff line number Diff line change 1- import { RESERVED_KEYS } from "@dub/utils" ;
1+ import { RESERVED_SLUGS } from "@dub/utils" ;
22
33const APP_REDIRECTS = {
44 "/account" : "/account/settings" ,
@@ -13,7 +13,7 @@ export const appRedirect = (path: string) => {
1313 }
1414 // Redirect "/[slug]" to "/[slug]/links"
1515 const rootRegex = / ^ \/ ( [ ^ \/ ] + ) $ / ;
16- if ( rootRegex . test ( path ) && ! RESERVED_KEYS . includes ( path . split ( "/" ) [ 1 ] ) )
16+ if ( rootRegex . test ( path ) && ! RESERVED_SLUGS . includes ( path . split ( "/" ) [ 1 ] ) )
1717 return path . replace ( rootRegex , "/$1/links" ) ;
1818
1919 // Redirect "programs/[programId]/settings" to "programs/[programId]/settings/rewards" (first tab)
Original file line number Diff line number Diff line change 11import z from "@/lib/zod" ;
2- import { DEFAULT_REDIRECTS , RESERVED_KEYS , validSlugRegex } from "@dub/utils" ;
2+ import { DEFAULT_REDIRECTS , RESERVED_SLUGS , validSlugRegex } from "@dub/utils" ;
33import slugify from "@sindresorhus/slugify" ;
44import { DomainSchema } from "./domains" ;
55import { planSchema , roleSchema } from "./misc" ;
@@ -133,9 +133,12 @@ export const createWorkspaceSchema = z.object({
133133 . max ( 48 , "Slug must be less than 48 characters" )
134134 . transform ( ( v ) => slugify ( v ) )
135135 . refine ( ( v ) => validSlugRegex . test ( v ) , { message : "Invalid slug format" } )
136- . refine ( async ( v ) => ! ( RESERVED_KEYS . includes ( v ) || DEFAULT_REDIRECTS [ v ] ) , {
137- message : "Cannot use reserved slugs" ,
138- } ) ,
136+ . refine (
137+ async ( v ) => ! ( RESERVED_SLUGS . includes ( v ) || DEFAULT_REDIRECTS [ v ] ) ,
138+ {
139+ message : "Cannot use reserved slugs" ,
140+ } ,
141+ ) ,
139142 logo : z . string ( ) . optional ( ) ,
140143 conversionEnabled : z . boolean ( ) . optional ( ) ,
141144} ) ;
Original file line number Diff line number Diff line change @@ -15,5 +15,5 @@ export * from "./misc";
1515export * from "./plan-compare" ;
1616export * from "./pricing" ;
1717export * from "./regions" ;
18- export * from "./reserved-keys " ;
18+ export * from "./reserved-slugs " ;
1919export * from "./saml" ;
Original file line number Diff line number Diff line change 44 * - cannot be used as a workspace slug
55 */
66
7- export const RESERVED_KEYS = [
7+ export const RESERVED_SLUGS = [
88 "va" ,
99 "static" ,
1010 "stats" ,
@@ -48,4 +48,8 @@ export const RESERVED_KEYS = [
4848 "wrapped" ,
4949 "invoices" ,
5050 "onboarding" ,
51+ "programs" ,
52+ "partners" ,
53+ "payouts" ,
54+ "resources" ,
5155] ;
You can’t perform that action at this time.
0 commit comments