From 9661b49718c9764829767509348a73280e15165d Mon Sep 17 00:00:00 2001 From: Jody Clements Date: Tue, 10 May 2022 11:22:14 -0400 Subject: [PATCH] Passes error message to user from forced password change 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. --- website/src/components/LoginForm.jsx | 10 ++++++---- website/src/contexts/AuthContext.jsx | 14 ++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/website/src/components/LoginForm.jsx b/website/src/components/LoginForm.jsx index beb824f..1892be2 100644 --- a/website/src/components/LoginForm.jsx +++ b/website/src/components/LoginForm.jsx @@ -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"; @@ -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" ) { @@ -59,7 +61,7 @@ export default function LoginForm() { {passwordUpdate ? ( diff --git a/website/src/contexts/AuthContext.jsx b/website/src/contexts/AuthContext.jsx index b2599ae..1eb898b 100644 --- a/website/src/contexts/AuthContext.jsx +++ b/website/src/contexts/AuthContext.jsx @@ -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); }