Can i pass session in props ?
Unanswered
Indian mackerel posted this in #help-forum
Indian mackerelOP
hello i'm tring to make a requests to my supabase db but i need to create a client with the sessions of the user
and th picture is a function call by my backend
export default async function PrivatePage() {
const supabase = createClient({
headers,
cookies,
});and th picture is a function call by my backend
77 Replies
@Indian mackerel hello i'm tring to make a requests to my supabase db but i need to create a client with the sessions of the user
js
export default async function PrivatePage() {
const supabase = createClient({
headers,
cookies,
});
and th picture is a function call by my backend
yes, you can pass session data as props
@B33fb0n3 yes, you can pass session data as props
Indian mackerelOP
have you an exemple ?
@Indian mackerel have you an exemple ?
yea:
Like this you can pass your serverside session directly to the client
import MyClientComponent from "@/app/MyClientComponent";
export default function MyServerComponent() {
const session = await getServerSession(authOptions);
return <div className={"w-full border-2 border-blue-500 border-dashed"}>
<p>Server Component</p>
<MyClientComponent session={session}/>
</div>
}Like this you can pass your serverside session directly to the client
but
i give to my function the cookies and the header of the user sessions
but he respond me again a void array
but he respond me again a void array
in second i tried to return juste the role of the user and he return a void table too
i think it's beacause i don't realy understand how the header and cookies function
@Indian mackerel Click to see attachment
Can you try getting the header and cookies inside your backend function, via „cookies()“ and „headers()“ function? Also instead of updating stuff, can you first log the current user with his current session?
@B33fb0n3 Can you try getting the header and cookies inside your backend function, via „cookies()“ and „headers()“ function? Also instead of updating stuff, can you first log the current user with his current session?
Indian mackerelOP
yes when i tried to console.log like in the two first line
the code return this
and the user is connected
on this 'main page' the user is connected
and i give the header and cookies to the Modal button
and the modal call the function
and he call this function
@B33fb0n3 Can you try getting the header and cookies inside your backend function, via „cookies()“ and „headers()“ function? Also instead of updating stuff, can you first log the current user with his current session?
Indian mackerelOP
and i don't understand why i can't request my db with all the info
Call the headers and cookies in the serverside function please. Let’s see if that works. There is no need why the nodal need to know about these headers and cookies
@B33fb0n3 Call the headers and cookies in the serverside function please. Let’s see if that works. There is no need why the nodal need to know about these headers and cookies
Indian mackerelOP
srry i'm beggining next js and i don't know how i can make this ?
like , how i can call the header and the cookies in the serverside function
@Indian mackerel srry i'm beggining next js and i don't know how i can make this ?
you can do this like you already done on your
So instead of passing the values around, get them directly in your function: (see attached picture 2).
Then fetch your current user, like you done on your
PrivatePage: (see attached).So instead of passing the values around, get them directly in your function: (see attached picture 2).
Then fetch your current user, like you done on your
PrivatePage: (see attached picture 3). Then log this user. Do you see the result?@Indian mackerel like this ?
yes, now console.log the active session. Do you see that there is a user?
Indian mackerelOP
no , the sessions is void
@Indian mackerel Click to see attachment
is there a 'use server' on top of the file where the
updateUser is?@B33fb0n3 is there a 'use server' on top of the file where the updateUser is?
Indian mackerelOP
nop
@Indian mackerel nop
add it
Indian mackerelOP
it's good
Indian mackerelOP
same
and you have a valid session, right?
@B33fb0n3 and you have a valid session, right?
Indian mackerelOP
yes
in the private pagfe i have a good sessions
Indian mackerelOP
no from the update user
Indian mackerelOP
yes i think
Can you verify that please?
@B33fb0n3 So if we match the colors, the correct color is for the correct log part, right?
Indian mackerelOP
like this ?
@Indian mackerel like this ?
nah, remove every console.log and only log
headers and cookies and session. Or add some text to your console.log, so you can identify them@Indian mackerel like this ?
Yea, it's a good beginning. More like this:
console.log("some unique string", cookiesStore)
console.log("this string must be unique like you did", headerstore)
// ...@Indian mackerel i thinks it's good
now log it and see what you get
Which of my messages has solved this problem? XD
@B33fb0n3 Which of my messages has solved this problem? XD
Indian mackerelOP
the last
but can we call for exemplain you x)
hm? 🤔
Indian mackerelOP
okay
i just a bad error with supabase
x)
not my code
x)))))
i'm acousthique
I am so confused right now
Indian mackerelOP
you wan't an explaination x)
@Indian mackerel ?
@B33fb0n3 <@792076403566051328> ?
Indian mackerelOP
AH YES SRRY
in the try and catch the first condition have a problèm
and therefore the function could not launch
@Indian mackerel and therefore the function could not launch
but we saw the console.logs... when they are executed the funciton exectued as well 🤔
