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

Passwordless | ResetPasswordEmailSentPage and API refactors #2881

Merged
merged 3 commits into from
Sep 9, 2024

Conversation

coldlink
Copy link
Member

@coldlink coldlink commented Sep 5, 2024

What does this change?

  • Sets up an ResetPasswordEmailSentPage component that displays the correct page based on whether we're using passcodes or the legacy link method
    • If we're using passcodes, as defined by hasStateHandle variable, then we show the PasscodeEmailSent component
      • If the passcode has already been used, then we show the PasscodeUsed component
    • If we're not using passcodes, then we show the EmailSent component as previously done
  • We also move challengeAuthenticatorSchema to shared/schemas.ts as it's also needed by the identifyRemediations type too
  • Finally we refactor the validate<ENDPOINT>Remediation methods into a single method called validateRemediation which takes type generics
    • Anything that was previously using the full method definition can just use the types instead, e.g. for validateChallengeAnswerRemediation it becomes
export const validateChallengeAnswerRemediation = validateRemediation<
	ChallengeAnswerResponse,
	ChallengeAnswerRemediationNames
>;

instead of

export const validateChallengeAnswerRemediation = (
	challengeAnswerResponse: ChallengeAnswerResponse,
	remediationName: ChallengeAnswerRemediationNames,
) => {
	const hasRemediation = challengeAnswerResponse.remediation.value.some(
		({ name }) => name === remediationName,
	);

	if (!hasRemediation) {
		throw new OAuthError(
			{
				error: 'invalid_request',
				error_description: `Remediation ${remediationName} not found in challenge/answer response`,
			},
			400,
		);
	}
};

@coldlink coldlink requested a review from a team as a code owner September 5, 2024 12:44
@coldlink coldlink changed the title Passwordless | ResetPasswordEmailSentPage and API refactors Passwordless | ResetPasswordEmailSentPage and API refactors Sep 5, 2024

if (!hasRemediation && useThrow) {
throw new Error(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
Copy link
Member Author

@coldlink coldlink Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed as typescript doesn't think that remediationName is a string type that it can put into a template expression even though it is, the tests above prove that: https://github.com/guardian/gateway/pull/2881/files#diff-b996cc3a1711f22fd1ace11e046c019d10b7e7d74ed0c8a2f4caa3750b9d3946R78

AshCorr
AshCorr previously approved these changes Sep 5, 2024
Copy link
Contributor

@akinsola-guardian akinsola-guardian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coldlink coldlink requested review from guardian-ci and removed request for guardian-ci September 9, 2024 10:02
@coldlink coldlink merged commit cb39dde into main Sep 9, 2024
19 checks passed
@coldlink coldlink deleted the mm/more-idx-refactors branch September 9, 2024 10:11
@coldlink coldlink added the passwordless PRs/Issues related to passwordless/passcode functionality label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
passwordless PRs/Issues related to passwordless/passcode functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants