# Serverless Node.js JWT validation

**URL:** <https://community.auth0.com/t/serverless-node-js-jwt-validation/60378>\
**Category:** Get Help\
**Tags:** jwt, jwt-validation, serverside, token-validation, auth0\
**Created:** [March 31, 2021, 5:00pm UTC](https://community.auth0.com/t/serverless-node-js-jwt-validation/60378 "2021-03-31T17:00:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![benmarsden](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmarsden/32/28495_2.png) [@benmarsden](https://community.auth0.com/u/benmarsden)\
**Post date:** [March 31, 2021, 5:00pm UTC](https://community.auth0.com/t/serverless-node-js-jwt-validation/60378/1 "2021-03-31T17:00:32Z")

</div>

- **Which SDK this is regarding:** e.g. auth0-react
- **SDK Version:** 1.4.0
- **Platform Version:** Node 15

Hey! I am looking for some advice regarding auth0-react server-side usage. I have a simple nextjs application that interacts with an API provided by node.js AWS Lambda functions. Generally, I’ve seen the `getAccessTokenSilently` as an effective way to [call an API](https://github.com/auth0/auth0-react#call-an-api). However, what’s not quite clear to me is a clear way to validate the JWT token received server-side.

I think what I’m basically looking for is auth0-react’s equivalent to nextjs-auth0’s [WithApiAuthRequired](https://auth0.github.io/nextjs-auth0/modules/helpers_with_api_auth_required.html). In other words, it’d be really nice to wrap an API route with a JWT validator. Unfortunately, I don’t believe I can use nextjs-auth0 because I also want to support non-browser (CLI) requests, and from my understanding, nextjs-auth0 is entirely session-based.

Another approach would be like how next-auth.js offers [jwt.getToken](https://next-auth.js.org/configuration/options#jwt-helper), which verifies and decrypts the JWT token received as a bearer token. I’m not sure if it’s possible to reuse this, perhaps? My initial attempt failed, but I suspect that may have been caused by this [opaqueness](https://community.auth0.com/t/auth0-angular-access-tokens-are-not-jwts/52945).

I’ve also seen other approaches like using the [`express-jwt` library](https://github.com/auth0/auth0-react/blob/master/examples/users-api/server.js). However, from my understanding, this would not work in a serverless context.

Is there a common approach for this out there? How are others solving this usecase?

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2021, 7:37pm UTC](https://community.auth0.com/t/serverless-node-js-jwt-validation/60378/3 "2021-03-31T19:37:21Z")

</div>

Hi @benmarsden,

Welcome to the Community!

If you are simply looking to verify a token signature in node you could use the [node-jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) library.

AWS also has built in JWT authorizers which make it very easy to attach to an API. We have a blog post that runs through the whole setup with Auth0. [Securing AWS HTTP APIs with JWT Authorizers](https://auth0.com/blog/securing-aws-http-apis-with-jwt-authorizers/).

Let me know if you have any questions.

---

<div class="post-metadata">

**Author:** ![benmarsden](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmarsden/32/28495_2.png) [@benmarsden](https://community.auth0.com/u/benmarsden)\
**Post date:** [April 1, 2021, 3:08pm UTC](https://community.auth0.com/t/serverless-node-js-jwt-validation/60378/4 "2021-04-01T15:08:09Z")

</div>

Hi Dan,

I’m pretty sure wrapping the functionality from [node-jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) into a nextjs API route middleware will do the job perfectly. Appreciate the quick help on this!

Cheers,  
Ben

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 1, 2021, 3:55pm UTC](https://community.auth0.com/t/serverless-node-js-jwt-validation/60378/5 "2021-04-01T15:55:23Z")

</div>

Let us know if you have any questions along the way.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 16, 2021, 3:55pm UTC](https://community.auth0.com/t/serverless-node-js-jwt-validation/60378/6 "2021-04-16T15:55:56Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
