Skip to content

fix: handle getUser error - #3285

Merged
AbhineetJain merged 6 commits into
mainfrom
abhineetjain/handle-get-user-error
Jul 29, 2022
Merged

AbhineetJain merged 6 commits into
mainfrom
abhineetjain/handle-get-user-error

Conversation

@AbhineetJain

@AbhineetJain AbhineetJain commented Jul 29, 2022 •

Copy link
Copy Markdown
Contributor

Building on #3241, this PR handles the getUser error from authXService.

Special criteria: The error is only shown when redirecting to the /login page from a page other than /. It is also not shown when loading the /login page directly.

Subtasks

  • show getUser error above the Sign-in form
  • restrict showing the error only when redirecting (except redirecting from /)
  • added stories
  • update relevant backend API middleware errors to have the a You are signed out. or An internal error occurred message and move the details in the error details section.

Fixes #3088

Screenshot

Screen Shot 2022-07-28 at 11 14 29 PM

@AbhineetJain
AbhineetJain requested review from a team July 29, 2022 02:55
@AbhineetJain AbhineetJain self-assigned this Jul 29, 2022
Comment thread coderd/httpmw/apikey.go Resolved

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to see the 500 error changed, but other than that, backend looks good. 👍🏻

Comment thread coderd/httpmw/apikey.go Resolved
Comment thread site/src/pages/LoginPage/LoginPage.tsx Resolved
const [authState, authSend] = useActor(xServices.authXService)
const isLoading = authState.hasTag("loading")
const redirectTo = retrieveRedirect(location.search)
const locationState = location.state ? (location.state as LocationState) : null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to use a ternary because of types? Or can we:

Suggested change
const locationState = location.state ? (location.state as LocationState) : null
const locationState = location.state ?? null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

location.state can be null, but since we are typecasting it, the compiler thinks it is never null, so we are typecasting it only if it is not null.

@Kira-Pilot Kira-Pilot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FE looks great!

const navigateTo = isHomePage ? "/login" : embedRedirect(location.pathname)
if (authState.matches("signedOut")) {
return <Navigate to={navigateTo} />
return <Navigate to={navigateTo} state={{ isRedirect: !isHomePage }} />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does isRedirect replicate the functionality of embedRedirect?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we could use one both to know whether to show the error and where to go next, but it might be better to keep them separate like this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we’d probably have to retrieve the redirect in the component but that didn’t seem like a very solid approach.

@AbhineetJain
AbhineetJain merged commit e94fe20 into main Jul 29, 2022
@AbhineetJain
AbhineetJain deleted the abhineetjain/handle-get-user-error branch July 29, 2022 17:10
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.

Fix error messages in authXService

6 participants