vicious-gold
vicious-gold2mo ago

Adding/using multiple supabase data providers

Is it possible to use multiple(two) supabase data providers with one being used as an authentication provider aswell. When trying to specify which data provider to use, refine seems to always default to the supabase client thats used for the auth even when I specify the correct data provider to use using the dataProviderName prop on the useTable hook and resource property
5 Replies
kapa.ai
kapa.ai2mo ago
Hi @Awelani. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to use multiple Supabase data providers in Refine, including one being used as an authentication provider. You can specify which data provider to use by utilizing the dataProviderName prop in your data hooks and components. Here is a step-by-step guide to achieve this: 1. Define Multiple Data Providers: You need to define multiple data providers in your Refine configuration. For example, you can have a default data provider and another one for specific resources.
const App = () => (
<Refine
dataProvider={{
default: defaultSupabaseDataProvider,
secondary: secondarySupabaseDataProvider,
}}
resources={[
{
// `default` data provider will be used for this resource
name: "posts",
},
{
name: "products",
// `secondarySupabaseDataProvider` data provider will be used for this resource
meta: { dataProviderName: "secondary" },
},
]}
/>
);

const App = () => (
<Refine
dataProvider={{
default: defaultSupabaseDataProvider,
secondary: secondarySupabaseDataProvider,
}}
resources={[
{
// `default` data provider will be used for this resource
name: "posts",
},
{
name: "products",
// `secondarySupabaseDataProvider` data provider will be used for this resource
meta: { dataProviderName: "secondary" },
},
]}
/>
);

2. Specify Data Provider in Hooks: When using data hooks, you can specify which data provider to use by passing the dataProviderName prop.
const { tableProps } = useTable({
dataProviderName: "secondary",
});

const { tableProps } = useTable({
dataProviderName: "secondary",
});

3. Authentication Provider: Ensure that your authentication provider is correctly set up and linked to the appropriate Supabase client.
import { AuthProvider } from "@refinedev/core";
import { supabaseClient } from "utility";

const authProvider: AuthProvider = {
login: async ({ email, password, providerName }) => {
// Authentication logic here
},
// Other auth methods...
};
const App = () => (
<Refine
authProvider={authProvider}
dataProvider={{
default: defaultSupabaseDataProvider,
secondary: secondarySupabaseDataProvider,
}}
resources={[
{
name: "posts",
},
{
name: "products",
meta: { dataProviderName: "secondary" },
},
]}
/>
);

import { AuthProvider } from "@refinedev/core";
import { supabaseClient } from "utility";

const authProvider: AuthProvider = {
login: async ({ email, password, providerName }) => {
// Authentication logic here
},
// Other auth methods...
};
const App = () => (
<Refine
authProvider={authProvider}
dataProvider={{
default: defaultSupabaseDataProvider,
secondary: secondarySupabaseDataProvider,
}}
resources={[
{
name: "posts",
},
{
name: "products",
meta: { dataProviderName: "secondary" },
},
]}
/>
);

4. Using Data Provider in Components: When using components like forms or tables, ensure you specify the correct data provider.
const { formProps } = useForm({
dataProviderName: "secondary",
});

const { formProps } = useForm({
dataProviderName: "secondary",
});

