Skip to content

Commit

Permalink
Merge pull request #40 from Sarmad61/dev_sarmad
Browse files Browse the repository at this point in the history
Update Utils.ts
  • Loading branch information
oliwolff1 authored Aug 27, 2024
2 parents a17562a + d635183 commit e57fad0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/SDK/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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()) {
Expand Down

0 comments on commit e57fad0

Please sign in to comment.