|
2 | 2 |
|
3 | 3 | ## Upgrading from v4 -> v5 |
4 | 4 |
|
5 | | -### Compatibility Requirements |
| 5 | +Version 5.0 of `react-native-auth0` is a significant update featuring a complete architectural overhaul. This new foundation improves performance, maintainability, and provides a more consistent API across all platforms. |
6 | 6 |
|
7 | | -- **React**: v5 requires React 19 or higher |
8 | | -- **React Native**: v5 requires React Native 0.78.0 or higher |
9 | | -- **Expo**: v5 requires Expo 53 or higher |
| 7 | +Upgrading from v4.x requires addressing several breaking changes. Please follow this guide carefully. |
10 | 8 |
|
11 | | -### Breaking Changes |
| 9 | +## 1. Compatibility & Installation |
12 | 10 |
|
13 | | -- **Platform Compatibility**: The minimum iOS deployment target is now 14.0. Update your iOS/Podfile with: |
| 11 | +Before updating the library, ensure your project meets the new minimum requirements. |
14 | 12 |
|
15 | | - ``` |
16 | | - platform :ios, '14.0' |
17 | | - ``` |
| 13 | +### Environment Requirements |
18 | 14 |
|
19 | | -- **Android Requirements**: Android SDK API level 35 or higher is now required |
| 15 | +- **React:** `19.0.0` or higher |
| 16 | +- **React Native:** `0.78.0` or higher |
| 17 | +- **Expo:** SDK `53` or higher |
| 18 | +- **iOS:** Deployment Target `14.0` |
| 19 | +- **Android:** Target SDK `35` or higher |
20 | 20 |
|
21 | | -### Migration Steps |
| 21 | +### Updating Your Project |
22 | 22 |
|
23 | | -#### For Regular React Native Projects |
| 23 | +#### For Standard React Native Projects: |
24 | 24 |
|
25 | | -1. First, ensure your project uses React 19 and React Native 0.78.0 or higher: |
| 25 | +1. **Upgrade React Native:** |
| 26 | + ```bash |
| 27 | + npm install react@^19.0.0 react-native@^0.78.0 |
| 28 | + ``` |
| 29 | +2. **Update this Library:** |
| 30 | + ```bash |
| 31 | + npm install react-native-auth0@beta |
| 32 | + ``` |
| 33 | +3. **Update iOS Target:** In your `ios/Podfile`, set the platform version: |
| 34 | + ```ruby |
| 35 | + platform :ios, '14.0' |
| 36 | + ``` |
| 37 | +4. **Install Pods:** |
| 38 | + ```bash |
| 39 | + cd ios && pod install && cd .. |
| 40 | + ``` |
26 | 41 |
|
27 | | - ```bash |
28 | | - npm install react@^19.0.0 |
29 | | - npm install react-native@^0.78.0 |
30 | | - ``` |
| 42 | +#### For Expo Projects: |
31 | 43 |
|
32 | | -2. Update the react-native-auth0 package: |
| 44 | +1. **Upgrade Expo SDK:** |
| 45 | + ```bash |
| 46 | + npx expo upgrade |
| 47 | + ``` |
| 48 | +2. **Update this Library:** |
| 49 | + ```bash |
| 50 | + npm install react-native-auth0@beta |
| 51 | + ``` |
| 52 | +3. **Rebuild Native Code:** |
| 53 | + ```bash |
| 54 | + npx expo prebuild --clean |
| 55 | + ``` |
| 56 | + > **Warning:** This will overwrite any manual changes in your `ios` and `android` directories. |
33 | 57 |
|
34 | | - ```bash |
35 | | - npm install react-native-auth0@beta |
36 | | - ``` |
| 58 | +## 2. Breaking API Changes |
37 | 59 |
|
38 | | -3. Update your iOS minimum deployment target in your Podfile: |
| 60 | +The following API changes require code modifications in your application. |
39 | 61 |
|
40 | | - ```ruby |
41 | | - platform :ios, '14.0' |
42 | | - ``` |
| 62 | +### Change #1: User Profile Properties are now `camelCase` |
43 | 63 |
|
44 | | -4. Install the updated pods: |
45 | | - ```bash |
46 | | - cd ios && pod install && cd .. |
47 | | - ``` |
| 64 | +To align with modern JavaScript standards, all properties on the `user` object are now `camelCase`. |
48 | 65 |
|
49 | | -#### For Expo Projects |
| 66 | +**✅ Action Required:** Update all references to `user` properties. |
50 | 67 |
|
51 | | -1. Update to Expo 53 or higher: |
| 68 | +| Before (snake_case) | After (camelCase) | |
| 69 | +| :-------------------- | :------------------- | |
| 70 | +| `user.given_name` | `user.givenName` | |
| 71 | +| `user.family_name` | `user.familyName` | |
| 72 | +| `user.email_verified` | `user.emailVerified` | |
| 73 | +| `user.phone_number` | `user.phoneNumber` | |
| 74 | +| ...and so on. | | |
52 | 75 |
|
53 | | - ```bash |
54 | | - npx expo upgrade |
55 | | - ``` |
| 76 | +### Change #2: Credentials Object uses `expiresAt` |
56 | 77 |
|
57 | | -2. Update the react-native-auth0 package: |
| 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. |
58 | 79 |
|
59 | | - ```bash |
60 | | - npm install react-native-auth0@beta |
61 | | - ``` |
| 80 | +**✅ Action Required:** Replace all logic using `expiresIn` with `expiresAt`. |
62 | 81 |
|
63 | | -3. Rebuild your app: |
64 | | - ```bash |
65 | | - npx expo prebuild --clean |
66 | | - ``` |
67 | | - Note: This will reset any manual changes to your native code. |
| 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 |
| 106 | +
|
| 107 | +All errors thrown by the library are now instances of a single, consistent `AuthError` class. This replaces multiple error types like `CredentialsManagerError`. |
| 108 | +
|
| 109 | +**✅ Action Required:** Update your `try...catch` blocks to handle the new unified error object. |
| 110 | +
|
| 111 | +**Before:** |
| 112 | +
|
| 113 | +```javascript |
| 114 | +catch (e) { |
| 115 | + // Inconsistent properties like e.error, e.error_description |
| 116 | + console.error(e.message); |
| 117 | +} |
| 118 | +``` |
| 119 | +
|
| 120 | +**After:** |
| 121 | +
|
| 122 | +```javascript |
| 123 | +import { AuthError } from 'react-native-auth0'; |
| 124 | +
|
| 125 | +catch (e) { |
| 126 | + if (e instanceof AuthError) { |
| 127 | + // Consistent properties are now available |
| 128 | + console.error(e.name, e.message); // e.g., 'invalid_grant', 'The refresh token is invalid.' |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | +
|
| 133 | +### Change #4: Updated `authorize` and `clearSession` Signatures |
| 134 | +
|
| 135 | +For improved clarity, SDK-specific options (like `ephemeralSession`) have been moved into a separate, second `options` object. |
| 136 | +
|
| 137 | +**✅ Action Required:** Restructure calls to `authorize` and `clearSession`. |
| 138 | +
|
| 139 | +**Before:** |
| 140 | +
|
| 141 | +```javascript |
| 142 | +// Mixed parameters and options |
| 143 | +await authorize({ |
| 144 | + scope: 'openid profile', |
| 145 | + ephemeralSession: true, |
| 146 | +}); |
| 147 | +``` |
| 148 | +
|
| 149 | +**After:** |
| 150 | +
|
| 151 | +```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 | +); |
| 157 | +``` |
68 | 158 |
|
69 | 159 | ## Upgrading from v3 -> v4 |
70 | 160 |
|
|
0 commit comments