-
Notifications
You must be signed in to change notification settings - Fork 881
fix: handle getUser
error
#3285
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
Changes from all commits
fbd0c6d
8dcd958
52c23fb
ade96de
da9c675
4bcf5e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ import React, { useContext } from "react" | |||||
import { Helmet } from "react-helmet" | ||||||
import { Navigate, useLocation } from "react-router-dom" | ||||||
import { Footer } from "../../components/Footer/Footer" | ||||||
import { SignInForm } from "../../components/SignInForm/SignInForm" | ||||||
import { LoginErrors, SignInForm } from "../../components/SignInForm/SignInForm" | ||||||
import { pageTitle } from "../../util/page" | ||||||
import { retrieveRedirect } from "../../util/redirect" | ||||||
import { XServiceContext } from "../../xServices/StateContext" | ||||||
|
@@ -28,19 +28,25 @@ export const useStyles = makeStyles((theme) => ({ | |||||
}, | ||||||
})) | ||||||
|
||||||
interface LocationState { | ||||||
isRedirect: boolean | ||||||
} | ||||||
|
||||||
export const LoginPage: React.FC = () => { | ||||||
const styles = useStyles() | ||||||
const location = useLocation() | ||||||
const xServices = useContext(XServiceContext) | ||||||
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 | ||||||
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. Do we need to use a ternary because of types? Or can we:
Suggested change
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.
|
||||||
const isRedirected = locationState ? locationState.isRedirect : false | ||||||
|
||||||
const onSubmit = async ({ email, password }: { email: string; password: string }) => { | ||||||
authSend({ type: "SIGN_IN", email, password }) | ||||||
} | ||||||
|
||||||
const { authError, checkPermissionsError, getMethodsError } = authState.context | ||||||
const { authError, getUserError, checkPermissionsError, getMethodsError } = authState.context | ||||||
|
||||||
if (authState.matches("signedIn")) { | ||||||
return <Navigate to={redirectTo} replace /> | ||||||
|
@@ -57,9 +63,10 @@ export const LoginPage: React.FC = () => { | |||||
redirectTo={redirectTo} | ||||||
isLoading={isLoading} | ||||||
loginErrors={{ | ||||||
authError, | ||||||
checkPermissionsError, | ||||||
getMethodsError, | ||||||
[LoginErrors.AUTH_ERROR]: authError, | ||||||
[LoginErrors.GET_USER_ERROR]: isRedirected ? getUserError : null, | ||||||
[LoginErrors.CHECK_PERMISSIONS_ERROR]: checkPermissionsError, | ||||||
[LoginErrors.GET_METHODS_ERROR]: getMethodsError, | ||||||
}} | ||||||
onSubmit={onSubmit} | ||||||
/> | ||||||
|
There was a problem hiding this comment.
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 ofembedRedirect
?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.