Skip to content

Commit

Permalink
Passes error message to user from forced password change
Browse files Browse the repository at this point in the history
The error messages were getting swallowed up by the console and not
informing the user that their password was not a valid choice. This
passes those messages back to the user and allows them to try again.
  • Loading branch information
neomorphic committed May 10, 2022
1 parent dc8add8 commit 9661b49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions website/src/components/LoginForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { Form, Button, Input } from "antd";
import { Form, Button, Input, message } from "antd";
import { useAuth } from "../contexts/AuthContext";
import { Link, useNavigate, useLocation } from "react-router-dom";

Expand All @@ -18,9 +18,11 @@ export default function LoginForm() {
values.username,
values.password,
values.newPassword,
(userObject) => {
(userObject, error) => {
setIsLoading(false);
if (
if (error) {
message.error(error.message);
} else if (
userObject &&
userObject.challengeName === "NEW_PASSWORD_REQUIRED"
) {
Expand Down Expand Up @@ -59,7 +61,7 @@ export default function LoginForm() {
{passwordUpdate ? (
<Form.Item
label="New Password"
extra="You are required to change you password. Please enter a new one here."
extra="You are required to change you password. Please enter a new one here. minimum length: 14 characters"
name="newPassword"
rules={[{ required: true, message: "Please create a new password!" }]}
>
Expand Down
14 changes: 8 additions & 6 deletions website/src/contexts/AuthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function AuthProvider({ children }) {
userObject, // the Cognito User Object
newPassword, // the new password
requiredAttributes
).then((updatedUser) => {
// at this time the user is logged in if no MFA required
setUser(user);
checkAdminStatus(() => setIsAdmin(true));
callback(updatedUser);
});
)
.then((updatedUser) => {
// at this time the user is logged in if no MFA required
setUser(user);
checkAdminStatus(() => setIsAdmin(true));
callback(updatedUser);
})
.catch((error) => callback(null, error));
} else {
callback(userObject);
}
Expand Down

0 comments on commit 9661b49

Please sign in to comment.