Fix login.

This commit is contained in:
Paulo Gustavo Veiga 2024-02-06 22:43:22 -08:00
parent 20c4ccc1ff
commit fc0c03b2bc

View File

@ -25,18 +25,19 @@ export type Model = {
password: string; password: string;
}; };
export type LoginErrorProps = {
errorCode: number | undefined;
};
const defaultModel: Model = { email: '', password: '' }; const defaultModel: Model = { email: '', password: '' };
const LoginError = () => { const LoginError = ({ errorCode }: LoginErrorProps) => {
// @Todo: This must be reviewed to be based on navigation state.
// Login error example: http://localhost:8080/c/login?login.error=2
const errorCode = new URLSearchParams(window.location.search).get('login_error');
const intl = useIntl(); const intl = useIntl();
let msg: null | string = null; let msg: null | string = null;
if (errorCode) { if (errorCode) {
switch (errorCode) { switch (errorCode) {
case '3': case 3:
msg = intl.formatMessage({ msg = intl.formatMessage({
id: 'login.userinactive', id: 'login.userinactive',
defaultMessage: defaultMessage:
@ -56,6 +57,8 @@ const LoginError = () => {
const LoginPage = (): React.ReactElement => { const LoginPage = (): React.ReactElement => {
const intl = useIntl(); const intl = useIntl();
const [model, setModel] = useState<Model>(defaultModel); const [model, setModel] = useState<Model>(defaultModel);
const [loginError, setLoginError] = useState<number | undefined>(undefined);
const client: Client = useSelector(activeInstance); const client: Client = useSelector(activeInstance);
const navigate = useNavigate(); const navigate = useNavigate();
@ -72,7 +75,9 @@ const LoginPage = (): React.ReactElement => {
{ {
onSuccess: () => navigate('/c/maps/'), onSuccess: () => navigate('/c/maps/'),
onError: (error) => { onError: (error) => {
// Hardcode error code...
console.log(error); console.log(error);
setLoginError(2);
}, },
}, },
); );
@ -103,7 +108,7 @@ const LoginPage = (): React.ReactElement => {
<FormattedMessage id="login.desc" defaultMessage="Log into your account" /> <FormattedMessage id="login.desc" defaultMessage="Log into your account" />
</Typography> </Typography>
<LoginError /> <LoginError errorCode={loginError} />
<FormControl> <FormControl>
<form onSubmit={handleOnSubmit}> <form onSubmit={handleOnSubmit}>