Next.js Discord

Discord Forum

Can i pass session in props ?

Unanswered
European anchovy posted this in #help-forum
Open in Discord
European anchovyOP
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

export default async function PrivatePage() {
  const supabase = createClient({
    headers,
    cookies,
  });


and th picture is a function call by my backend

77 Replies

@B33fb0n3 yes, you can pass session data as props
European anchovyOP
have you an exemple ?
@European anchovy have you an exemple ?
yea:
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
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
@European anchovy 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?
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
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
like , how i can call the header and the cookies in the serverside function
@European anchovy 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 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?
@European anchovy like this ?
yes, now console.log the active session. Do you see that there is a user?
European anchovyOP
no , the sessions is void
@European anchovy Click to see attachment
is there a 'use server' on top of the file where the updateUser is?
@European anchovy nop
add it
European anchovyOP
it's good
🤔
European anchovyOP
same
and you have a valid session, right?
@B33fb0n3 and you have a valid session, right?
European anchovyOP
yes
in the private pagfe i have a good sessions
@European anchovy in the private pagfe i have a good sessions
this is from private page?
European anchovyOP
no from the update user
So if we match the colors, the correct color is for the correct log part, right?
European anchovyOP
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?
European anchovyOP
like this ?
@European anchovy 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
@B33fb0n3 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
European anchovyOP
like this ?
@European anchovy 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)
// ...
@European anchovy i thinks it's good
now log it and see what you get
@B33fb0n3 now log it and see what you get
European anchovyOP
it's good
!
but i don't now why
:kappa:
@European anchovy Click to see attachment
good job 👏
Which of my messages has solved this problem? XD
@B33fb0n3 Which of my messages has solved this problem? XD
European anchovyOP
the last
but can we call for exemplain you x)
hm? 🤔
European anchovyOP
okay
i just a bad error with supabase
x)
not my code
x)))))
i'm acousthique
I am so confused right now
European anchovyOP
you wan't an explaination x)
@European anchovy ?
@B33fb0n3 <@792076403566051328> ?
European anchovyOP
AH YES SRRY
in the try and catch the first condition have a problèm
and therefore the function could not launch
@European anchovy and therefore the function could not launch
but we saw the console.logs... when they are executed the funciton exectued as well 🤔