# Is it possible to get a JWT via a backend server and pass it to the front end client?

**URL:** <https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969>\
**Category:** JWT.io\
**Created:** [January 28, 2020, 6:28pm UTC](https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969 "2020-01-28T18:28:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvin1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calvin1/32/9696_2.png) [@calvin1](https://community.auth0.com/u/calvin1)\
**Post date:** [January 28, 2020, 6:28pm UTC](https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969/1 "2020-01-28T18:28:03Z")

</div>

Is it possible to have a react app (SPA) send an email and password to a node server and then have the node server create the user and get a JWT from auth0, then pass back the JWT to the react app?  
The use case for this would be having a single end point for multiple react apps to talk to and sign up with without having to implement any auth0 code across all the apps.

Is there anything wrong with doing the above?

Or is it the case that the react apps (SPA) will each have to talk to auth0 directly in order to create a user and receive back a JWT via the callback?

Any help and clarification on this would be much appreciated.

---

<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 29, 2020, 5:13pm UTC](https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969/3 "2020-01-29T17:13:16Z")

</div>

Hi @calvin1,

> [@calvin1](#):
>
> Is it possible to have a react app (SPA) send an email and password to a node server and then have the node server create the user and get a JWT from auth0, then pass back the JWT to the react app?

Are you just talking about signup or would you login with this same flow? Getting the token would require some type of login, as a signup will not return a token in the scenario you described.

> [@calvin1](#):
>
> Is there anything wrong with doing the above?

**If you are talking about signup _and_ login with this method:** This is not really recommended. Sending raw credentials via a POST request is possible via the resource owner password grant, but it is usually a last resort. This is for numerous reasons, watch [this video](https://auth0.com/docs/videos/learn-identity/05-desktop-and-mobile-apps#wistia_dq3c4pz9lb?time=1580) if you want to hear why. Have you tried adding Auth0 to your SPAs? Once you do one, it shouldn’t be too difficult to add to all of them. Are you running into specific issues?

**If you are just talking about signup:** You can use the [db signup endpoint](https://auth0.com/docs/api/authentication#signup) to sign up users with just a username, pw, and some other profile info, but you will not receive a token in return. The user will still be required to log in.

---

<div class="post-metadata">

**Author:** ![calvin1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calvin1/32/9696_2.png) [@calvin1](https://community.auth0.com/u/calvin1)\
**Post date:** [January 29, 2020, 6:45pm UTC](https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969/4 "2020-01-29T18:45:10Z")

</div>

Hi @dan.woda,

Thanks for the response.

> “Are you just talking about signup or would you login with this same flow?”

Both signup and then login in the same flow. My understanding is that this could be achieved by signing up the user via [db signup endpoint](https://auth0.com/docs/api/authentication#signup) and then using the ‘resource owner password grant’ in the same flow to get the access\_token, which would then be returned to the client.

Subsequent logins would require the client to pass the credentials to the node server which exchanges them for an access\_token via the ‘resource owner password grant’.

I think what you are saying is that the above is possible but not recommended for the reasons outlined in the video? Is this correct?

From a user experience point of view, when a user submit their username and password, we would like to sign them up AND log them in. We don’t want the user to sign up and then be redirected to the login page to login using credentials they have just entered. Can this flow be achieved by adding Auth0 in our SPAs?

![](https://global.discourse-cdn.com/auth0/original/3X/9/c/9c619e56706add2a9fed3fcec168bfd847cf981a.png) calvin1:

---

<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 30, 2020, 8:55pm UTC](https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969/5 "2020-01-30T20:55:29Z")

</div>

> [@calvin1](#):
>
> I think what you are saying is that the above is possible but not recommended for the reasons outlined in the video? Is this correct?

That is correct. In addition, using ROPG sacrifices many benefits of the auth0 service, also outlined in the video.

> [@calvin1](#):
>
> From a user experience point of view, when a user submit their username and password, we would like to sign them up AND log them in. We don’t want the user to sign up and then be redirected to the login page to login using credentials they have just entered. Can this flow be achieved by adding Auth0 in our SPAs?

Yes, using Universal Login, it is possible to achieve this flow. In-fact, it is the default flow. A signup event when using UL also returns a token. I would encourage you to check out our quickstarts. It demonstrates how simple it is to add auth to a SPA.

> **[Auth0 Single-Page App Quickstarts](https://auth0.com/docs/quickstart/spa)**
>
> Browse single-page app quickstarts to learn how to quickly add authentication to your app.

---

<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:** [February 14, 2020, 12:55am UTC](https://community.auth0.com/t/is-it-possible-to-get-a-jwt-via-a-backend-server-and-pass-it-to-the-front-end-client/36969/6 "2020-02-14T00:55:34Z")

</div>

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