Skip to content

Commit

Permalink
📦 NEW: #101 Allow password reset token to be passed when calling subm…
Browse files Browse the repository at this point in the history
…itPassword function
  • Loading branch information
souvik666 committed Mar 7, 2024
1 parent 13d4362 commit 2fe9b89
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 108 deletions.
218 changes: 110 additions & 108 deletions lib/ts/recipe/emailpassword/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,52 @@ export default function getRecipeImplementation(
formFields,
options,
userContext,
passwordToken
}: {
formFields: {
id: string;
value: string;
}[];
options?: RecipeFunctionOptions;
userContext: any;
passwordToken?: string
}): Promise<
| {
status: "OK";
fetchResponse: Response;
}
status: "OK";
fetchResponse: Response;
}
| {
status: "RESET_PASSWORD_INVALID_TOKEN_ERROR";
fetchResponse: Response;
}
status: "RESET_PASSWORD_INVALID_TOKEN_ERROR";
fetchResponse: Response;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
> {
const tenantId = this.getTenantIdFromURL({ userContext });
const token = this.getResetPasswordTokenFromURL({
const token = passwordToken || this.getResetPasswordTokenFromURL({
userContext,
});

const { jsonBody, fetchResponse } = await querier.post<
| {
status: "OK";
}
status: "OK";
}
| {
status: "RESET_PASSWORD_INVALID_TOKEN_ERROR";
}
status: "RESET_PASSWORD_INVALID_TOKEN_ERROR";
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
>(
tenantId,
"/user/password/reset",
Expand Down Expand Up @@ -123,38 +125,38 @@ export default function getRecipeImplementation(
userContext: any;
}): Promise<
| {
status: "OK";
fetchResponse: Response;
}
status: "OK";
fetchResponse: Response;
}
| {
status: "PASSWORD_RESET_NOT_ALLOWED";
reason: string;
fetchResponse: Response;
}
status: "PASSWORD_RESET_NOT_ALLOWED";
reason: string;
fetchResponse: Response;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
> {
let { jsonBody, fetchResponse } = await querier.post<
| {
status: "OK";
}
status: "OK";
}
| {
status: "PASSWORD_RESET_NOT_ALLOWED";
reason: string;
}
status: "PASSWORD_RESET_NOT_ALLOWED";
reason: string;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
>(
await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ userContext }),
"/user/password/reset/token",
Expand Down Expand Up @@ -207,40 +209,40 @@ export default function getRecipeImplementation(
userContext: any;
}): Promise<
| {
status: "OK";
user: User;
fetchResponse: Response;
}
status: "OK";
user: User;
fetchResponse: Response;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
| {
status: "SIGN_UP_NOT_ALLOWED";
reason: string;
fetchResponse: Response;
}
status: "SIGN_UP_NOT_ALLOWED";
reason: string;
fetchResponse: Response;
}
> {
let { jsonBody, fetchResponse } = await querier.post<
| {
status: "OK";
user: User;
}
status: "OK";
user: User;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
| {
status: "SIGN_UP_NOT_ALLOWED";
reason: string;
}
status: "SIGN_UP_NOT_ALLOWED";
reason: string;
}
>(
await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ userContext }),
"/signup",
Expand Down Expand Up @@ -293,47 +295,47 @@ export default function getRecipeImplementation(
userContext: any;
}): Promise<
| {
status: "OK";
user: User;
fetchResponse: Response;
}
status: "OK";
user: User;
fetchResponse: Response;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
fetchResponse: Response;
}
| {
status: "WRONG_CREDENTIALS_ERROR";
fetchResponse: Response;
}
status: "WRONG_CREDENTIALS_ERROR";
fetchResponse: Response;
}
| {
status: "SIGN_IN_NOT_ALLOWED";
reason: string;
fetchResponse: Response;
}
status: "SIGN_IN_NOT_ALLOWED";
reason: string;
fetchResponse: Response;
}
> {
let { jsonBody, fetchResponse } = await querier.post<
| {
status: "OK";
user: User;
}
status: "OK";
user: User;
}
| {
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
status: "FIELD_ERROR";
formFields: {
id: string;
error: string;
}[];
}
| {
status: "WRONG_CREDENTIALS_ERROR";
}
status: "WRONG_CREDENTIALS_ERROR";
}
| {
status: "SIGN_IN_NOT_ALLOWED";
reason: string;
}
status: "SIGN_IN_NOT_ALLOWED";
reason: string;
}
>(
await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ userContext }),
"/signin",
Expand Down
1 change: 1 addition & 0 deletions lib/ts/recipe/emailpassword/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type RecipeInterface = {
}[];
options?: RecipeFunctionOptions;
userContext: any;
passwordToken?: string
}) => Promise<
| {
status: "OK";
Expand Down

0 comments on commit 2fe9b89

Please sign in to comment.