Support Forums

Share Code between each function (for jwt authentication)

I am coming from aws lambda where we generally have full control over the function and api gateway

How can I authenticate each of my function before execution? The client passes a bearer token in the headers. I could write a auth script for each function, but if I have 30+ functions, that would be a mess and it would make sense to separate business logic and auth logic

I know that functions are independent of each other, but it seems that all of my functions will need some kind of initialization such as a CORS setting and a AUTH script.

I guess the same question applies to all cloud functions like vercel/netlify/cloudflare etc, where there isn’t a api gateway to manage them.

Any suggestion where i can write code once that will cover all my functions?


Hey @Rishi_Uttam,
Do you think our signed proxy redirects for your use case? Here’s a thread where they’re being discussed:

And our docs:

Thanks. I would still need to write auth logic from the context to check if the token is valid or not. maybe not as much but still need to do it for many end points. hope Netlify can implement an api gateway.

I understand and we’ll keep that concern in mind.

Just for clarification, we already do have our own API gateway. It’s just not identical to AWS’s API gateway.

Hopefully the reduced code is enough to meet your needs for now.

Any suggestion where i can write code once that will cover all my functions?

I do this in my app (require an auth script in all my Netlify functions).

Not sure if it fits your use-case, but sharing it in case it helps someone.