Skip to content

Commit

Permalink
Added non-flexible identifier check for reset-password-request primar…
Browse files Browse the repository at this point in the history
…y submit handler
  • Loading branch information
gyaneshgouraw-okta committed Feb 5, 2025
1 parent 87e5a5c commit c6c859d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/auth0-acul-js/interfaces/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,5 @@ export interface TransactionMembers {
errors: Error[] | null;
currentConnection: Connection | null;
alternateConnections: (Connection | EnterpriseConnection)[] | null;
hasFlexibleIdentifier: boolean;
}
5 changes: 5 additions & 0 deletions packages/auth0-acul-js/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class Transaction implements TransactionMembers {
errors: TransactionMembers['errors'];
currentConnection: TransactionMembers['currentConnection'];
alternateConnections: TransactionMembers['alternateConnections'];
hasFlexibleIdentifier: boolean;

constructor(transaction: TransactionContext) {
this.state = transaction.state;
Expand All @@ -21,6 +22,7 @@ export class Transaction implements TransactionMembers {
this.errors = Transaction.getErrors(transaction);
this.currentConnection = Transaction.getCurrentConnection(transaction);
this.alternateConnections = Transaction.getAlternateConnections(transaction);
this.hasFlexibleIdentifier = this.isFlexibleIdentifier(transaction.connection?.options);
}

static getErrors(transaction: TransactionContext): TransactionMembers['errors'] {
Expand Down Expand Up @@ -74,4 +76,7 @@ export class Transaction implements TransactionMembers {
return connectionProperties;
});
}
isFlexibleIdentifier(options: Record<string, unknown> | null | undefined): boolean {
return options !== null && options !== undefined && typeof options === 'object' && 'attributes' in options;

This comment has been minimized.

Copy link
@gyaneshgouraw-okta

gyaneshgouraw-okta Feb 5, 2025

Author Contributor

@nandan-bhat
I added a new isFlexibleIdentifier property at the base transaction level.

An alternative approach would have been to add a property specific to the reset-password-request transaction override. However, that would have required using transaction.connection.attributes, which wasn't available. So, I would have still needed to update an existing base property or create a new one.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default class ResetPasswordRequest extends BaseContext implements ResetPa
const options: FormOptions = {
state: this.transaction.state,
};
await new FormHandler(options).submitData(payload);
const updatedPayload = this.updatePayloadByIdentifier(payload);
await new FormHandler(options).submitData(updatedPayload);
}

/**
Expand All @@ -51,6 +52,18 @@ export default class ResetPasswordRequest extends BaseContext implements ResetPa
};
await new FormHandler(options).submitData<CustomOptions>({ ...payload, action: 'back-to-login' });
}

updatePayloadByIdentifier(payload: ResetPasswordRequestOptions): ResetPasswordRequestOptions {
if (!this.transaction.hasFlexibleIdentifier) {
console.log('Identified nonFlexibleIdentifier flow');

Check warning on line 58 in packages/auth0-acul-js/src/screens/reset-password-request/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test auth0-acul-js

Unexpected console statement
return {
...payload,
email: payload.username,
};
} else {
return payload;
}
}
}

export { ResetPasswordRequestMembers, ResetPasswordRequestOptions, ScreenOptions };
21 changes: 19 additions & 2 deletions packages/auth0-acul-js/src/screens/signup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class Signup extends BaseContext implements SignupMembers {
*
* @example
* ```typescript
* import Signup from '@auth0/auth0-acul-js/signup-new';
* import Signup from '@auth0/auth0-acul-js/signup';
*
* const signupManager = new Signup();
*
Expand All @@ -51,7 +51,7 @@ export default class Signup extends BaseContext implements SignupMembers {
*
* @example
* ```typescript
* import Signup from '@auth0/auth0-acul-js/signup-new';
* import Signup from '@auth0/auth0-acul-js/signup';
*
* const signupManager = new Signup();
*
Expand All @@ -66,6 +66,23 @@ export default class Signup extends BaseContext implements SignupMembers {
};
await new FormHandler(options).submitData<SocialSignupOptions>(payload);
}

/**
* @example
* import Signup from "@auth0/auth0-acul-js/signup";
* const signupManager = new Signup();
*
* signupManager.pickCountryCode();
*/
async pickCountryCode(): Promise<void> {
const options: FormOptions = {
state: this.transaction.state,
};

await new FormHandler(options).submitData({
action: 'pick-country-code',
});
}
}

export { SignupMembers, SignupOptions, ScreenOptions };

0 comments on commit c6c859d

Please sign in to comment.