helpful-purple
helpful-purple6mo ago

REST client uses resource name instead of what's set for list for getList requests

I’ve been following the tutorial on multitenancy Multitenancy Imagine a SAAS app sending emails where the root is a list of organisations and each organisations can have email accounts assigned using SMTP. My issue is that navigating to list smtp navigates to the right path in my refine app, but the REST API call to my backend is https://myapi.com/smtp instead of https://myapi.com/organization/1234/smtp.
I have the rest client swizzled, and getList: async ({ resource, pagination, filters, sorters, meta }) returns smtp instead of /organization/:organizationId/smtp as resource param. Show/edit/… seems to work fine, seems to be happening just for list requests. Just wanted to confirm that I’m doing something wrong before filing a bug report. This is my resources:
resources={[
{
name: "organization",
list: "/organization",
create: "/organization/create",
edit: "/organization/edit/:id",
show: "/organization/:id",
meta: {
canDelete: true
},
},
{
name: "smtp",
list: "/organization/:organizationId/smtp",
create: "/organization/:organizationId/smtp/create",
edit: "/organization/:organizationId/smtp/edit/:id",
show: "/organization/:organizationId/smtp/:id",
meta: {
canDelete: true,
organizationId
},
},
// ......
resources={[
{
name: "organization",
list: "/organization",
create: "/organization/create",
edit: "/organization/edit/:id",
show: "/organization/:id",
meta: {
canDelete: true
},
},
{
name: "smtp",
list: "/organization/:organizationId/smtp",
create: "/organization/:organizationId/smtp/create",
edit: "/organization/:organizationId/smtp/edit/:id",
show: "/organization/:organizationId/smtp/:id",
meta: {
canDelete: true,
organizationId
},
},
// ......
Multitenancy | refine
Refine's architecture allows you to customize your app's data providers, access control and routing to support multi tenant features easily. This guide will provide you with a high level overview of the concepts and how to implement them. To see multi tenant app examples, check out the Examples section.
3 Replies
kapa.ai
kapa.ai6mo ago
Hi @petr4990. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, it seems like you have correctly defined your resources and routes. However, the issue you're facing might be due to how the getList method is being invoked. In refine, the getList method in the data provider receives the resource parameter, which is the name of the resource. In your case, it seems like it's receiving smtp instead of /organization/:organizationId/smtp. This might be because the getList method is not aware of the custom route you've defined for the smtp resource. One way to handle this could be to swizzle the data provider and modify the getList method to handle the custom route. You can check out the swizzle data provider guide (https://refine.dev/docs/packages/list-of-packages/#swizzle) for more information. Here's an example of how you might modify the getList method:
getList: async ({ resource, pagination, filters, sorters, meta }) => {
let url;
if (resource === 'smtp' && meta.organizationId) {
url = `/organization/${meta.organizationId}/smtp`;
} else {
url = `/${resource}`;
}
// ... rest of your getList implementation
};
getList: async ({ resource, pagination, filters, sorters, meta }) => {
let url;
if (resource === 'smtp' && meta.organizationId) {
url = `/organization/${meta.organizationId}/smtp`;
} else {
url = `/${resource}`;
}
// ... rest of your getList implementation
};
In this example, if the resource is smtp and organizationId is available in meta, it constructs the URL as /organization/:organizationId/smtp. Otherwise, it uses the resource name as the URL. Please note that this is a general suggestion and might need to be adjusted based on your specific implementation and requirements. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6mo ago
<@356390195681296387> kapa.ai is still learning and improving, please let us know how it did by reacting below
helpful-purple
helpful-purple6mo ago
@kapa.ai So dataProvider does not use list property of a resource?