how to use getServerSession inside onclick server action

I am trying to call getServerSession inside onClick and it's not working can anyone have answer to this how can we call getServerSession inside server action which is used inside onClick
export async function Example() {
const session = await getServerSession(authOption);
console.log(session);
}
export async function Example() {
const session = await getServerSession(authOption);
console.log(session);
}
export default function Page() {
return <div onClick={() => Example()}>hello</div>;
}
export default function Page() {
return <div onClick={() => Example()}>hello</div>;
}
3 Replies
pradeep
pradeepOP2y ago
error
Error: Invariant: Method expects to have requestAsyncStorage, none available
error
Error: Invariant: Method expects to have requestAsyncStorage, none available
Aland
Aland2y ago
onClick can't be used on server components. make the component a client component and then fetch the data onClick
Maj
Maj2y ago
if you use "server" u cannot use events from the frontend window so the best way is to fetch from tthe api like Aland said
Want results from more Discord servers?
Add your server