-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Sarmad61/dev_sarmad
Update Utils.ts
- Loading branch information
Showing
1 changed file
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Provides endpoints to manage your Kinde Businesses | ||
* | ||
* The version of the OpenAPI document: 1 | ||
* Contact: [email protected] | ||
* Contact: mailto:[email protected] | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
|
@@ -15,6 +15,7 @@ import crypto, { LibWordArray } from 'crypto-js'; | |
import Constants, { ExecutionEnvironment } from 'expo-constants'; | ||
import * as WebBrowser from 'expo-web-browser'; | ||
import InAppBrowser from 'react-native-inappbrowser-reborn'; | ||
import { Platform } from 'react-native'; // Added import for Platform | ||
import { InvalidTypeException } from '../common/exceptions/invalid-type.exception'; | ||
import { PropertyRequiredException } from '../common/exceptions/property-required.exception'; | ||
import { UnexpectedException } from '../common/exceptions/unexpected.exception'; | ||
|
@@ -158,6 +159,13 @@ export const addAdditionalParameters = ( | |
|
||
export const isExpo = Constants.executionEnvironment !== undefined; | ||
|
||
/** | ||
* Opens a web browser or in-app browser for authentication. | ||
* @param {string} url - The URL to open. | ||
* @param {KindeSDK} kindeSDK - The KindeSDK instance. | ||
* @param {AuthBrowserOptions} [options] - Optional browser options. | ||
* @returns A promise that resolves with the token or null if authentication fails. | ||
*/ | ||
export const OpenWebInApp = async ( | ||
url: string, | ||
kindeSDK: KindeSDK, | ||
|
@@ -173,26 +181,40 @@ export const OpenWebInApp = async ( | |
return kindeSDK.getToken(response.url); | ||
} | ||
console.error( | ||
'Something wrong when trying to authenticating. Reason: ', | ||
'Something wrong when trying to authenticate. Reason: ', | ||
response.type | ||
); | ||
return null; | ||
} catch (error: any) { | ||
console.error( | ||
'Something wrong when trying to authenticating. Reason: ', | ||
'Something wrong when trying to authenticate. Reason: ', | ||
error.message | ||
); | ||
return null; | ||
} | ||
}; | ||
|
||
/** | ||
* Opens a web browser using custom tabs on Android or default browser on other platforms. | ||
* @param {string} url - The URL to open. | ||
* @param {string} redirectUri - The redirect URI. | ||
* @param {AuthBrowserOptions} [options] - Optional browser options. | ||
* @returns A promise that resolves with the authentication response. | ||
* @throws Error if no web browser is found. | ||
*/ | ||
export const openWebBrowser = async ( | ||
url: string, | ||
redirectUri: string, | ||
options?: AuthBrowserOptions | ||
) => { | ||
if (isExpo) { | ||
return WebBrowser.openAuthSessionAsync(url, redirectUri, options); | ||
if (Platform.OS === 'android') { | ||
// Use custom tabs for Android | ||
const { preferredBrowserPackage } = await WebBrowser.getCustomTabsSupportingBrowsersAsync(); | ||
return WebBrowser.openAuthSessionAsync(url, redirectUri, { browserPackage: preferredBrowserPackage, ...options }); | ||
} else { | ||
return WebBrowser.openAuthSessionAsync(url, redirectUri, options); | ||
} | ||
} | ||
if (InAppBrowser) { | ||
if (await InAppBrowser.isAvailable()) { | ||
|