- Notifications
You must be signed in to change notification settings - Fork928
fix: handle all auth API errors#3241
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
6ae13b1
fix: show errors on SSH Key page
AbhineetJainc37b4ec
handle all auth api errors
AbhineetJain865c1c5
add stories, refactor code
AbhineetJainc41fb43
Merge branch 'main' into abhineetjain/auth-service-unused-errors
AbhineetJain3ce260a
remove getUserError
AbhineetJaindadce4b
Merge branch 'main' into abhineetjain/auth-service-unused-errors
AbhineetJain3dbd3f3
use makeMockApiError helper
AbhineetJainFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
43 changes: 27 additions & 16 deletionssite/src/components/SignInForm/SignInForm.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
37 changes: 25 additions & 12 deletionssite/src/components/SignInForm/SignInForm.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionssite/src/pages/LoginPage/LoginPage.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletionssite/src/pages/LoginPage/LoginPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -40,6 +40,8 @@ export const LoginPage: React.FC = () => { | ||
authSend({ type: "SIGN_IN", email, password }) | ||
} | ||
const { authError, checkPermissionsError, getMethodsError } = authState.context | ||
if (authState.matches("signedIn")) { | ||
return <Navigate to={redirectTo} replace /> | ||
} else { | ||
@@ -54,8 +56,11 @@ export const LoginPage: React.FC = () => { | ||
authMethods={authState.context.methods} | ||
redirectTo={redirectTo} | ||
isLoading={isLoading} | ||
loginErrors={{ | ||
authError, | ||
checkPermissionsError, | ||
getMethodsError, | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nice! | ||
onSubmit={onSubmit} | ||
/> | ||
</div> | ||
7 changes: 4 additions & 3 deletionssite/src/pages/UserSettingsPage/SSHKeysPage/SSHKeysPage.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
45 changes: 17 additions & 28 deletionssite/src/pages/UserSettingsPage/SSHKeysPage/SSHKeysPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import { useActor } from "@xstate/react" | ||
import React, { useContext, useEffect } from "react" | ||
import { ConfirmDialog } from "../../../components/ConfirmDialog/ConfirmDialog" | ||
import { Section } from "../../../components/Section/Section" | ||
import { XServiceContext } from "../../../xServices/StateContext" | ||
import { SSHKeysPageView } from "./SSHKeysPageView" | ||
export const Language = { | ||
title: "SSH keys", | ||
description: | ||
"Coder automatically inserts a private key into every workspace; you can add the corresponding public key to any services (such as Git) that you need access to from your workspace.", | ||
regenerateDialogTitle: "Regenerate SSH key?", | ||
regenerateDialogMessage: | ||
"You will need to replace the public SSH key on services you use it with, and you'll need to rebuild existing workspaces.", | ||
@@ -24,36 +19,30 @@ export const Language = { | ||
export const SSHKeysPage: React.FC = () => { | ||
const xServices = useContext(XServiceContext) | ||
AbhineetJain marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
const [authState, authSend] = useActor(xServices.authXService) | ||
const { sshKey, getSSHKeyError, regenerateSSHKeyError } = authState.context | ||
useEffect(() => { | ||
authSend({ type: "GET_SSH_KEY" }) | ||
}, [authSend]) | ||
const isLoading = authState.matches("signedIn.ssh.gettingSSHKey") | ||
const hasLoaded = authState.matches("signedIn.ssh.loaded") | ||
const onRegenerateClick = () => { | ||
authSend({ type: "REGENERATE_SSH_KEY" }) | ||
} | ||
return ( | ||
<> | ||
<Section title={Language.title} description={Language.description}> | ||
<SSHKeysPageView | ||
isLoading={isLoading} | ||
hasLoaded={hasLoaded} | ||
getSSHKeyError={getSSHKeyError} | ||
regenerateSSHKeyError={regenerateSSHKeyError} | ||
sshKey={sshKey} | ||
onRegenerateClick={onRegenerateClick} | ||
/> | ||
</Section> | ||
<ConfirmDialog | ||
53 changes: 53 additions & 0 deletionssite/src/pages/UserSettingsPage/SSHKeysPage/SSHKeysPageView.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Story } from "@storybook/react" | ||
import { makeMockApiError } from "testHelpers/entities" | ||
import { SSHKeysPageView, SSHKeysPageViewProps } from "./SSHKeysPageView" | ||
export default { | ||
title: "components/SSHKeysPageView", | ||
component: SSHKeysPageView, | ||
argTypes: { | ||
onRegenerateClick: { action: "Submit" }, | ||
}, | ||
} | ||
const Template: Story<SSHKeysPageViewProps> = (args: SSHKeysPageViewProps) => ( | ||
<SSHKeysPageView {...args} /> | ||
) | ||
export const Example = Template.bind({}) | ||
Example.args = { | ||
isLoading: false, | ||
hasLoaded: true, | ||
sshKey: { | ||
user_id: "test-user-id", | ||
created_at: "2022-07-28T07:45:50.795918897Z", | ||
updated_at: "2022-07-28T07:45:50.795919142Z", | ||
public_key: "SSH-Key", | ||
}, | ||
onRegenerateClick: () => { | ||
return Promise.resolve() | ||
}, | ||
} | ||
export const Loading = Template.bind({}) | ||
Loading.args = { | ||
...Example.args, | ||
isLoading: true, | ||
} | ||
export const WithGetSSHKeyError = Template.bind({}) | ||
WithGetSSHKeyError.args = { | ||
...Example.args, | ||
hasLoaded: false, | ||
getSSHKeyError: makeMockApiError({ | ||
message: "Failed to get SSH key", | ||
}), | ||
} | ||
export const WithRegenerateSSHKeyError = Template.bind({}) | ||
WithRegenerateSSHKeyError.args = { | ||
...Example.args, | ||
regenerateSSHKeyError: makeMockApiError({ | ||
message: "Failed to regenerate SSH key", | ||
}), | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.