Is it possible to access Request in action?

const myAction = action(async (data: FormData) => {
"use server";
// can I access Request here?
// to extract request url, cookies and so on?
console.log(Object.fromEntries(data));
return "ok";
}, "save");

export default function SomeRoute() {
return (
<form method="post" action={myAction}>
<input name="example" />
<button type="submit">Submit</button>
</form>
);
}
const myAction = action(async (data: FormData) => {
"use server";
// can I access Request here?
// to extract request url, cookies and so on?
console.log(Object.fromEntries(data));
return "ok";
}, "save");

export default function SomeRoute() {
return (
<form method="post" action={myAction}>
<input name="example" />
<button type="submit">Submit</button>
</form>
);
}
5 Replies
peerreynders
peerreynders9mo ago
You can use getRequestEvent()
peerreynders
peerreynders9mo ago
When event.request doesn't have what you need look at event.nativeEvent which is an H3Event where you can find things like event.nativeEvent.node (when applicable).
Event Object - h3
Event object carries an incoming request and context.
Nycheporuk
NycheporukOP9mo ago
Thanks) It would be great to put this info somewhere in documentation
Nycheporuk
NycheporukOP9mo ago
thanks)
Want results from more Discord servers?
Add your server