-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next 13 example (app/ Directory) #340
Comments
@wiesson would you be able to provide your code and screenshots of the errors you were seeing? I'm working on an example now, but it would be helpful to understand how you approached this and what errors you experienced. Thanks. |
import { use } from "react";
import { createClient } from "@supabase/supabase-js";
const supabaseServer = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL as string,
process.env.SUPABASE_SERVICE_KEY as string
);
async function getData() {
const { data } = await supabase
.from("bookings_booking")
.select("*")
.order("created_at", { ascending: false });
return data;
}
export default function Page() {
const bookings = use(getData());
return (
<div>
{bookings((item) => (
<div key={item.id}>{item.title}</div>
))}
</div>
);
} Error
I tried to monkey-patch node-fetch to version 3.X but then I got ESM Import errors. What works (kind of) const fetch = (...args) =>
import("node-fetch").then(({ default: fetch }) => fetch(...args));
const supabaseServer = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL as string,
process.env.SUPABASE_SERVICE_KEY as string,
{
global: {
fetch,
},
}
); I still get the error, but I also get data. I assume that server rendering fails but FE can fetch it |
@wiesson this is working fine for me // /app/nextjs-13/client-component/page.tsx
import { use } from 'react';
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL as string,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY as string
);
async function getData() {
const { data } = await supabase.from('users').select('*');
return data;
}
export default function Page() {
const data = use(getData());
return <pre>{JSON.stringify(data, null, 2)}</pre>;
} With the following versions "dependencies": {
"@supabase/supabase-js": "^2.0.4",
"eslint-config-next": "^13.0.0",
"next": "^13.0.0",
"react": "18.2.0",
"react-dom": "18.2.0"
}, What versions are you using? |
Also note that you should not use |
It was just for testing purposes - I'm trying to find if it runs on the client or on the server. I still have the same issues as mentioned initially. Even if I directly copy your example: "dependencies": {
"@supabase/supabase-js": "^2.0.4",
"next": "13.0.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "18.11.5",
"@types/react": "18.0.23",
"eslint": "8.26.0",
"eslint-config-next": "13.0.0",
"typescript": "4.8.4"
} node LTS (v16.18.0) |
@wiesson any chance your code is available on GitHub somewhere? I'm currently not able to reproduce this. You can find my code here: https://github.com/supabase/auth-helpers/pull/342/files |
Thanks for the repo! I'll test it. https://github.com/wiesson/supabase-next-13
I saw that you explicitly called your route "client-component" but I can't see a "use client" - how do you know that it will be only loaded client-side? I suspect that you won't have any fetch errors because supabase will use the native browser fetch instead 🤔 |
I'm missing it because the guide as well as your snippet above aren't using it https://beta.nextjs.org/docs/data-fetching/fetching#example-fetch-and-use-in-client-components. Refactoring now. In the guide it does however say:
|
Based on https://beta.nextjs.org/docs/data-fetching/fetching#example-fetch-and-use-in-client-components it sounds like It does work fine when adding |
@wiesson I'm able to reproduce the warning with your repo, but it should be safe to ignore as it's an optional dependency in Therefore should be safe to ignore, but nonetheless, I've filed it here: supabase/supabase-js#612 Thanks for the report! |
Feature request
Next 13 has been released https://nextjs.org/blog/next-13#layouts and a new app structure with data fetching has been introduced (currently in beta).
Is your feature request related to a problem? Please describe.
I tried to adapt but I got errors on server side that the supabase client has problem with the polyfilled fetch provided by next.
Describe the solution you'd like
Just a minimal working example would be nice :)
The text was updated successfully, but these errors were encountered: