marmelab / ra-supabase

Supabase adapter for react-admin, the frontend framework for building admin applications on top of REST/GraphQL services.
MIT License
156 stars 27 forks source link

Error: No API key found in request #34

Closed mrigo closed 9 months ago

mrigo commented 1 year ago

Hi, I can't connect to supabase because the api key isn't passed in the request headers.

// supabase.js
import { createClient } from '@supabase/supabase-js';

export const supabase = createClient(import.meta.env.VITE_SUPABASE_BASE_URL, import.meta.env.VITE_SUPABASE_ANON_KEY);

// dataProvider.js
import { supabaseDataProvider } from 'ra-supabase-core';
import { supabase } from './supabase';

const data = {
    instanceUrl: import.meta.env.VITE_SUPABASE_BASE_URL,
    apiKey: import.meta.env.VITE_SUPABASE_ANON_KEY,
    supabaseClient: supabase
}

export const dataProvider = supabaseDataProvider(data);

// App.jsx

import * as React from "react";
import { Admin, Resource, ListGuesser } from 'react-admin';
import { dataProvider } from "./provider/dataProvider";

const App = () => (
    <Admin dataProvider={dataProvider}>
        <Resource name="countries" list={ListGuesser} />
    </Admin>
);

export default App;

I've logged the anon key and is correctly passed. I've checked the network request, using plain supabase-js the apikey is passed, but with the dataprovider the apikey isn't in the request.

Thanks

slax57 commented 1 year ago

Hi, I see nothing wrong with your code. But it seems very close to the code from our demo app, which does not have this issue AFAIK. Did you try with the demo app? Do you reproduce the issue there?

davidpelissier commented 1 year ago

Same issue in my case. I tried also with demo app code.

slax57 commented 1 year ago

@davidpelissier Not sure I understand, did you try the demo app hooked up to your (remote) supabase instance, or with the provided local supabase instance? If you are using the local instance, did you change anything in the code or in the supabase settings? Can you provide more info to help us reproduce and debug the issue, like e.g. network traces? Thanks

marques576 commented 1 year ago

@mrigo have you found any solution? I have the same error in next js. It is not adding 'apikey' to the request headers

marques576 commented 1 year ago

I apologise for the poor file structure but the apiKey is not being included in the headers of the request image image image image

costicraciunescu commented 11 months ago

Nott sure if I read the code correctly but it seems that the apiKey is set only when there's an autheticated supabase session

dataProvider.ts

image

djhi commented 11 months ago

Indeed, we should always pass the provided key. Thanks for the report!

Revarh commented 10 months ago

I have the same error which is problematic.