IdoPesok / zsa

https://zsa.vercel.app
MIT License
436 stars 13 forks source link

Cannot access request when creating a procedure #147

Closed mikerudge closed 1 week ago

mikerudge commented 1 week ago

I am checking if the request has come from a certain IP address. However, when creating a procedure, the request is always undefined even though it is typed to be available.

createServerActionProcedure().handler(
    async ({ request }) => {
        if (!request) {
            console.log('no request')
            throw new ZSAError('NOT_AUTHORIZED')
        }
mikerudge commented 1 week ago

I should add I am on

"zsa": "^0.4.0"
IdoPesok commented 1 week ago

Hi, request will only be defined if you are using our openapi library.

The type you are seeing should be:

request: NextRequest | undefined
// a request object if the action is run from an Open API route createOpenApiServerActionRouter

To get the IP address, try this: https://nextjs.org/docs/app/api-reference/functions/headers#ip-address. Let me know if that works!

IdoPesok commented 1 week ago

Closing this issue for now, if the Next docs didn't fix it happy to reopen.