Skip to content

Commit

Permalink
fix: use correct userContext type
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Jul 23, 2024
1 parent c5e6988 commit 204b625
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
10 changes: 6 additions & 4 deletions lib/build/recipe/oauth2client/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>
): Promise<{
urlWithQueryParams: string;
pkceCodeVerifier?: string | undefined;
Expand All @@ -17,9 +16,12 @@ export default class Wrapper {
redirectURIQueryParams: any;
pkceCodeVerifier?: string | undefined;
},
userContext: UserContext
userContext?: Record<string, any>
): Promise<import("./types").OAuthTokenResponse>;
static getUserInfo(oAuthTokens: OAuthTokens, userContext: UserContext): Promise<import("./types").UserInfo>;
static getUserInfo(
oAuthTokens: OAuthTokens,
userContext?: Record<string, any>
): Promise<import("./types").UserInfo>;
}
export declare let init: typeof Recipe.init;
export declare let getAuthorisationRedirectURL: typeof Wrapper.getAuthorisationRedirectURL;
Expand Down
25 changes: 17 additions & 8 deletions lib/build/recipe/oauth2client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 19 additions & 10 deletions lib/ts/recipe/oauth2client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>
) {
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),
});
}

Expand All @@ -36,24 +41,28 @@ export default class Wrapper {
redirectURIQueryParams: any;
pkceCodeVerifier?: string | undefined;
},
userContext: UserContext
userContext?: Record<string, any>
) {
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<string, any>) {
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),
});
}
}
Expand Down

0 comments on commit 204b625

Please sign in to comment.