- Notifications
You must be signed in to change notification settings - Fork928
fix: handlegetUser
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
fbd0c6d
8dcd958
52c23fb
ade96de
da9c675
4bcf5e7
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,9 +13,10 @@ export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => { | ||
const xServices = useContext(XServiceContext) | ||
const [authState] = useActor(xServices.authXService) | ||
const location = useLocation() | ||
const isHomePage = location.pathname === "/" | ||
const navigateTo = isHomePage ? "/login" : embedRedirect(location.pathname) | ||
if (authState.matches("signedOut")) { | ||
return <Navigate to={navigateTo}state={{ isRedirect: !isHomePage }}/> | ||
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. does 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. I think wecould 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 commentThe 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. | ||
} else if (authState.hasTag("loading")) { | ||
return <FullScreenLoader /> | ||
} else { | ||
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 {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,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={{ | ||||||
[LoginErrors.AUTH_ERROR]: authError, | ||||||
[LoginErrors.GET_USER_ERROR]: isRedirected ? getUserError : null, | ||||||
[LoginErrors.CHECK_PERMISSIONS_ERROR]: checkPermissionsError, | ||||||
[LoginErrors.GET_METHODS_ERROR]: getMethodsError, | ||||||
}} | ||||||
onSubmit={onSubmit} | ||||||
/> | ||||||