Skip to content

Commit

Permalink
Update login step to show message about needing to reset password
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Dec 22, 2024
1 parent 5740b81 commit debd6aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/pages/api/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ const log = logger.child({}, { msgPrefix: '[api/login] ' });

export interface ILoginResponse {
success?: boolean;
error?: 'invalid-credentials' | 'login-failed' | 'failed-userdata-request' | 'invalid-token' | 'method-not-allowed';
error?:
| 'invalid-credentials'
| 'login-failed'
| 'failed-userdata-request'
| 'invalid-token'
| 'method-not-allowed'
| 'must-reset-credentials';
}

export default withIronSessionApiRoute(login, sessionConfig);
Expand Down Expand Up @@ -100,10 +106,16 @@ export const handleAuthentication = async (
return res.status(200).json({ success: false, error: 'failed-userdata-request' });
}
}
log.debug('Login failed', { data });
log.debug({ data }, 'Login failed');
return res.status(401).json({ success: false, error: 'login-failed' });
} catch (error) {
log.trace('Login failed', { error });
} catch (err) {
log.error({ err }, 'Login failed');

// if the login failed due to a password reset requirement, return a specific error
if (axios.isAxiosError(err) && err.response && err.response.status === HttpStatusCode.UnprocessableEntity) {
return res.status(401).json({ success: false, error: 'must-reset-credentials' });
}

return res.status(401).json({ success: false, error: 'login-failed' });
}
};
11 changes: 10 additions & 1 deletion src/pages/user/account/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Login: NextPage = () => {
['login'],
async (params) => {
const { data } = await axios.post<ILoginResponse>('/api/auth/login', params);

if (data?.error) {
throw new Error(data.error);
}
Expand Down Expand Up @@ -69,7 +70,7 @@ const Login: NextPage = () => {
if (isError) {
focus();
}
}, [isError]);
}, [isError, focus]);

return (
<>
Expand Down Expand Up @@ -143,6 +144,14 @@ const LoginErrorMessage = (props: { error: AxiosError<ILoginResponse> | Error })
case 'failed-userdata-request':
case 'invalid-token':
return <StandardAlertMessage status="error" title="Unable to login" description="Please try again later." />;
case 'must-reset-credentials':
return (
<StandardAlertMessage
status="error"
title="Please reset your password"
description="Your password does not meet the new security requirements. An email has been sent to you with instructions on how to reset your password."
/>
);
default:
return null;
}
Expand Down

0 comments on commit debd6aa

Please sign in to comment.