# Angular + Nodejs New User flow

**URL:** <https://community.auth0.com/t/angular-nodejs-new-user-flow/92112>\
**Category:** Get Help\
**Tags:** single-page-applicat, create-user, mysql, api, login\
**Created:** [October 10, 2022, 9:01pm UTC](https://community.auth0.com/t/angular-nodejs-new-user-flow/92112 "2022-10-10T21:01:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpencerWF](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/spencerwf/32/40488_2.png) [@SpencerWF](https://community.auth0.com/u/SpencerWF)\
**Post date:** [October 10, 2022, 9:01pm UTC](https://community.auth0.com/t/angular-nodejs-new-user-flow/92112/1 "2022-10-10T21:01:14Z")

</div>

Please include the following information in your post:

- Which SDK this is regarding:
- SDK Version:
- Platform Version:
- Code Snippets/Error Messages/Supporting Details/Screenshots:

Hello,

I have an Angular front end (using Auth0’s single page application) and a nodejs API backend (trying to implement Auth0’s API functionality). My backend communicates with a MYSQL database for the project functionality.

I’m hoping to understand a few things:

1. How is it expected that an Angular Frontend and a Nodejs Backend API share a user when you sign in?
2. How does one access the app\_metadata in the angular project? (This quickstart guide throws up a bunch of Typescript errors - [Auth0 Angular SDK Quickstarts: Call an API](https://auth0.com/docs/quickstart/spa/angular/02-calling-an-api))
3. When a project has a database and a new user signs in, is it best to use the Auth0 “Rules” to access the database on user creation and create an empty new user in my database that way?
4. Alternatively is it better when creating a new user to create them in my database and then from the (Nodejs) backend access the Auth0 database and leave user information there to connect the two?

Any help you can provide is greatly appreciated.  
Cheers,  
Spen

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [October 10, 2022, 11:12pm UTC](https://community.auth0.com/t/angular-nodejs-new-user-flow/92112/4 "2022-10-10T23:12:25Z")

</div>

Hey there @SpencerWF welcome to the community!

These are all great questions! I usually point to our [architectural scenarios](https://auth0.com/docs/get-started/architecture-scenarios/spa-api) documentation first and foremost to serve as high level overview.

1. In an Auth0/OAuth/OIDC context this is all done via [tokens](https://auth0.com/docs/secure/tokens) (ID/Access).

2. Typically, this is added as a custom claim to a user’s ID and/or Access token, something like:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://example.com';
    api.accessToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
    api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
//additionally, user metadata
    api.accessToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
    api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
};

```

Some more on [custom claims](https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token) and [metadata](https://auth0.com/docs/manage-users/user-accounts/metadata/manage-user-metadata).

1. You can certainly go the rule/action route - That is, inspect the user profile on login for some some of reference to your external DB, and if it does not exist then make the necessary calls to your backend.

Alternatively, you could use the ID token returned in the initial authentication exchange to create the user in your DB. Here’s a similar topic which should help:

> [@Best practices for creating users in backend DB on new registrations with Auth0](https://community.auth0.com/t/best-practices-for-creating-users-in-backend-db-on-new-registrations-with-auth0/61185/4):
>
> One question we have is why you would need a call to the management API at all. You should be able to use the ID token returned from the initial authentication to create a user in your DB.

1. You should be able to avoid a call the Management API altogether if you use the ID Token as mentioned previously.

Hopefully this helps clear things up a bit!

---

<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:** [November 22, 2022, 10:43pm UTC](https://community.auth0.com/t/angular-nodejs-new-user-flow/92112/5 "2022-11-22T22:43:29Z")

</div>

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