# SPA & Custom API

**URL:** <https://community.auth0.com/t/spa-custom-api/113492>\
**Category:** Get Help\
**Tags:** clients, management-api\
**Created:** [August 11, 2023, 8:44pm UTC](https://community.auth0.com/t/spa-custom-api/113492 "2023-08-11T20:44:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alelor01](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@alelor01](https://community.auth0.com/u/alelor01)\
**Post date:** [August 11, 2023, 8:44pm UTC](https://community.auth0.com/t/spa-custom-api/113492/1 "2023-08-11T20:44:49Z")

</div>

Hi,

I have a React SPA and a HapiJS (Node) API.

I’ve managed to get authentication working on the React app, by following the built-in guide on the Auth0 dashboard. I haven’t got authorisation working on the API yet but I think that’s mostly on my end, so would be do-able.

I was trying to setup environment variables on React app, when I was reminded that values won’t be secret on an SPA.

Whilst I assume this has already been thought of and that exposing the client ID and domain may not be the end of the world, I would still like to handle everything on the API side.

I keep getting lost and confused in all of the documentation. I did come across [this doc](https://auth0.com/docs/manage-users/cookies/spa-authenticate-with-cookies), which I think outlines the flow I want.

How do I do this?

My questions:

1. Do I need to represent the SPA with an Auth0 application?
2. Do I need to represent the API with an Auth0 API or an Auth0 application?
3. Is my current implementation okay anyway?
4. What is the recommended setup and flow for a custom SPA and API like this?
5. Can you recommend specific documentation for this?

Thanks,  
Alex

---

<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:** [August 12, 2023, 12:23am UTC](https://community.auth0.com/t/spa-custom-api/113492/3 "2023-08-12T00:23:55Z")

</div>

Hey @alelor01 welcome to the community!

I definitely recommend checking out our architecture scenarios documentation for a high level overview:

> **[Single-Page Applications (SPA) with API](https://auth0.com/docs/get-started/architecture-scenarios/spa-api)**
>
> Explains the architecture scenario where a single-page application (SPA) talks to an API using OpenID Connect (OIDC), and the OAuth 2.0 Implicit Grant Flow, to authenticate users with Auth0.

1. Yes, you should create a SPA type application to represent your frontend application.
2. You will want to [register an API](https://auth0.com/docs/get-started/auth0-overview/set-up-apis) in Auth0 to represent your API itself.
3. Your approach seems good to me - Although I am not sure how you would handle a React SPA API side.
4. The recommend set up is outlined in the architecture scenarios documentation I linked above.
5. Our React [quickstart](https://auth0.com/docs/quickstart/spa/react/01-login) and subsequent [sample app](https://github.com/auth0-samples/auth0-react-samples) as well as [this guide](https://developer.auth0.com/resources/guides/spa/react/basic-authentication/v17-javascript-react-router-5#quick-react-setup) should be helpful as well!

Hope this helps!

---

<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:** [August 26, 2023, 12:24am UTC](https://community.auth0.com/t/spa-custom-api/113492/4 "2023-08-26T00:24:45Z")

</div>

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