Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows empty provider list #652

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `getRolesForUser`
- `getRolesForUser`
- Similar changes in combination recipes (thirdpartyemailpassword and thirdpartypasswordless) have been made
- Even if thirdpartyemailpassword and thirdpartpasswordless recipes do not have a providers array as an input, they will still expose the third party recipe routes to the frontend.

### Changes

Expand Down
4 changes: 2 additions & 2 deletions lib/build/recipe/thirdpartyemailpassword/recipe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Recipe extends RecipeModule {
recipeId: string,
appInfo: NormalisedAppinfo,
isInServerlessEnv: boolean,
config: TypeInput,
config: TypeInput | undefined,
recipes: {
thirdPartyInstance: ThirdPartyRecipe | undefined;
emailPasswordInstance: EmailPasswordRecipe | undefined;
Expand All @@ -39,7 +39,7 @@ export default class Recipe extends RecipeModule {
emailDelivery: EmailDeliveryIngredient<TypeThirdPartyEmailPasswordEmailDeliveryInput> | undefined;
}
);
static init(config: TypeInput): RecipeListFunction;
static init(config?: TypeInput): RecipeListFunction;
static reset(): void;
static getInstanceOrThrowError(): Recipe;
getAPIsHandled: () => APIHandled[];
Expand Down
62 changes: 26 additions & 36 deletions lib/build/recipe/thirdpartyemailpassword/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class Recipe extends recipeModule_1.default {
super(recipeId, appInfo);
this.getAPIsHandled = () => {
let apisHandled = [...this.emailPasswordRecipe.getAPIsHandled()];
if (this.thirdPartyRecipe !== undefined) {
apisHandled.push(...this.thirdPartyRecipe.getAPIsHandled());
}
apisHandled.push(...this.thirdPartyRecipe.getAPIsHandled());
return apisHandled;
};
this.handleAPIRequest = (id, tenantId, req, res, path, method, userContext) =>
Expand All @@ -95,7 +93,6 @@ class Recipe extends recipeModule_1.default {
);
}
if (
this.thirdPartyRecipe !== undefined &&
(yield this.thirdPartyRecipe.returnAPIIdIfCanHandleRequest(path, method, userContext)) !== undefined
) {
return yield this.thirdPartyRecipe.handleAPIRequest(
Expand All @@ -117,28 +114,23 @@ class Recipe extends recipeModule_1.default {
} else {
if (this.emailPasswordRecipe.isErrorFromThisRecipe(err)) {
return yield this.emailPasswordRecipe.handleError(err, request, response);
} else if (
this.thirdPartyRecipe !== undefined &&
this.thirdPartyRecipe.isErrorFromThisRecipe(err)
) {
} else if (this.thirdPartyRecipe.isErrorFromThisRecipe(err)) {
return yield this.thirdPartyRecipe.handleError(err, request, response);
}
throw err;
}
});
this.getAllCORSHeaders = () => {
let corsHeaders = [...this.emailPasswordRecipe.getAllCORSHeaders()];
if (this.thirdPartyRecipe !== undefined) {
corsHeaders.push(...this.thirdPartyRecipe.getAllCORSHeaders());
}
corsHeaders.push(...this.thirdPartyRecipe.getAllCORSHeaders());
return corsHeaders;
};
this.isErrorFromThisRecipe = (err) => {
return (
error_1.default.isErrorFromSuperTokens(err) &&
(err.fromRecipe === Recipe.RECIPE_ID ||
this.emailPasswordRecipe.isErrorFromThisRecipe(err) ||
(this.thirdPartyRecipe !== undefined && this.thirdPartyRecipe.isErrorFromThisRecipe(err)))
this.thirdPartyRecipe.isErrorFromThisRecipe(err))
);
};
this.config = utils_1.validateAndNormaliseUserInput(this, appInfo, config);
Expand Down Expand Up @@ -194,33 +186,31 @@ class Recipe extends recipeModule_1.default {
emailDelivery: this.emailDelivery,
}
);
if (this.config.providers.length !== 0) {
this.thirdPartyRecipe =
recipes.thirdPartyInstance !== undefined
? recipes.thirdPartyInstance
: new recipe_2.default(
recipeId,
appInfo,
isInServerlessEnv,
{
override: {
functions: (_) => {
return thirdPartyRecipeImplementation_1.default(this.recipeInterfaceImpl);
},
apis: (_) => {
return thirdPartyAPIImplementation_1.default(this.apiImpl);
},
this.thirdPartyRecipe =
recipes.thirdPartyInstance !== undefined
? recipes.thirdPartyInstance
: new recipe_2.default(
recipeId,
appInfo,
isInServerlessEnv,
{
override: {
functions: (_) => {
return thirdPartyRecipeImplementation_1.default(this.recipeInterfaceImpl);
},
signInAndUpFeature: {
providers: this.config.providers,
apis: (_) => {
return thirdPartyAPIImplementation_1.default(this.apiImpl);
},
},
{},
{
emailDelivery: this.emailDelivery,
}
);
}
signInAndUpFeature: {
providers: this.config.providers,
},
},
{},
{
emailDelivery: this.emailDelivery,
}
);
}
static init(config) {
return (appInfo, isInServerlessEnv) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { ProviderInput } from "../../thirdparty/types";
export default function getRecipeInterface(
emailPasswordQuerier: Querier,
getEmailPasswordConfig: () => TypeNormalisedInput,
thirdPartyQuerier?: Querier,
thirdPartyQuerier: Querier,
providers?: ProviderInput[]
): RecipeInterface;
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ function getRecipeInterface(emailPasswordQuerier, getEmailPasswordConfig, thirdP
emailPasswordQuerier,
getEmailPasswordConfig
);
let originalThirdPartyImplementation;
if (thirdPartyQuerier !== undefined) {
originalThirdPartyImplementation = recipeImplementation_2.default(thirdPartyQuerier, providers);
}
let originalThirdPartyImplementation = recipeImplementation_2.default(thirdPartyQuerier, providers);
return {
emailPasswordSignUp: function (input) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -66,29 +63,20 @@ function getRecipeInterface(emailPasswordQuerier, getEmailPasswordConfig, thirdP
},
thirdPartySignInUp: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
throw new Error("No thirdparty provider configured");
}
return originalThirdPartyImplementation.signInUp.bind(thirdPartyRecipeImplementation_1.default(this))(
input
);
});
},
thirdPartyManuallyCreateOrUpdateUser: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
throw new Error("No thirdparty provider configured");
}
return originalThirdPartyImplementation.manuallyCreateOrUpdateUser.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
});
},
thirdPartyGetProvider: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
throw new Error("No thirdparty provider configured");
}
return originalThirdPartyImplementation.getProvider.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
Expand All @@ -102,9 +90,6 @@ function getRecipeInterface(emailPasswordQuerier, getEmailPasswordConfig, thirdP
if (user !== undefined) {
return user;
}
if (originalThirdPartyImplementation === undefined) {
return undefined;
}
return yield originalThirdPartyImplementation.getUserById.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
Expand All @@ -115,9 +100,6 @@ function getRecipeInterface(emailPasswordQuerier, getEmailPasswordConfig, thirdP
let userFromEmailPass = yield originalEmailPasswordImplementation.getUserByEmail.bind(
emailPasswordRecipeImplementation_1.default(this)
)({ email, tenantId, userContext });
if (originalThirdPartyImplementation === undefined) {
return userFromEmailPass === undefined ? [] : [userFromEmailPass];
}
let usersFromThirdParty = yield originalThirdPartyImplementation.getUsersByEmail.bind(
thirdPartyRecipeImplementation_1.default(this)
)({ email, tenantId, userContext });
Expand All @@ -129,9 +111,6 @@ function getRecipeInterface(emailPasswordQuerier, getEmailPasswordConfig, thirdP
},
getUserByThirdPartyInfo: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
return undefined;
}
return originalThirdPartyImplementation.getUserByThirdPartyInfo.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
Expand Down
62 changes: 26 additions & 36 deletions lib/build/recipe/thirdpartypasswordless/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class Recipe extends recipeModule_1.default {
super(recipeId, appInfo);
this.getAPIsHandled = () => {
let apisHandled = [...this.passwordlessRecipe.getAPIsHandled()];
if (this.thirdPartyRecipe !== undefined) {
apisHandled.push(...this.thirdPartyRecipe.getAPIsHandled());
}
apisHandled.push(...this.thirdPartyRecipe.getAPIsHandled());
return apisHandled;
};
this.handleAPIRequest = (id, tenantId, req, res, path, method, userContext) =>
Expand All @@ -96,7 +94,6 @@ class Recipe extends recipeModule_1.default {
);
}
if (
this.thirdPartyRecipe !== undefined &&
(yield this.thirdPartyRecipe.returnAPIIdIfCanHandleRequest(path, method, userContext)) !== undefined
) {
return yield this.thirdPartyRecipe.handleAPIRequest(
Expand All @@ -118,28 +115,23 @@ class Recipe extends recipeModule_1.default {
} else {
if (this.passwordlessRecipe.isErrorFromThisRecipe(err)) {
return yield this.passwordlessRecipe.handleError(err, request, response);
} else if (
this.thirdPartyRecipe !== undefined &&
this.thirdPartyRecipe.isErrorFromThisRecipe(err)
) {
} else if (this.thirdPartyRecipe.isErrorFromThisRecipe(err)) {
return yield this.thirdPartyRecipe.handleError(err, request, response);
}
throw err;
}
});
this.getAllCORSHeaders = () => {
let corsHeaders = [...this.passwordlessRecipe.getAllCORSHeaders()];
if (this.thirdPartyRecipe !== undefined) {
corsHeaders.push(...this.thirdPartyRecipe.getAllCORSHeaders());
}
corsHeaders.push(...this.thirdPartyRecipe.getAllCORSHeaders());
return corsHeaders;
};
this.isErrorFromThisRecipe = (err) => {
return (
error_1.default.isErrorFromSuperTokens(err) &&
(err.fromRecipe === Recipe.RECIPE_ID ||
this.passwordlessRecipe.isErrorFromThisRecipe(err) ||
(this.thirdPartyRecipe !== undefined && this.thirdPartyRecipe.isErrorFromThisRecipe(err)))
this.thirdPartyRecipe.isErrorFromThisRecipe(err))
);
};
this.isInServerlessEnv = isInServerlessEnv;
Expand Down Expand Up @@ -190,33 +182,31 @@ class Recipe extends recipeModule_1.default {
smsDelivery: this.smsDelivery,
}
);
if (this.config.providers.length !== 0) {
this.thirdPartyRecipe =
recipes.thirdPartyInstance !== undefined
? recipes.thirdPartyInstance
: new recipe_2.default(
recipeId,
appInfo,
isInServerlessEnv,
{
override: {
functions: (_) => {
return thirdPartyRecipeImplementation_1.default(this.recipeInterfaceImpl);
},
apis: (_) => {
return thirdPartyAPIImplementation_1.default(this.apiImpl);
},
this.thirdPartyRecipe =
recipes.thirdPartyInstance !== undefined
? recipes.thirdPartyInstance
: new recipe_2.default(
recipeId,
appInfo,
isInServerlessEnv,
{
override: {
functions: (_) => {
return thirdPartyRecipeImplementation_1.default(this.recipeInterfaceImpl);
},
signInAndUpFeature: {
providers: this.config.providers,
apis: (_) => {
return thirdPartyAPIImplementation_1.default(this.apiImpl);
},
},
{},
{
emailDelivery: this.emailDelivery,
}
);
}
signInAndUpFeature: {
providers: this.config.providers,
},
},
{},
{
emailDelivery: this.emailDelivery,
}
);
}
static init(config) {
return (appInfo, isInServerlessEnv) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { Querier } from "../../../querier";
import { ProviderInput } from "../../thirdparty/types";
export default function getRecipeInterface(
passwordlessQuerier: Querier,
thirdPartyQuerier?: Querier,
thirdPartyQuerier: Querier,
providers?: ProviderInput[]
): RecipeInterface;
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ const passwordlessRecipeImplementation_1 = __importDefault(require("./passwordle
const thirdPartyRecipeImplementation_1 = __importDefault(require("./thirdPartyRecipeImplementation"));
function getRecipeInterface(passwordlessQuerier, thirdPartyQuerier, providers = []) {
let originalPasswordlessImplementation = recipeImplementation_1.default(passwordlessQuerier);
let originalThirdPartyImplementation;
if (thirdPartyQuerier !== undefined) {
originalThirdPartyImplementation = recipeImplementation_2.default(thirdPartyQuerier, providers);
}
let originalThirdPartyImplementation = recipeImplementation_2.default(thirdPartyQuerier, providers);
return {
consumeCode: function (input) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -136,29 +133,20 @@ function getRecipeInterface(passwordlessQuerier, thirdPartyQuerier, providers =
},
thirdPartySignInUp: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
throw new Error("No thirdparty provider configured");
}
return originalThirdPartyImplementation.signInUp.bind(thirdPartyRecipeImplementation_1.default(this))(
input
);
});
},
thirdPartyManuallyCreateOrUpdateUser: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
throw new Error("No thirdparty provider configured");
}
return originalThirdPartyImplementation.manuallyCreateOrUpdateUser.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
});
},
thirdPartyGetProvider: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
throw new Error("No thirdparty provider configured");
}
return originalThirdPartyImplementation.getProvider.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
Expand All @@ -172,9 +160,6 @@ function getRecipeInterface(passwordlessQuerier, thirdPartyQuerier, providers =
if (user !== undefined) {
return user;
}
if (originalThirdPartyImplementation === undefined) {
return undefined;
}
return yield originalThirdPartyImplementation.getUserById.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
Expand All @@ -185,9 +170,6 @@ function getRecipeInterface(passwordlessQuerier, thirdPartyQuerier, providers =
let userFromEmailPass = yield originalPasswordlessImplementation.getUserByEmail.bind(
passwordlessRecipeImplementation_1.default(this)
)({ email, tenantId, userContext });
if (originalThirdPartyImplementation === undefined) {
return userFromEmailPass === undefined ? [] : [userFromEmailPass];
}
let usersFromThirdParty = yield originalThirdPartyImplementation.getUsersByEmail.bind(
thirdPartyRecipeImplementation_1.default(this)
)({ email, tenantId, userContext });
Expand All @@ -199,9 +181,6 @@ function getRecipeInterface(passwordlessQuerier, thirdPartyQuerier, providers =
},
getUserByThirdPartyInfo: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (originalThirdPartyImplementation === undefined) {
return undefined;
}
return originalThirdPartyImplementation.getUserByThirdPartyInfo.bind(
thirdPartyRecipeImplementation_1.default(this)
)(input);
Expand Down
Loading
Loading