Skip to content

Commit b3f604c

Browse files
authored
Merge pull request #401 from brettchaldecott/feat/react-native-v7/kinde-provider
feat: added kinde provider documentation
2 parents b750eb9 + 942a201 commit b3f604c

1 file changed

Lines changed: 101 additions & 46 deletions

File tree

src/content/docs/developer-tools/sdks/native/react-native-sdk.mdx

Lines changed: 101 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ You can also check out our starter kits on GitHub:
7676

7777
## Before you begin
7878

79-
- If you havent already got a Kinde account, [register for free here](https://app.kinde.com/register) (no credit card required). Registering gives you a Kinde domain, which you need to get started, e.g. `yourapp.kinde.com`.
79+
- If you haven't already got a Kinde account, [register for free here](https://app.kinde.com/register) (no credit card required). Registering gives you a Kinde domain, which you need to get started, e.g. `yourapp.kinde.com`.
8080
- You will also need Node, the React Native command line interface, a JDK, Android Studio (for Android) and Xcode (for iOS).
81-
- Follow [the installation instructions for your chosen OS](https://reactnative.dev/docs/environment-setup) to install dependencies.
81+
- Follow [the installation instructions for your chosen OS](https://reactnative.dev/docs/environment-setup) to install dependencies.
8282

8383
<Aside type="warning" title="Important">
8484

@@ -104,6 +104,27 @@ Because the Kinde SDK requires React Native 0.60 or higher, native dependencies
104104

105105
### **iOS**
106106

107+
Before installing CocoaPods, ensure you have Ruby and Bundler set up correctly on your system.
108+
109+
### Shell setup
110+
111+
```shell
112+
# Install or update Bundler
113+
gem install bundler
114+
115+
# Create a new Gemfile if it doesn't exist
116+
bundle init
117+
118+
# Add CocoaPods to your Gemfile
119+
bundle add cocoapods
120+
121+
# Install dependencies using Bundler
122+
bundle install
123+
124+
# Install pods for your project
125+
cd ios && bundle exec pod install
126+
```
127+
107128
#### Update iOS native dependencies
108129
To update iOS native dependencies, you can use **CocoaPods**. We recommend installing **CocoaPods** using [Homebrew](https://brew.sh/).
109130

@@ -116,18 +137,18 @@ cd ios && pod install
116137

117138
If you encounter any errors during the SDK installation process, you can refer to the General Tips section at the end of this topic.
118139

119-
## K**inde configuration**
140+
## Kinde configuration
120141

121-
1. In Kinde, go to **Settings > Applications.**
122-
2. Select **View details** on the **Front-end app**.
123-
3. Scroll down to the **Callback URLs** section.
142+
1. In Kinde, go to **Settings > Applications.**
143+
2. Select **View details** on the **Front-end app**.
144+
3. Scroll down to the **Callback URLs** section.
124145
4. Add in the callback URLs for your React Native app, which should look something like this:
125-
- Allowed callback URLs - `myapp://myhost.kinde.com/kinde_callback`
126-
- Allowed logout redirect URLs - `myapp://myhost.kinde.com/kinde_callback`
146+
- Allowed callback URLs - `myapp://myhost.kinde.com/kinde_callback`
147+
- Allowed logout redirect URLs - `myapp://myhost.kinde.com/kinde_callback`
127148

128149
Make sure you press the Save button at the bottom of the page!
129150

130-
Note: The `myapp://myhost.kinde.com/kinde_callback` is used as an example of local URL Scheme, change to the local local URL Scheme that you use.
151+
Note: The `myapp://myhost.kinde.com/kinde_callback` is used as an example of local URL Scheme, change to the local local URL Scheme that you use.
131152

132153
## Environments
133154

@@ -139,10 +160,10 @@ If you would like to use our Environments feature as part of your development pr
139160

140161
Put these variables in your .env file. You can find these variables on the same page as where you set the callback URLs.
141162

142-
- `KINDE_ISSUER_URL` - your Kinde domain
143-
- `KINDE_POST_CALLBACK_URL` - After the user authenticates we will callback to this address. Make sure this URL is under your allowed callback URLs
144-
- `KINDE_POST_LOGOUT_REDIRECT_URL` - where you want users to be redirected to after logging out. Make sure this URL is under your allowed logout redirect URLs
145-
- `KINDE_CLIENT_ID` - you can find this on the App Keys page
163+
- `KINDE_ISSUER_URL` - your Kinde domain
164+
- `KINDE_POST_CALLBACK_URL` - After the user authenticates we will callback to this address. Make sure this URL is under your allowed callback URLs
165+
- `KINDE_POST_LOGOUT_REDIRECT_URL` - where you want users to be redirected to after logging out. Make sure this URL is under your allowed logout redirect URLs
166+
- `KINDE_CLIENT_ID` - you can find this on the App Keys page
146167

147168
```typescript
148169
KINDE_ISSUER_URL=https://your_kinde_domain.kinde.com
@@ -346,6 +367,40 @@ import { KindeSDK } from '@kinde-oss/react-native-sdk-0-7x';
346367
const client = new KindeSDK(YOUR_KINDE_ISSUER, YOUR_KINDE_REDIRECT_URI, YOUR_KINDE_CLIENT_ID, YOUR_KINDE_LOGOUT_REDIRECT_URI);
347368
```
348369

370+
## **KindeProvider (React Native 0.7x only)**
371+
372+
The KindeProvider is a powerful component introduced in React Native SDK 0.7x that simplifies session management and SDK initialization. It handles the complexity of user session lifecycles on mobile devices, including token validation and refresh logic.
373+
374+
To use the KindeProvider, import it from the SDK:
375+
376+
```typescript
377+
import { useKindeProvider } from '@kinde-oss/react-native-sdk-0-7x';
378+
```
379+
380+
The `useKindeProvider` hook initializes the SDK if it hasn't been initialized and returns a cached instance if it has. It also provides session state information and a reference to the SDK client.
381+
382+
Here's how to use it:
383+
384+
```typescript
385+
const { isAuthenticated, verifyToken, authSdk } = useKindeProvider({
386+
issuerUrl: 'https://myhost.kinde.com',
387+
redirectUri: 'myapp://myhost.kinde.com/kinde_callback',
388+
clientId: 'secret',
389+
logoutRedirectUri: 'myapp://myhost.kinde.com/kinde_callback',
390+
});
391+
```
392+
393+
The hook returns:
394+
- `isAuthenticated`: A boolean indicating the current authentication state
395+
- `verifyToken`: A function to verify the token's validity
396+
- `authSdk`: A reference to the initialized KindeSDK instance
397+
398+
This approach simplifies session management by:
399+
- Automatically handling SDK initialization
400+
- Caching the SDK instance appropriately
401+
- Managing token validation and refresh logic
402+
- Providing easy access to authentication state
403+
349404
## Sign in and registration
350405

351406
Kinde provides methods for easily implementing a login / register flow. You can add buttons as follows.
@@ -363,7 +418,7 @@ Kinde provides methods for easily implementing a login / register flow. You can
363418

364419
Then define new functions that match for each button.
365420

366-
**Note**: Before proceeding, make sure youve defined the **KindeSDK** as a **client** variable.
421+
**Note**: Before proceeding, make sure you've defined the **KindeSDK** as a **client** variable.
367422

368423
```typescript
369424
...
@@ -478,7 +533,7 @@ Go to the Users page in Kinde to see your newly registered user.
478533

479534
Once a user has been verified, your product/application will return the JWT token with an array of permissions for that user. You will need to configure your product/application to read permissions and unlock the respective functions.
480535

481-
[Set permissions](/manage-users/roles-and-permissions/user-permissions/) in your Kinde account. Heres an example set of permissions.
536+
[Set permissions](/manage-users/roles-and-permissions/user-permissions/) in your Kinde account. Here's an example set of permissions.
482537

483538
```typescript
484539
const permissions = [
@@ -513,7 +568,7 @@ if ((await client.getPermission("create:todos")).isGranted) {
513568

514569
## Audience
515570

516-
An audience is the intended recipient of an access token - for example the API for your application. The audience argument can be passed to the Kinde client to request an audience be added to the token.
571+
An audience is the intended recipient of an access token - for example the API for your application. The audience argument can be passed to the Kinde client to request an audience be added to the token.
517572

518573
The audience of a token is the intended recipient of the token.
519574

@@ -530,7 +585,7 @@ const client = new KindeSDK(
530585
);
531586
```
532587

533-
For details on how to connect, see [Register an API](/developer-tools/your-apis/register-manage-apis/).
588+
For details on how to connect, see [Register an API](/developer-tools/your-apis/register-manage-apis/).
534589

535590
## Overriding scope
536591

@@ -590,7 +645,7 @@ client.createOrg({org_name: "Your Organization"});
590645

591646
### Sign in and sign up to organizations
592647

593-
Kinde has a unique code for every organization. Youll have to pass this code through when you register a new user.
648+
Kinde has a unique code for every organization. You'll have to pass this code through when you register a new user.
594649

595650
Example function below:
596651

@@ -646,7 +701,7 @@ For more information about how organizations work in Kinde, see [Kinde organizat
646701

647702
## **Feature Flags**
648703

649-
We have provided a helper to return any features flag from the access token:
704+
We have provided a helper to return any features flag from the access token:
650705

651706
```typescript
652707
client.getFlag('theme')
@@ -673,7 +728,7 @@ client.getFlag('theme', 'default-theme', 'b')
673728
// Error: Flag 'theme' is type string - requested type boolean
674729
```
675730

676-
We also require wrapper functions by type which should leverage `getFlag` above.
731+
We also require wrapper functions by type which should leverage `getFlag` above.
677732

678733
### **Get boolean flags**
679734

@@ -759,7 +814,7 @@ kindeClient.getIntegerFlag("is_dark_mode", false);
759814

760815
## Token Storage
761816

762-
Once the user has successfully authenticated, you'll have a JWT and a refresh token and that has been stored securely. E.g. using the `getAccessToken` method of the `Storage` class to get an access token.
817+
Once the user has successfully authenticated, you'll have a JWT and a refresh token and that has been stored securely. E.g. using the `getAccessToken` method of the `Storage` class to get an access token.
763818

764819
```typescript
765820
...
@@ -770,9 +825,9 @@ const accessToken = await Storage.getAccessToken();
770825
console.log('access_token', accessToken);
771826
```
772827

773-
We're using the [react-native-keychain](https://www.npmjs.com/package/react-native-keychain) for `React Native`
828+
We're using the [react-native-keychain](https://www.npmjs.com/package/react-native-keychain) for `React Native`
774829

775-
The storage handler can be found at: [Storage class](https://github.com/kinde-oss/kinde-react-native-sdk-0-7x/blob/main/dist/SDK/Storage/index.d.ts)
830+
The storage handler can be found at: [Storage class](https://github.com/kinde-oss/kinde-react-native-sdk-0-7x/blob/main/dist/SDK/Storage/index.d.ts)
776831

777832
## **How to test**
778833

@@ -786,7 +841,7 @@ Note: Ensure you have already run `npm install` or equivalent.
786841

787842
### `issuer`
788843

789-
Either your Kinde URL or your custom domain. e.g `https://yourapp.kinde.com`.
844+
Either your Kinde URL or your custom domain. e.g `https://yourapp.kinde.com`.
790845

791846
Type: `string`
792847

@@ -836,7 +891,7 @@ Required: No
836891

837892
Default: `{}`
838893

839-
### `additionalParameters` `- audience`
894+
### `additionalParameters` `- audience`
840895

841896
The audience claim for the JWT.
842897

@@ -946,7 +1001,7 @@ await kinde.logout();
9461001
await kinde.logout(true);
9471002
```
9481003

949-
Sample output: `true` or `false`
1004+
Sample output: `true` or `false`
9501005

9511006
### `getToken`
9521007

@@ -996,9 +1051,9 @@ Arguments:
9961051
Usage:
9971052

9981053
```typescript
999-
await kinde.createOrg(); 
1000-
// or 
1001-
await kinde.createOrg({org_name: 'your organization name'}); _**//**_
1054+
await kinde.createOrg();
1055+
// or
1056+
await kinde.createOrg({org_name: 'your organization name'}); _**//**_
10021057
```
10031058

10041059
Allow `org_name` to be provided if you want a specific organization name when you create.
@@ -1144,11 +1199,11 @@ Usage:
11441199
await kinde.isAuthenticate;
11451200
```
11461201

1147-
Sample output: `true` or `false`
1202+
Sample output: `true` or `false`
11481203

11491204
### **`getFlag`**
11501205

1151-
Get a flag from the feature_flags claim of the `access_token`.
1206+
Get a flag from the feature_flags claim of the `access_token`.
11521207

11531208
Arguments:
11541209

@@ -1184,7 +1239,7 @@ Sample output:
11841239

11851240
### **`getBooleanFlag`**
11861241

1187-
Get a boolean flag from the `feature_flags` claim of the access token
1242+
Get a boolean flag from the `feature_flags` claim of the access token
11881243

11891244
Arguments:
11901245

@@ -1199,11 +1254,11 @@ Usage:
11991254
kinde.getBooleanFlag("is_dark_mode");
12001255
```
12011256

1202-
Sample output: `true`
1257+
Sample output: `true`
12031258

12041259
### **`getStringFlag`**
12051260

1206-
Get a string flag from the `feature_flags` claim of the access token
1261+
Get a string flag from the `feature_flags` claim of the access token
12071262

12081263
Arguments:
12091264

@@ -1218,11 +1273,11 @@ Usage:
12181273
kinde.getStringFlag("theme");
12191274
```
12201275

1221-
Sample output: `black`
1276+
Sample output: `black`
12221277

12231278
### **`getIntegerFlag`**
12241279

1225-
Get a integer flag from the `feature_flags` claim of the access token
1280+
Get a integer flag from the `feature_flags` claim of the access token
12261281

12271282
Arguments:
12281283

@@ -1237,21 +1292,21 @@ Usage:
12371292
kinde.getIntegerFlag("team_count");
12381293
```
12391294

1240-
Sample output: `2`
1295+
Sample output: `2`
12411296

12421297
## General tips
12431298

12441299
### **Building issues**
12451300

1246-
**`'value'`** **is unavailable: introduced in iOS 12.0**
1301+
**`'value'`** **is unavailable: introduced in iOS 12.0**
12471302

1248-
If you got the error **'value' is unavailable: introduced in iOS 12.0** when trying to build the app, you can follow the below steps to fix that:
1303+
If you got the error **'value' is unavailable: introduced in iOS 12.0** when trying to build the app, you can follow the below steps to fix that:
12491304

1250-
1. In your Xcode project navigator, select **Pods.**
1251-
2. Under Targets, select **React-Codegen**.
1305+
1. In your Xcode project navigator, select **Pods.**
1306+
2. Under Targets, select **React-Codegen**.
12521307
3. Select the **Build Settings** tab.
1253-
4. Under **Deployment**, set **iOS Deployment Target** to **12.4.**
1254-
5. Clean project and rebuild: **Product > Clean Build Folder, Product > Build.**
1308+
4. Under **Deployment**, set **iOS Deployment Target** to **12.4.**
1309+
5. Clean project and rebuild: **Product > Clean Build Folder, Product > Build.**
12551310

12561311
<img
12571312
src="https://imagedelivery.net/skPPZTHzSlcslvHjesZQcQ/e441dff0-bc34-40a6-5854-2f390e805300/public"
@@ -1263,9 +1318,9 @@ If you got the error **'value' is unavailable: introduced in iOS 12.0** when t
12631318
decoding="async"
12641319
/>
12651320

1266-
6. Dependency `'androidx.browser:browser:1.6.0-beta01'` requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs
1321+
6. Dependency `'androidx.browser:browser:1.6.0-beta01'` requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs
12671322

1268-
The solution is add `androidXBrowser = "1.4.0"` in your project.
1323+
The solution is add `androidXBrowser = "1.4.0"` in your project.
12691324

12701325
```java
12711326
// android/build.gradle
@@ -1282,7 +1337,7 @@ If you got the error **'value' is unavailable: introduced in iOS 12.0** when t
12821337
12831338
7. Duplicate class **kotlin.collections.jdk8.CollectionsJDK8Kt** found in modules **jetified-kotlin-stdlib-1.8.10** (org.jetbrains.kotlin:kotlin-stdlib:1.8.10) and **jetified-kotlin-stdlib-jdk8-1.7.22** (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.22)
12841339
1285-
The solution is add `org.jetbrains.kotlin:kotlin-bom:1.8.0` dependency in your project.
1340+
The solution is add `org.jetbrains.kotlin:kotlin-bom:1.8.0` dependency in your project.
12861341
12871342
```java
12881343
// android/app/build.grade

0 commit comments

Comments
 (0)