# Using Auth0-React SDK with Lambda

**URL:** <https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697>\
**Category:** Get Help\
**Tags:** auth0-react, reactjs, aws, lambda\
**Created:** [November 23, 2020, 12:25pm UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697 "2020-11-23T12:25:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![markm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/markm/32/12776_2.png) [@markm](https://community.auth0.com/u/markm)\
**Post date:** [November 23, 2020, 12:25pm UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/1 "2020-11-23T12:25:01Z")

</div>

The Auth0-React SDK seems to simplify what is the fairly complicated process of setting up OAuth inside a React application.

The tutorials that exist show how to setup the React side, but following [this tutorial](https://auth0.com/blog/complete-guide-to-react-user-authentication/#Calling-an-API) it links to various [backend quick starts](https://auth0.com/docs/quickstart/backend), of which Express is one.

However, there is nothing specifically for Lambda or other serverless approaches.

What is the intended use case here? Am I meant to setup a custom authorizer (like shown [here](https://auth0.com/docs/integrations/aws-api-gateway-custom-authorizers)) and have the React app target Lambdas that I attach to it? My understanding is the React-SDK will attach an `Authorization` header to each API request that the custom authorizer will verify.

But then what about refresh tokens? Silent token requests? How does the rest of the authorization code auth flow integrate into my serverless setup?

---

<div class="post-metadata">

**Author:** ![markm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/markm/32/12776_2.png) [@markm](https://community.auth0.com/u/markm)\
**Post date:** [November 24, 2020, 8:13pm UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/2 "2020-11-24T20:13:41Z")

</div>

Can anyone chime in here? Still looking for answers.

---

<div class="post-metadata">

**Author:** ![markm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/markm/32/12776_2.png) [@markm](https://community.auth0.com/u/markm)\
**Post date:** [December 9, 2020, 11:23am UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/3 "2020-12-09T11:23:18Z")

</div>

Still wondering if anyone can help on this. I have progressed without using Auth0 and instead using my own Lambda authorization but this is only for a small project. I have a larger project in the pipeline and Auth0 looks attractive if I can get some of these issues ironed out.

---

<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:** [January 4, 2021, 11:46pm UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/5 "2021-01-04T23:46:25Z")

</div>

Hi @markm,

Let’s take a look.

The React app will function the same, regardless of it consuming APIs that are hosted in a serverless environment.

Your react app will request tokens from Auth0 intended for your API (serverless functions), will then send those tokens in a header along with a request, and your API will verify the tokens and either fulfill or deny the request depending on the validity of the token, scopes, permissions, etc.

This is largely the same as a more traditional non-serverless scenario.

This doc shows how to call an API with the token from your react app.

> **[Auth0 React SDK Quickstarts: Call an API](https://auth0.com/docs/quickstart/spa/react/02-calling-an-api)**
>
> This tutorial demonstrates how to make API calls to the Auth0 Management API.

---

<div class="post-metadata">

**Author:** ![markm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/markm/32/12776_2.png) [@markm](https://community.auth0.com/u/markm)\
**Post date:** [January 5, 2021, 12:18am UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/6 "2021-01-05T00:18:07Z")

</div>

Hi Dan,

Many thanks for getting back to me on this thread; I thought it was dead but I am still mulling this over so I appreciate your input!

From what you’ve said, I understand that - in an AWS environment - I would use a custom authorizer to intercept the `Authorization` header that was generated by Auth0 and then validate it in some way. My understanding of all this has increased since I made this thread so I think I can manage that.

My other issue was refresh tokens - nobody wants to have to sign in again after an hour. From the article you have linked it says the SDK basically handles that for us:

> The `getAccessTokenSilently()` method can renew the access and ID token for you using [refresh tokens](https://auth0.com/docs/tokens/concepts/refresh-tokens). To [get a refresh token](https://auth0.com/docs/tokens/guides/get-refresh-tokens) when a user logs in, pass `useRefreshTokens={true}` as a prop to `Auth0Provider` .

…which is great if so - it sounds deceptively easy 😜

Thanks for your input!

---

<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:** [January 5, 2021, 12:30am UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/7 "2021-01-05T00:30:28Z")

</div>

You got it!

The SDK does most of the heavy lifting, the code exchanges, refresh token rotation or cookies for silent requests, etc. There isn’t much you should have to configure. I would recommend looking at our [react quickstart](https://auth0.com/docs/quickstart/spa/react/01-login) if you want to see a sample app with best practices.

---

<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:** [January 20, 2021, 12:30am UTC](https://community.auth0.com/t/using-auth0-react-sdk-with-lambda/53697/8 "2021-01-20T00:30:28Z")

</div>

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