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

SWC-7228 #1511

Merged
merged 3 commits into from
Jan 23, 2025
Merged

SWC-7228 #1511

merged 3 commits into from
Jan 23, 2025

Conversation

nickgros
Copy link
Collaborator

@nickgros nickgros commented Jan 22, 2025

Fix alias check on account creation with Google

image

image

Comment on lines +50 to +64
function BackButtonForPage(props: {
page: Pages
setPage: (page: Pages) => void
}) {
const { page, setPage } = props
switch (page) {
case Pages.CHOOSE_REGISTRATION:
return <BackButton to={'/authenticated/myaccount'} />
case Pages.EMAIL_REGISTRATION:
case Pages.GOOGLE_REGISTRATION:
return <BackButton onClick={() => setPage(Pages.CHOOSE_REGISTRATION)} />
default:
return <></>
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Extracted nested component definition (eslint: react/no-unstable-nested-components)

Comment on lines -151 to -154
if (!aliasCheckResponse.available) {
displayToast('Sorry, that username has already been taken.', 'danger')
} else if (!aliasCheckResponse.valid) {
displayToast('Sorry, that username is not valid.', 'danger')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to check valid flag first. Extracted this check to a validateAlias utility.

Comment on lines -171 to -177
.then((data: any) => {
const authUrl = data.authorizationUrl
window.location.assign(authUrl)
})
.catch((err: any) => {
displayToast(err.reason as string, 'danger')
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're already using try/catch here, so change this to an await

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused by this comment. Are you referring to the await SynapseClient.isAliasAvailable()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just mean SynapseClient.oAuthUrlRequest was written using .then(...).catch(...) when the error handling behavior inside the catch was identical to the error handling behavior in the try/catch that is already wrapping this code block.

So we get the same behavior with less, cleaner code by using await instead of promise callbacks

Comment on lines +66 to +76
function handleError(e: unknown) {
if (e instanceof SynapseClientError) {
displayToast(e.reason, 'danger')
} else if (e instanceof Error) {
displayToast(e.message, 'danger')
} else {
// This should never happen
console.error(e)
displayToast(JSON.stringify(e), 'danger')
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shared generic error handling on this page

@@ -269,9 +286,9 @@ export const RegisterAccount1 = () => {
)
}
value={email || ''}
onKeyPress={(e: any) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

onKeyPress is deprecated

Comment on lines +393 to 394
{page === Pages.GOOGLE_REGISTRATION && (
<Typography variant="body1" sx={{ marginBottom: '20px' }}>
Your <strong>Synapse</strong> account can also be used to
access many other resources from Sage Bionetworks.
{VALID_USERNAME_DESCRIPTION}
</Typography>
)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Show the username requirements when prompted for a username

Fix alias check on account creation with Google
Comment on lines +17 to +23
it('throws if invalid and unavailable, warning about validity', () => {
expect(() =>
validateAlias({ valid: false, available: false }),
).toThrowError(
'Sorry, that username is not valid. User names can contain letters, numbers, dot (.), dash (-) and underscore (_) and must be at least 3 characters long.',
)
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this test validates the issue

export function validateAlias(aliasCheckResponse: AliasCheckResponse) {
if (!aliasCheckResponse.valid) {
throw new Error(
`Sorry, that username is not valid. ${VALID_USERNAME_DESCRIPTION}`,
Copy link
Member

Choose a reason for hiding this comment

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

Really like the check for valid before available (invalid aliases are never available!)

)
})
it('throws if alias is invalid', () => {
expect(() => validateAlias({ valid: false, available: true })).toThrowError(
Copy link
Member

Choose a reason for hiding this comment

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

I think technically this scenario is not possible, but fine to leave it

type="button"
disabled={email && !isLoading ? false : true}
Copy link
Member

Choose a reason for hiding this comment

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

Yikes, did I really type this?
!isLoading ? false : true

}
}}
/>
</StyledFormControl>
<Button
sx={buttonSx}
variant="contained"
onClick={onSignUpWithGoogle}
onClick={e => {
void onSignUpWithGoogle(e)
Copy link
Member

Choose a reason for hiding this comment

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

Should this also clear the error state before attempted signup (same as clicking Enter)?
setUsernameInvalidReason(null)

Clear the error in the handler so it happens in every code path
@nickgros nickgros merged commit aabaddc into Sage-Bionetworks:main Jan 23, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants