Skip to content
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

Customize error message for expired password #279

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/features/auth/LoginForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { styled } from '../../theme/stitches.config.js';
import { Auth } from 'aws-amplify';
import { Authenticator, useAuthenticator } from '@aws-amplify/ui-react';
import { indigo } from '@radix-ui/colors';
import Button from '../../components/Button.jsx';
Expand Down Expand Up @@ -163,6 +164,20 @@ const LoginForm = () => {
const { route, toSignIn } = useAuthenticator((context) => [context.route]);
const userName = useSelector(selectUserUsername);

const services = {
async handleSignIn(input) {
try {
const { username, password } = input;
return await Auth.signIn(username, password);
} catch (error) {
console.log(error.code);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still trying to figure out the corresponding error code for an expired password. Unsure how to trigger this until I use an expired temp password that I have ready on Friday(1/17)

Seems unclear from this list: https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_InitiateAuth.html#API_InitiateAuth_Errors

Copy link
Contributor Author

@jue-henry jue-henry Jan 16, 2025

Choose a reason for hiding this comment

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

Might be UserNotConfirmedException but will confirm

throw new Error(
'Temporary password has expired and must be reset by an Project Manager. For more information see: https://docs.animl.camera/fundamentals/user-management',
);
}
},
};

const helperText = {
confirmResetPassword: 'Reset your password',
resetPassword: 'Enter your email address to receive a password reset code',
Expand All @@ -173,7 +188,12 @@ const LoginForm = () => {
<LoginScreen>
<Header css={{ '@bp3': { fontSize: '64px' } }}>Welcome back</Header>
<Subheader>{helperText[route] || userName || ''}</Subheader>
<StyledAuthenticator loginMechanisms={['email']} hideDefault={true} hideSignUp={true} />
<StyledAuthenticator
services={services}
loginMechanisms={['email']}
hideDefault={true}
hideSignUp={true}
/>
{route === 'resetPassword' && (
<StyledLoginCallout>
<Callout type="info" title="Note about temporary passwords">
Expand Down
Loading