Comments (9)
I was having a similar issue, I was able to fix it by ensuring that my createClient() statements are within the functions of my code. For example, your actions.ts should be updated to the below:
Actions.ts
"use server"
import { createClient } from "@/utils/supabase/server";
export async function getLatestProjects() {
const supabase = createClient();
let { data: projects, error } = await supabase
.from('new_projects')
.select('*')
.order('end_date', { ascending: false })
.limit(10);
if (error) throw error;
return projects;
}
from next.js.
can confirm that the problem is in fact usage of createClient() out of function scope aka usage as global variable.
from next.js.
I am also facing same issue, have you been able to resolve this problem?
from next.js.
hmm i am also getting the same error when using supabase/server.ts
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'
export function createClient() {
const cookieStore = cookies()
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll()
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options),
)
},
},
},
)
}
It happens when i am making a stripe webhook call and want to save user's data in supabase, it is working fine it i directly use supabase
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
)
from next.js.
I have encountered the same problem.
What is strange this problem occurs with me only on a specific route. On other route pages where I have basically almost identical logic the problem does not occur.
Interestingly - With the same code, a week ago, everything worked. Isn't this a problem maybe with Supabase?
I'm using Next 14.2.3
Problem occurs on local server - npm run dev
from next.js.
I have encountered the same problem. What is strange this problem occurs with me only on a specific route. On other route pages where I have basically almost identical logic the problem does not occur.
Interestingly - With the same code, a week ago, everything worked. Isn't this a problem maybe with Supabase?
I'm using Next
14.2.3
Problem occurs on local server -npm run dev
Interesting, I haven't had the issue in dev so far, just the build step. Which I needed to work in order to build a docker container for hosting but also would assume I would get errors if I pushed to Vercel or others.
I'm on 14.2.4 but when i started this project I think it was 14.2.1. As well, I have used both NPM and Bun, with and without turbopack enabled.
from next.js.
I was having a similar issue, I was able to fix it by ensuring that my createClient() statements are within the functions of my code. For example, your actions.ts should be updated to the below:
Actions.ts
"use server" import { createClient } from "@/utils/supabase/server"; export async function getLatestProjects() { const supabase = createClient(); let { data: projects, error } = await supabase .from('new_projects') .select('*') .order('end_date', { ascending: false }) .limit(10); if (error) throw error; return projects; }
Hmm, this makes sense. Prior to posting here I did run a bunch of google searches and the only thread or mention I could find did talk about making sure my cookies()
call was inside my function. But I was not directly using that anywhere in my app. However I didn't think about that pass down of the cookies that are called in the supabase client.
I will give this a shot, I did already find a workaround of sorts. I just moved all the calls to my Page.tsx component rather than refactoring to the actions file. This works but was still puzzled as to why a pattern I have used everywhere else seemingly was not allowed?
Thanks for the suggestion! I will update if that works for me.
from next.js.
Ok I also fixed my problem
Here is how my action.ts
looks like now
"use server";
import { createClient } from "@/utils/supabase/server";
export async function getAllClients() {
const supabase = createClient();
const { data } = await supabase.from("profiles").select();
return data ?? [];
}
export async function getSpecificClient(clientId: string) {
const supabase = createClient();
const { data } = await supabase
.from("profiles")
.select()
.eq("id", clientId)
.single();
return data;
}
In a previous version of this file, I declared const supabase = createClient()
once right after importing the file.
Unfortunately, the initialization of the supabase has to be done separately inside each exported function. I don't like such duplication of code π’
from next.js.
yea the soln is just to find any where you called createClient that is not inside a function , dont call your createClient in a global scope
from next.js.
Related Issues (20)
- Docs: Text content does not match server-rendered HTML HOT 5
- Docs: definition of ServerComponent HOT 4
- RSC request prevent on prefetch false HOT 1
- RSC request prevent on prefetch false HOT 3
- Document not defined, NextJS cant throw traces HOT 1
- Global error not working if triggered in sub-path in version 13.5.5
- Wrong generated favico metada links HOT 1
- notFound() does not replace robots tag HOT 1
- Web workers do not work when runtime is edge HOT 4
- Google Analytics package in @next/third-parties/google doesn't track data if multiple GA4 streams are added HOT 1
- Docs: `pages/optimizePackageImports` points at `compress` instead HOT 3
- Loading.tsx files dont works with nested routes
- Unable to Fetch Data from Backend Server in Next.js SSR Production with Docker HOT 2
- with-next-translate example broken (html, body missing in layout; 404 pages)
- Stale search parameters when using an anchor/fragment in the `as` property of `Link`
- Docs: ε¨next14.2.5ηζ¬δΈοΌζδΉηε¬θ·―η±ηηεε HOT 1
- Response.redirect with relative URLs not working for Route Handlers HOT 1
- Error: Automatic publicPath is not supported in this browser
- Form error with server action on route change HOT 2
- Gravatar Error On Build HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.