Knowledge Required
Closed this issue · 2 comments
irtaza9 commented
Please explain how you are handling sub-domain working. I checked this code block but I need a little bit context about it. Like how you are handling all the working of sub-domain creation.
const { data, error } = await supabase
.from("sites")
.insert([
{
user_id: userId,
site_name,
site_description,
site_subdomain: site_subdomain.toLowerCase(),
site_logo,
},
])
.select();
michaelshimeles commented
This stores the site information in the database. The database schema for sites is setup that only unique subdomains can be inserted, so if u trying to create a site with an already existing subdomain it will not allow it.
Once the subdomain is inserted in the db, all the redirect and url rewriting is done in the middleware
irtaza9 commented
I think you are talking about this? Wow, great idea. I was wondering how you are creating sub-domains for so many users. Applause 👏
if (tenantSubdomain) {
return NextResponse.rewrite(
new URL(`/${tenantSubdomain}${pathname}`, req.url)
);
}
// Rewrite the URL to the tenant-specific path
return NextResponse.rewrite(
new URL(tenantSubdomain === "/" ? "" : `tsafi.xyz`, req.url)
);