Skip to content

Commit c0eda0f

Browse files
committed
create starter application
1 parent d9935fd commit c0eda0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+86965
-10
lines changed

NOTICE

Lines changed: 55904 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
1-
# React/JavaScript: Security and Identity Management
1+
# React/JavaScript: Starter SPA Code Sample
22

3-
Visit the ["React/JavaScript Code Samples: App Security in Action"](https://auth0.com/developers/hub/code-samples/spa/react-javascript) section of the ["Auth0 Developer Hub"](https://auth0.com/developers/hub) to explore how you can secure React applications written in JavaScript by implementing user authentication with Auth0.
3+
This JavaScript code sample demonstrates how to build a Single-Page Application (SPA) using React. This React code sample builds the API server using the React Router 6 library.
44

5-
[![React/JavaScript Code Samples: App Security in Action](https://cdn.auth0.com/blog/hub/code-samples/spa/react-javascript.png)](https://auth0.com/developers/hub/code-samples/spa/react-javascript)
6-
7-
## Basic User Authentication Code Sample
5+
Visit the ["React/JavaScript Code Samples: SPA Security in Action"](https://developer.auth0.com/resources/code-samples/spa/react) section of the ["Auth0 Developer Resources"](https://developer.auth0.com/resources) to explore how you can secure React applications written in JavaScript by implementing endpoint protection and authorization with Auth0.
86

9-
This JavaScript code sample demonstrates **how to implement user authentication** in React applications using Auth0.
7+
[![React/JavaScript Code Samples: SPA Security in Action](https://cdn.auth0.com/blog/hub/code-samples/spa/react-javascript.png)](https://developer.auth0.com/resources/code-samples/spa/react)
108

11-
Visit the ["React/JavaScript Code Sample: User Authentication For Basic Apps"](https://auth0.com/developers/hub/code-samples/spa/react-javascript/basic-authentication) page for instructions on how to configure and run this code sample and how to integrate it with an API server of your choice to [create a full-stack code sample](https://auth0.com//developers/hub/code-samples/full-stack/hello-world/basic-access-control/spa).
9+
## Why Use Auth0?
1210

13-
[![React/JavaScript Code Sample: User Authentication For Basic Apps](https://cdn.auth0.com/blog/hub/code-samples/spa/react-javascript/basic-authentication.png)](https://auth0.com/developers/hub/code-samples/spa/react-javascript/basic-authentication)
11+
Auth0 is a flexible drop-in solution to add authentication and authorization services to your applications. Your team and organization can avoid the cost, time, and risk that come with building your own solution to authenticate and authorize users. We offer tons of guidance and SDKs for you to get started and [integrate Auth0 into your stack easily](https://developer.auth0.com/resources/code-samples/full-stack).
1412

13+
## Set Up and Run the React Project
1514

15+
Install the project dependencies:
1616

17-
## Why Use Auth0?
17+
```bash
18+
npm install
19+
```
20+
21+
The starter React project offers a functional application that consumes data from an external API to hydrate the user interface. For simplicity and convenience, the starter project simulates the external API locally using [`json-server`](https://github.com/typicode/json-server).
22+
23+
However, you can also integrate this starter project with any of the ["Hello World" API code samples, which are available in multiple backend frameworks and programming languages](https://github.com/orgs/auth0-developer-hub/repositories?language=&q=api+hello-world&sort=&type=public).
24+
25+
The compatible API server runs on `http://localhost:6060` by default. As such, to connect your React application with that API server, create a `.env` file under the root project directory and populate it with the following environment variables:
26+
27+
```bash
28+
REACT_APP_API_SERVER_URL=http://localhost:6060
29+
```
30+
31+
Next, execute the following command to run the JSON server API:
32+
33+
```bash
34+
npm run api
35+
```
36+
37+
Finally, open another terminal tab and execute this command to run your React application:
38+
39+
```bash
40+
npm start
41+
```
42+
43+
Visit [`http://localhost:4040/`](http://localhost:4040/) to access the starter application.
1844

19-
Auth0 is a flexible drop-in solution to add authentication and authorization services to your applications. Your team and organization can avoid the cost, time, and risk that come with building your own solution to authenticate and authorize users. We offer tons of guidance and SDKs for you to get started and [integrate Auth0 into your stack easily](https://auth0.com/developers/hub/code-samples/full-stack).
45+
In the starter project, all the starter React application routes are public. However, you can use Auth0 to get an ID token to hydrate the user profile information present on the `/profile` page with information from a real user. With Auth0, you can also get an access token to make a secure call to an external API to hydrate the messages present in the `/protected` and `/admin` pages.

json-server/db.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"api-messages-public": {
3+
"text": "This is a public message."
4+
},
5+
"api-messages-protected": {
6+
"text": "This is a protected message."
7+
},
8+
"api-messages-admin": {
9+
"text": "This is an admin message."
10+
}
11+
}

json-server/routes.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"/api/messages/public": "/api-messages-public",
3+
"/api/messages/protected": "/api-messages-protected",
4+
"/api/messages/admin": "/api-messages-admin"
5+
}

0 commit comments

Comments
 (0)