From 204b6254e1f936e7fb606e6c42670c97653469c2 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Tue, 23 Jul 2024 18:28:16 +0530 Subject: [PATCH] fix: use correct userContext type --- lib/build/recipe/oauth2client/index.d.ts | 10 ++++---- lib/build/recipe/oauth2client/index.js | 25 +++++++++++++------- lib/ts/recipe/oauth2client/index.ts | 29 ++++++++++++++++-------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/lib/build/recipe/oauth2client/index.d.ts b/lib/build/recipe/oauth2client/index.d.ts index b42ed62c5..a16f0bb05 100644 --- a/lib/build/recipe/oauth2client/index.d.ts +++ b/lib/build/recipe/oauth2client/index.d.ts @@ -1,12 +1,11 @@ // @ts-nocheck -import { UserContext } from "../../types"; import Recipe from "./recipe"; import { RecipeInterface, APIInterface, APIOptions, OAuthTokens } from "./types"; export default class Wrapper { static init: typeof Recipe.init; static getAuthorisationRedirectURL( redirectURIOnProviderDashboard: string, - userContext: UserContext + userContext?: Record ): Promise<{ urlWithQueryParams: string; pkceCodeVerifier?: string | undefined; @@ -17,9 +16,12 @@ export default class Wrapper { redirectURIQueryParams: any; pkceCodeVerifier?: string | undefined; }, - userContext: UserContext + userContext?: Record ): Promise; - static getUserInfo(oAuthTokens: OAuthTokens, userContext: UserContext): Promise; + static getUserInfo( + oAuthTokens: OAuthTokens, + userContext?: Record + ): Promise; } export declare let init: typeof Recipe.init; export declare let getAuthorisationRedirectURL: typeof Wrapper.getAuthorisationRedirectURL; diff --git a/lib/build/recipe/oauth2client/index.js b/lib/build/recipe/oauth2client/index.js index 285af7656..e9481bbfa 100644 --- a/lib/build/recipe/oauth2client/index.js +++ b/lib/build/recipe/oauth2client/index.js @@ -20,32 +20,41 @@ var __importDefault = }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getUserInfo = exports.exchangeAuthCodeForOAuthTokens = exports.getAuthorisationRedirectURL = exports.init = void 0; +const utils_1 = require("../../utils"); const recipe_1 = __importDefault(require("./recipe")); class Wrapper { static async getAuthorisationRedirectURL(redirectURIOnProviderDashboard, userContext) { const recipeInterfaceImpl = recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl; - const providerConfig = await recipeInterfaceImpl.getProviderConfig({ userContext }); + const providerConfig = await recipeInterfaceImpl.getProviderConfig({ + userContext: utils_1.getUserContext(userContext), + }); return await recipeInterfaceImpl.getAuthorisationRedirectURL({ providerConfig, redirectURIOnProviderDashboard, - userContext, + userContext: utils_1.getUserContext(userContext), }); } static async exchangeAuthCodeForOAuthTokens(redirectURIInfo, userContext) { const recipeInterfaceImpl = recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl; - const providerConfig = await recipeInterfaceImpl.getProviderConfig({ userContext }); + const providerConfig = await recipeInterfaceImpl.getProviderConfig({ + userContext: utils_1.getUserContext(userContext), + }); return await recipeInterfaceImpl.exchangeAuthCodeForOAuthTokens({ providerConfig, redirectURIInfo, - userContext, + userContext: utils_1.getUserContext(userContext), }); } static async getUserInfo(oAuthTokens, userContext) { const recipeInterfaceImpl = recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl; - const providerConfig = await recipeInterfaceImpl.getProviderConfig({ userContext }); - return await recipe_1.default - .getInstanceOrThrowError() - .recipeInterfaceImpl.getUserInfo({ providerConfig, oAuthTokens, userContext }); + const providerConfig = await recipeInterfaceImpl.getProviderConfig({ + userContext: utils_1.getUserContext(userContext), + }); + return await recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl.getUserInfo({ + providerConfig, + oAuthTokens, + userContext: utils_1.getUserContext(userContext), + }); } } exports.default = Wrapper; diff --git a/lib/ts/recipe/oauth2client/index.ts b/lib/ts/recipe/oauth2client/index.ts index 4ae33ab34..0ae790b4d 100644 --- a/lib/ts/recipe/oauth2client/index.ts +++ b/lib/ts/recipe/oauth2client/index.ts @@ -13,20 +13,25 @@ * under the License. */ -import { UserContext } from "../../types"; +import { getUserContext } from "../../utils"; import Recipe from "./recipe"; import { RecipeInterface, APIInterface, APIOptions, OAuthTokens } from "./types"; export default class Wrapper { static init = Recipe.init; - static async getAuthorisationRedirectURL(redirectURIOnProviderDashboard: string, userContext: UserContext) { + static async getAuthorisationRedirectURL( + redirectURIOnProviderDashboard: string, + userContext?: Record + ) { const recipeInterfaceImpl = Recipe.getInstanceOrThrowError().recipeInterfaceImpl; - const providerConfig = await recipeInterfaceImpl.getProviderConfig({ userContext }); + const providerConfig = await recipeInterfaceImpl.getProviderConfig({ + userContext: getUserContext(userContext), + }); return await recipeInterfaceImpl.getAuthorisationRedirectURL({ providerConfig, redirectURIOnProviderDashboard, - userContext, + userContext: getUserContext(userContext), }); } @@ -36,24 +41,28 @@ export default class Wrapper { redirectURIQueryParams: any; pkceCodeVerifier?: string | undefined; }, - userContext: UserContext + userContext?: Record ) { const recipeInterfaceImpl = Recipe.getInstanceOrThrowError().recipeInterfaceImpl; - const providerConfig = await recipeInterfaceImpl.getProviderConfig({ userContext }); + const providerConfig = await recipeInterfaceImpl.getProviderConfig({ + userContext: getUserContext(userContext), + }); return await recipeInterfaceImpl.exchangeAuthCodeForOAuthTokens({ providerConfig, redirectURIInfo, - userContext, + userContext: getUserContext(userContext), }); } - static async getUserInfo(oAuthTokens: OAuthTokens, userContext: UserContext) { + static async getUserInfo(oAuthTokens: OAuthTokens, userContext?: Record) { const recipeInterfaceImpl = Recipe.getInstanceOrThrowError().recipeInterfaceImpl; - const providerConfig = await recipeInterfaceImpl.getProviderConfig({ userContext }); + const providerConfig = await recipeInterfaceImpl.getProviderConfig({ + userContext: getUserContext(userContext), + }); return await Recipe.getInstanceOrThrowError().recipeInterfaceImpl.getUserInfo({ providerConfig, oAuthTokens, - userContext, + userContext: getUserContext(userContext), }); } }