stuck-chocolate
stuck-chocolate17mo ago

Multitenant URLs

Hi all! Anyone have more info on how to provide props to the nextjs-router in v4? We are multitenant, so URL path will be /:tenantId/post/:id How do I provide a session specific tenantId to the router?
7 Replies
kapa.ai
kapa.ai17mo ago
Hey @jekedorff! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
kapa.ai
kapa.ai17mo ago
---------------------- In refine v4, you can define custom routes for your resources, which allows you to handle multi-tenant structures with ease. Here's an example of how you can define custom routes with tenantId in the URL path:
resources={[
{
name: "products",
list: "/:tenantId/products",
show: "/:tenantId/products/:id",
edit: "/:tenantId/products/:id/edit",
create: "/:tenantId/products/create",
},
]}
resources={[
{
name: "products",
list: "/:tenantId/products",
show: "/:tenantId/products/:id",
edit: "/:tenantId/products/:id/edit",
create: "/:tenantId/products/create",
},
]}
This is only a resource definition, which must be handled within the preferred router structure. The detail page of a product can have a nested structure and also supports additional parameters. These parameters can be passed along with the meta properties in such hooks and components. Existing parameters in the URL will also be used when constructing the navigation path. For more information, refer to the extract on multi-tenant structures (https://refine.dev/docs/migration-guide/3x-to-4x#resources). ----------------------
Migrating from 3.x.x to 4.x.x | refine
Motivation behind the release
kapa.ai
kapa.ai17mo ago
<@904809161366335489> kapa.ai is still learning and improving, please let us how it did by reacting below
fair-rose
fair-rose17mo ago
Hi @jekedorff , It's depend on your auth provider implementation. I think, you need to pass tenantId and user token to the your API. Then, you can use response in your check method in authProvider. I believe, you can inspire from our nextjs example: https://github.com/refinedev/refine/tree/next/examples/with-nextjs
stuck-chocolate
stuck-chocolate17mo ago
Thanks a lot. I already get the tenantId from my authProvider, it is just how to efficiently use it in routerProvider I do not understand. Can I add it as a general param to the routerProvider or do I have manually include it in my calls to push/replace ?
fair-rose
fair-rose17mo ago
You don’t need to handle for all situations. For example buttons have “meta” property for this. You can check out here: https://refine.dev/docs/api-reference/antd/components/buttons/show-button/#meta
Show | refine
uses Ant Design's component. It uses the show method from useNavigation under the hood. It can be useful when redirecting the app to the show page with the record id route of resource.
stuck-chocolate
stuck-chocolate17mo ago
Thanks a lot! The meta property in the various useNavigation functions was exactly what I was looking for. 👌