By following these steps, you should be able to use multiple Supabase data providers in your Refine application, with one being used for authentication and others for different resources. For more detailed information, you can refer to the following documentation: - Data Provider Usage (https://refine.dev/docs/data/data-provider/#usage-1) - useTable Hook (https://refine.dev/docs/data/hooks/use-many/#dataprovidername) - Auth Provider (https://refine.dev/docs/authentication/auth-provider/) If you encounter any issues, ensure that the dataProviderName is correctly specified and that the data providers are properly configured in your Refine setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1227314902184628346> kapa.ai is still learning and improving, please let us know how it did by reacting below
vicious-gold
vicious-gold2mo ago
So seems like the order in which the supabase client is created is what determines which supabase data provider is used @kapa.ai So seems like the order in which the supabase client is created is what determines which supabase data provider is used
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The order in which the Supabase client is created does not necessarily determine which Supabase data provider is used. Instead, you can explicitly specify which data provider to use by utilizing the dataProviderName prop in your data hooks and components. Here’s a detailed explanation and example to clarify: Step-by-Step Guide 1. Define Multiple Data Providers: You need to define multiple data providers in your Refine configuration. For example, you can have a default data provider and another one for specific resources.
import { Refine } from "@refinedev/core";
import { dataProvider as defaultDataProvider } from "@refinedev/supabase";
import { dataProvider as secondaryDataProvider } from "@refinedev/supabase";
import { supabaseClient as defaultSupabaseClient } from "./utility/defaultSupabaseClient";
import { supabaseClient as secondarySupabaseClient } from "./utility/secondarySupabaseClient";

const App = () => (
<Refine
dataProvider={{
default: defaultDataProvider(defaultSupabaseClient),
secondary: secondaryDataProvider(secondarySupabaseClient),
}}
resources={[
{
name: "posts",
},
{
name: "products",
meta: { dataProviderName: "secondary" },
},
]}
/>
);

export default App;

import { Refine } from "@refinedev/core";
import { dataProvider as defaultDataProvider } from "@refinedev/supabase";
import { dataProvider as secondaryDataProvider } from "@refinedev/supabase";
import { supabaseClient as defaultSupabaseClient } from "./utility/defaultSupabaseClient";
import { supabaseClient as secondarySupabaseClient } from "./utility/secondarySupabaseClient";

const App = () => (
<Refine
dataProvider={{
default: defaultDataProvider(defaultSupabaseClient),
secondary: secondaryDataProvider(secondarySupabaseClient),
}}
resources={[
{
name: "posts",
},
{
name: "products",
meta: { dataProviderName: "secondary" },
},
]}
/>
);

export default App;

2. Specify Data Provider in Hooks: When using data hooks, you can specify which data provider to use by passing the dataProviderName prop.
import { useTable } from "@refinedev/core";

const ProductsTable = () => {
const { tableProps } = useTable({
dataProviderName: "secondary",
});

return (
<Table {...tableProps}>
{/* Table content */}
</Table>
);
};

import { useTable } from "@refinedev/core";

const ProductsTable = () => {
const { tableProps } = useTable({
dataProviderName: "secondary",
});

return (
<Table {...tableProps}>
{/* Table content */}
</Table>
);
};

3. Authentication Provider: Ensure that your authentication provider is correctly set up and linked to the appropriate Supabase client.
import { AuthProvider } from "@refinedev/core";
import { supabaseClient as authSupabaseClient } from "./utility/authSupabaseClient";

const authProvider: AuthProvider = {
login: async ({ email, password, providerName }) => {
// Authentication logic here
},
// Other auth methods...
};

const App = () => (
<Refine
authProvider={authProvider}
dataProvider={{
default: defaultDataProvider(defaultSupabaseClient),
secondary: secondaryDataProvider(secondarySupabaseClient),
}}
resources={[
{
name: "posts",
},
{
name: "products",
meta: { dataProviderName: "secondary" },
},
]}
/>
);

export default App;

import { AuthProvider } from "@refinedev/core";
import { supabaseClient as authSupabaseClient } from "./utility/authSupabaseClient";

const authProvider: AuthProvider = {
login: async ({ email, password, providerName }) => {
// Authentication logic here
},
// Other auth methods...
};

const App = () => (
<Refine
authProvider={authProvider}
dataProvider={{
default: defaultDataProvider(defaultSupabaseClient),
secondary: secondaryDataProvider(secondarySupabaseClient),
}}
resources={[
{
name: "posts",
},
{
name: "products",
meta: { dataProviderName: "secondary" },
},
]}
/>
);

export default App;

4. Using Data Provider in Components: When using components like forms or tables, ensure you specify the correct data provider.
import { useForm } from "@refinedev/core";

const ProductForm = () => {
const { formProps } = useForm({
dataProviderName: "secondary",
});

return (
<Form {...formProps}>
{/* Form content */}
</Form>
);
};

import { useForm } from "@refinedev/core";

const ProductForm = () => {
const { formProps } = useForm({
dataProviderName: "secondary",
});

return (
<Form {...formProps}>
{/* Form content */}
</Form>
);
};

Conclusion By explicitly specifying the dataProviderName in your hooks and components, you can control which Supabase data provider is used, regardless of the order in which the Supabase clients are created. For more detailed information, you can refer to the following documentation: - Data Provider Usage (https://refine.dev/docs/data/data-provider/#usage-1) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1227314902184628346> kapa.ai is still learning and improving, please let us know how it did by reacting below