Skip to content

Commit f773375

Browse files
authored
Release 0.4.0 (auth0#33)
1 parent 036ff10 commit f773375

26 files changed

+48497
-105744
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
CHANGELOG.md
2+
docs

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## [v0.4.0](https://github.com/auth0/auth0-react/tree/v0.4.0) (2020-06-05)
4+
5+
**Added**
6+
7+
- [SDK-1697] Add custom user agent to spa js [\#28](https://github.com/auth0/auth0-react/pull/28) ([adamjmcgrath](https://github.com/adamjmcgrath))
8+
- Use `checkSession` to start login [\#27](https://github.com/auth0/auth0-react/pull/27) ([adamjmcgrath](https://github.com/adamjmcgrath))
9+
- [SDK-1690] Add generated API docs [\#25](https://github.com/auth0/auth0-react/pull/25) ([adamjmcgrath](https://github.com/adamjmcgrath))
10+
311
## [v0.3.1](https://github.com/auth0/auth0-react/tree/v0.3.1) (2020-06-01)
412

513
**Fixed**

README.md

+36-27
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
# @auth0/auth0-react
22

3-
Auth0 SDK for React Applications.
3+
Auth0 SDK for React Single Page Applications (SPA).
44

55
[![CircleCI](https://circleci.com/gh/auth0/auth0-react.svg?style=svg&circle-token=b7d4097b3e2d3d3d086b26df6b20fb0f51d8ca09)](https://circleci.com/gh/auth0/auth0-react)
66
[![License](https://img.shields.io/:license-mit-blue.svg?style=flat)](https://opensource.org/licenses/MIT)
77

8-
### Early Access
8+
### Beta
99

10-
**@auth0/auth0-react** is in _Early Access_ in order to get feedback to shape its design. That means:
11-
12-
- It is under active development so breaking changes are expected and we will do our best to communicate them.
13-
- The library is not yet published onto npm.
10+
**@auth0/auth0-react** is in Beta in order to get feedback to shape its design. As we move towards general availability please be aware that releases may contain breaking changes, but we will do our best to communicate them.
1411

1512
## Table of Contents
1613

14+
- [Documentation](#documentation)
1715
- [Installation](#installation)
1816
- [Getting Started](#getting-started)
19-
- [Other Use Cases](#other-use-cases)
2017
- [Contributing](#contributing)
2118
- [Support + Feedback](#support--feedback)
2219
- [Vulnerability Reporting](#vulnerability-reporting)
2320
- [What is Auth0](#what-is-auth0)
2421
- [License](#license)
2522

23+
## Documentation
24+
25+
- [API Reference](https://auth0.github.io/auth0-react/)
26+
2627
## Installation
2728

28-
For Early Access, download the binary from the releases page: [auth0-auth0-react-0.3.1.tgz](https://github.com/auth0/auth0-react/releases/download/v0.3.1/auth0-auth0-react-0.3.1.tgz).
29+
Using [npm](https://npmjs.org/)
30+
31+
```bash
32+
npm install @auth0/auth0-react
33+
```
2934

30-
Then install it from the folder you downloaded it to:
35+
Using [yarn](https://yarnpkg.com/)
3136

3237
```bash
33-
npm install ~/Downloads/auth0-auth0-react-0.3.1.tgz
38+
yarn add @auth0/auth0-react
3439
```
3540

3641
## Getting Started
@@ -94,9 +99,7 @@ function App() {
9499
export default App;
95100
```
96101

97-
## Other Use Cases
98-
99-
### Class Components
102+
### Use with a Class Component
100103

101104
Use the `withAuth0` higher order component to add the `auth0` property to Class components:
102105

@@ -114,7 +117,7 @@ class Profile extends Component {
114117
export default withAuth0(Profile);
115118
```
116119

117-
### Protecting Routes
120+
### Protect a Route
118121

119122
Protect a route component using the `withAuthenticationRequired` higher order component. Visits to this route when unauthenticated will redirect the user to the login page and back to this page after login:
120123

@@ -130,9 +133,11 @@ const PrivateRoute = () => <div>Private</div>;
130133
export default withAuthenticationRequired(PrivateRoute, Redirecting);
131134
```
132135

133-
### Access an API
136+
**Note** If you are using a custom router, you will need to supply the `Auth0Provider` with a custom `onRedirectCallback` method to perform the action that returns the user to the protected page. See examples for [react-router](https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md#1-protecting-a-route-in-a-react-router-dom-app), [Gatsby](https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md#2-protecting-a-route-in-a-gatsby-app) and [Next.js](https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md#3-protecting-a-route-in-a-nextjs-app-in-spa-mode).
137+
138+
### Call an API
134139

135-
Use a protected API with an Access Token:
140+
Call a protected API with an Access Token:
136141

137142
```jsx
138143
import React, { useEffect, useState } from 'react';
@@ -144,16 +149,20 @@ const Posts = () => {
144149

145150
useEffect(() => {
146151
(async () => {
147-
const token = await getAccessTokenSilently({
148-
audience: 'https://api.example.com/',
149-
scope: 'read:posts',
150-
});
151-
const response = await fetch('https://api.example.com/posts', {
152-
headers: {
153-
Authorization: `Bearer ${token}`,
154-
},
155-
});
156-
setPosts(await response.json());
152+
try {
153+
const token = await getAccessTokenSilently({
154+
audience: 'https://api.example.com/',
155+
scope: 'read:posts',
156+
});
157+
const response = await fetch('https://api.example.com/posts', {
158+
headers: {
159+
Authorization: `Bearer ${token}`,
160+
},
161+
});
162+
setPosts(await response.json());
163+
} catch (e) {
164+
console.error(e);
165+
}
157166
})();
158167
}, [getAccessTokenSilently]);
159168

@@ -173,7 +182,7 @@ const Posts = () => {
173182
export default Posts;
174183
```
175184

176-
See more examples in [EXAMPLES.md](./EXAMPLES.md)
185+
For a more detailed example see how to [create a `useApi` hook for accessing protected APIs with an access token](#4-create-a-useapi-hook-for-accessing-protected-apis-with-an-access-token).
177186

178187
## Contributing
179188

0 commit comments

Comments
 (0)