Skip to content

Commit 2ca550e

Browse files
Release v5.0.0-beta.4 (#1242)
1 parent 6887b5b commit 2ca550e

File tree

87 files changed

+17268
-12403
lines changed

Some content is hidden

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

87 files changed

+17268
-12403
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v5.0.0-beta.3
1+
v5.0.0-beta.4

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
# Change Log
22

3+
## [v5.0.0-beta.4](https://github.com/auth0/react-native-auth0/tree/v5.0.0-beta.4) (2025-07-21)
4+
5+
[Full Changelog](https://github.com/auth0/react-native-auth0/compare/v5.0.0-beta.3...v5.0.0-beta.4)
6+
7+
**💡 Major Refactor**: Version 5.0 features a complete architectural overhaul for improved performance, maintainability, and multi-platform extensibility. Check the [Migration Guide](https://github.com/auth0/react-native-auth0/blob/master/MIGRATION_GUIDE.md) for detailed upgrade instructions.
8+
9+
**⚠️ BREAKING CHANGES**
10+
11+
- feat: architectural refactor for multi-platform extensibility [\#1233](https://github.com/auth0/react-native-auth0/pull/1233) ([subhankarmaiti](https://github.com/subhankarmaiti))
12+
13+
**Added**
14+
15+
- Fix Documentation Typo: 'retreive' → 'retrieve' [\#1183](https://github.com/auth0/react-native-auth0/pull/1183) ([tinchomengo](https://github.com/tinchomengo))
16+
- feat: added react native web support [\#1233](https://github.com/auth0/react-native-auth0/pull/1233) ([subhankarmaiti](https://github.com/subhankarmaiti))
17+
18+
**Changed**
19+
20+
- feat(deps): Upgrade React Native to 0.80.1 [\#1237](https://github.com/auth0/react-native-auth0/pull/1237) ([subhankarmaiti](https://github.com/subhankarmaiti))
21+
22+
**Fixed**
23+
24+
- fix(iOS): Fix ephemeralSession parameter type conversion in webAuth [\#1238](https://github.com/auth0/react-native-auth0/pull/1238) ([subhankarmaiti](https://github.com/subhankarmaiti))
25+
26+
**Security**
27+
28+
- chore: pin prettier-related packages to prevent malicious package installation [\#1241](https://github.com/auth0/react-native-auth0/pull/1241) ([subhankarmaiti](https://github.com/subhankarmaiti))
29+
330
## [v5.0.0-beta.3](https://github.com/auth0/react-native-auth0/tree/v5.0.0-beta.3) (2025-06-23)
431

532
[Full Changelog](https://github.com/auth0/react-native-auth0/compare/v5.0.0-beta.2...v5.0.0-beta.3)

FAQ.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
7. [Auth0 web browser gets killed when going to the background on Android](#7-auth0-web-browser-gets-killed-when-going-to-the-background-on-android)
1010
8. [How to resolve the _Failed to start this transaction, as there is an active transaction at the moment_ error?](#8-how-to-resolve-the-failed-to-start-this-transaction-as-there-is-an-active-transaction-at-the-moment-error)
1111
9. [How can I prevent the autogenerated redirect_uri from breaking if the applicationId has mixed cases or special characters in it on Android?](#9-how-can-i-prevent-the-autogenerated-redirect_uri-from-breaking-if-the-applicationId-has-mixed-cases-or-special-characters-in-it-on-android)
12+
10. [Why doesn't `await authorize()` work on the web? How do I handle login?](#10-why-doesnt-await-authorize-work-on-the-web-how-do-i-handle-login)
13+
11. [Why do my users get logged out frequently? How do I keep them logged in?](#11-why-do-my-users-get-logged-out-frequently-how-do-i-keep-them-logged-in)
1214

1315
## 1. How can I have separate Auth0 domains for each environment on Android?
1416

@@ -262,3 +264,76 @@ If you don't need SSO, consider using `ephemeral sessions` or `SFSafariViewContr
262264
## 9. How can I prevent the autogenerated redirect_uri from breaking if the applicationId has mixed cases or special characters in it on Android ?
263265

264266
It is recommended to have your applicationId in lower case without special characters to prevent any mismatch with the generated redirect_uri. But in the scenario where you require your applicationId to be of mixed case, to avoid any mismatch , the user can pass a `redirectUri` which matches the one provided in the manage dashboard as part of the `AgentLoginOptions` property.
267+
268+
## 10. Why doesn't `await authorize()` work on the web? How do I handle login?
269+
270+
This is a key difference between native and web platforms.
271+
272+
- **On Native (iOS/Android):** `authorize()` opens an in-app browser overlay. Your app continues running in the background. When the user authenticates, the browser dismisses and the `authorize()` promise resolves with the credentials. `await` works as expected.
273+
274+
- **On Web:** `authorize()` triggers a **full-page browser redirect** to the Auth0 Universal Login page. Your application's current state is lost. After authentication, the user is redirected back to your app, which causes your entire React application to reload and re-initialize from scratch. Because of this, the original `authorize()` promise is never able to resolve.
275+
276+
**The Solution: Use the `useAuth0` Hook**
277+
278+
The recommended way to handle this is by using the `Auth0Provider` and `useAuth0` hook. They are designed to manage this flow automatically:
279+
280+
1. **On initial load:** The provider checks if the user is returning from a login redirect. If so, it processes the credentials in the URL and establishes a session.
281+
2. **State Management:** The `user` and `isLoading` properties from the `useAuth0` hook will automatically update to reflect the authenticated state after the redirect is handled.
282+
283+
Your UI should be reactive to the `user` and `isLoading` state, rather than trying to `await` the result of `authorize()`.
284+
285+
```jsx
286+
import { useAuth0 } from 'react-native-auth0';
287+
288+
const MyComponent = () => {
289+
const { authorize, user, isLoading } = useAuth0();
290+
291+
// This component will re-render after the redirect,
292+
// and `user` will be populated.
293+
if (isLoading) {
294+
return <Text>Loading...</Text>;
295+
}
296+
297+
return (
298+
<View>
299+
{user ? (
300+
<Text>Welcome, {user.name}!</Text>
301+
) : (
302+
<Button
303+
title="Log In"
304+
onPress={async () => {
305+
// This will trigger the redirect. No need to `await`.
306+
await authorize();
307+
}}
308+
/>
309+
)}
310+
</View>
311+
);
312+
};
313+
```
314+
315+
## 11. Why do my users get logged out frequently? How do I keep them logged in?
316+
317+
If your users are being asked to log in again after a short period (e.g., when they close and reopen the app), it's likely because the SDK cannot silently refresh their tokens.
318+
319+
The `getCredentials()` method is responsible for retrieving tokens. If the `accessToken` is expired, it will attempt to get a new one using a `refreshToken`. This process happens silently without requiring user interaction.
320+
321+
To enable this, you **must** request the `offline_access` scope during the initial login. This scope is what signals to Auth0 that you want to receive a `refreshToken`.
322+
323+
**The Solution: Add the `offline_access` Scope**
324+
325+
When calling `authorize`, ensure you include `offline_access` in the scope string.
326+
327+
```javascript
328+
import { useAuth0 } from 'react-native-auth0';
329+
330+
const { authorize } = useAuth0();
331+
332+
const handleLogin = async () => {
333+
await authorize({
334+
scope: 'openid profile email offline_access', // <-- Add this scope
335+
});
336+
};
337+
```
338+
339+
By including this scope, the SDK will receive and securely store a `refreshToken`. This token will then be used by `getCredentials()` to maintain the user's session across app launches, providing a much smoother user experience.

MIGRATION_GUIDE.md

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,7 @@ To align with modern JavaScript standards, all properties on the `user` object a
7373
| `user.phone_number` | `user.phoneNumber` |
7474
| ...and so on. | |
7575

76-
### Change #2: Credentials Object uses `expiresAt`
77-
78-
The `Credentials` object no longer includes `expiresIn` (a duration). It now provides `expiresAt`, an absolute **UNIX timestamp** (in seconds), making expiration checks simpler and less error-prone.
79-
80-
**✅ Action Required:** Replace all logic using `expiresIn` with `expiresAt`.
81-
82-
**Before:**
83-
84-
```javascript
85-
const expiresAt = Date.now() / 1000 + credentials.expiresIn;
86-
if (isExpired(expiresAt)) {
87-
// ...
88-
}
89-
```
90-
91-
**After:**
92-
93-
```javascript
94-
// Direct comparison is now possible
95-
if (credentials.expiresAt < Date.now() / 1000) {
96-
// ...
97-
}
98-
99-
// Or, use the new helper method (if you have an instance of the Credentials model):
100-
if (credentials.isExpired()) {
101-
// ...
102-
}
103-
```
104-
105-
### Change #3: Standardized `AuthError` Object
76+
### Change #2: Standardized `AuthError` Object
10677

10778
All errors thrown by the library are now instances of a single, consistent `AuthError` class. This replaces multiple error types like `CredentialsManagerError`.
10879

@@ -130,32 +101,73 @@ catch (e) {
130101
}
131102
```
132103
133-
### Change #4: Updated `authorize` and `clearSession` Signatures
104+
### Change #3: Platform-Specific API Availability
105+
106+
With the introduction of **React Native Web support**, some methods are only available on native platforms for security reasons. Direct authentication grants that handle user credentials (like passwords or OTP codes) are **not supported in the browser** and will throw a `NotImplemented` error.
107+
108+
**✅ Action Required:** If you are building for the web, ensure all authentication flows are initiated via the redirect-based `authorize()` method. Review the platform support table in the [README](README.md#features-and-platform-support) for a full list of platform-specific methods.
109+
110+
### Change #4: `authorize()` Behavior on Web
134111
135-
For improved clarity, SDK-specific options (like `ephemeralSession`) have been moved into a separate, second `options` object.
112+
On React Native Web, the `authorize()` method now triggers a **full-page redirect** to Auth0. As a result, the promise returned by `authorize()` will **not resolve** in the browser. Your application must be structured to handle the user state upon reloading after the redirect.
136113
137-
**✅ Action Required:** Restructure calls to `authorize` and `clearSession`.
114+
**✅ Action Required:** Review the new **[FAQ entry](#faq-authorize-web)** for guidance on how to correctly handle the post-login flow on the web. The `Auth0Provider` and `useAuth0` hook are designed to manage this flow automatically.
115+
116+
### Change #5: New Peer Dependency for Web Support
117+
118+
To support the web platform, the library now has an **optional peer dependency** on `@auth0/auth0-spa-js`.
119+
120+
**✅ Action Required:** If you are using `react-native-auth0` in a React Native Web project, you **must** install this package. Native-only projects can ignore this.
121+
122+
```bash
123+
npm install @auth0/auth0-spa-js
124+
```
125+
126+
### Change #6: Hook Methods Now Throw Error
127+
128+
Previously, all hook-related methods such as `getCredentials()`, `saveCredentials()`, etc., did not throw error directly. Instead, any issues were silently handled and surfaced via the error property in `useAuth0()`:
129+
130+
```javascript
131+
const { error } = useAuth0();
132+
// error would be populated if getCredentials failed
133+
```
134+
135+
**What's Changed:**
136+
137+
These methods now throw error directly to the caller. You must handle them explicitly using try...catch blocks.
138+
139+
**✅ Action Required:** Update your code to handle error for each function call individually.
138140
139141
**Before:**
140142
141143
```javascript
142-
// Mixed parameters and options
143-
await authorize({
144-
scope: 'openid profile',
145-
ephemeralSession: true,
146-
});
144+
const { getCredentials, error } = useAuth0();
145+
---
146+
await getCredentials();
147+
// Check error manually later
147148
```
148149
149150
**After:**
150151
151152
```javascript
152-
// Parameters and options are now separate arguments
153-
await authorize(
154-
{ scope: 'openid profile' }, // 1. OIDC / Auth0 Parameters
155-
{ ephemeralSession: true } // 2. SDK-Specific Options
156-
);
153+
const { getCredentials, error } = useAuth0();
154+
155+
try {
156+
await getCredentials();
157+
} catch (e) {
158+
console.error(e);
159+
}
157160
```
158161
162+
All thrown errors are instances of the new standardized AuthError class described in Change #2.
163+
164+
### Recommended Reading
165+
166+
After migrating, we highly recommend reviewing the updated **[FAQ](FAQ.md)** for detailed explanations on:
167+
168+
- How to handle the `authorize()` redirect flow on the web.
169+
- The importance of the `offline_access` scope for keeping users logged in.
170+
159171
## Upgrading from v3 -> v4
160172
161173
- **If your project is built with Expo:**

REACT_NATIVE_WEB_SETUP.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# React Native Web Configuration Guide
2+
3+
This guide provides instructions for using React Native Auth0 with React Native Web.
4+
5+
## What is React Native Web?
6+
7+
React Native Web is a library that provides React Native components and APIs that are compatible with React and the web. It allows you to write your application once using React Native and run it on iOS, Android, and web platforms.
8+
9+
**Official React Native Web Repository:** https://github.com/necolas/react-native-web
10+
11+
## Setup Instructions
12+
13+
If you want to use React Native Web with React Native Auth0, follow these steps:
14+
15+
### 1. Install React Native Web
16+
17+
Follow the official React Native Web installation guide:
18+
**https://necolas.github.io/react-native-web/docs/setup/**
19+
20+
### 2. Install Auth0 SPA JS (Required for Web)
21+
22+
React Native Auth0 requires `@auth0/auth0-spa-js` for web platform support:
23+
24+
```bash
25+
# Using npm
26+
npm install @auth0/auth0-spa-js
27+
28+
# Using yarn
29+
yarn add @auth0/auth0-spa-js
30+
```
31+
32+
### 3. Use React Native Auth0
33+
34+
Once React Native Web and Auth0 SPA JS are installed, you can use React Native Auth0 exactly as you would in a native React Native app. The library will automatically detect the web platform and use the appropriate implementation.
35+
36+
## Example Usage
37+
38+
```jsx
39+
import React from 'react';
40+
import { Auth0Provider } from 'react-native-auth0';
41+
42+
const App = () => (
43+
<Auth0Provider domain="YOUR_AUTH0_DOMAIN" clientId="YOUR_AUTH0_CLIENT_ID">
44+
{/* Your app components */}
45+
</Auth0Provider>
46+
);
47+
48+
export default App;
49+
```
50+
51+
## Resources
52+
53+
- **React Native Web Setup Guide**: https://necolas.github.io/react-native-web/docs/setup/
54+
- **React Native Web GitHub**: https://github.com/necolas/react-native-web
55+
- **Auth0 SPA JS**: https://github.com/auth0/auth0-spa-js
56+
- **React Native Auth0 Documentation**: https://auth0.github.io/react-native-auth0/
57+
58+
## Notes
59+
60+
- React Native Auth0 automatically detects when running on web and uses the Auth0 SPA JS library under the hood
61+
- All React Native Auth0 APIs work the same across platforms (iOS, Android, and Web)
62+
- For web-specific examples, see the [EXAMPLES-WEB.md](https://github.com/auth0/react-native-auth0/blob/master/EXAMPLES-WEB.md) file in this repository

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ We're excited to announce the release of react-native-auth0 `v4.0.0` and the bet
2323
- [Expo Quickstart](https://auth0.com/docs/quickstart/native/react-native-expo/interactive)
2424
- [Sample App](https://github.com/auth0-samples/auth0-react-native-sample/tree/master/00-Login-Hooks)
2525
- [Expo Sample App](https://github.com/auth0-samples/auth0-react-native-sample/tree/master/00-Login-Expo)
26+
- [React Native Web Setup](https://github.com/auth0/react-native-auth0/blob/master/REACT_NATIVE_WEB_SETUP.md)
2627
- [FAQs](https://github.com/auth0/react-native-auth0/blob/master/FAQ.md)
2728
- [Examples](https://github.com/auth0/react-native-auth0/blob/master/EXAMPLES.md)
29+
- [Examples for Web](https://github.com/auth0/react-native-auth0/blob/master/EXAMPLES-WEB.md)
2830
- [Docs Site](https://auth0.github.io/react-native-auth0/)
2931

3032
## Getting Started

docs/.nojekyll

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/assets/hierarchy.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/highlight.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
--dark-hl-13: #d4d4d4;
3030
--light-hl-14: #0070c1;
3131
--dark-hl-14: #4fc1ff;
32+
--light-hl-15: #098658;
33+
--dark-hl-15: #b5cea8;
3234
--light-code-background: #ffffff;
3335
--dark-code-background: #1e1e1e;
3436
}
@@ -50,6 +52,7 @@
5052
--hl-12: var(--light-hl-12);
5153
--hl-13: var(--light-hl-13);
5254
--hl-14: var(--light-hl-14);
55+
--hl-15: var(--light-hl-15);
5356
--code-background: var(--light-code-background);
5457
}
5558
}
@@ -71,6 +74,7 @@
7174
--hl-12: var(--dark-hl-12);
7275
--hl-13: var(--dark-hl-13);
7376
--hl-14: var(--dark-hl-14);
77+
--hl-15: var(--dark-hl-15);
7478
--code-background: var(--dark-code-background);
7579
}
7680
}
@@ -91,6 +95,7 @@
9195
--hl-12: var(--light-hl-12);
9296
--hl-13: var(--light-hl-13);
9397
--hl-14: var(--light-hl-14);
98+
--hl-15: var(--light-hl-15);
9499
--code-background: var(--light-code-background);
95100
}
96101

@@ -110,6 +115,7 @@
110115
--hl-12: var(--dark-hl-12);
111116
--hl-13: var(--dark-hl-13);
112117
--hl-14: var(--dark-hl-14);
118+
--hl-15: var(--dark-hl-15);
113119
--code-background: var(--dark-code-background);
114120
}
115121

@@ -158,6 +164,9 @@
158164
.hl-14 {
159165
color: var(--hl-14);
160166
}
167+
.hl-15 {
168+
color: var(--hl-15);
169+
}
161170
pre,
162171
code {
163172
background: var(--code-background);

0 commit comments

Comments
 (0)