Skip to content

Commit

Permalink
fix: format email values
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozwiaczek committed Nov 12, 2020
1 parent de2426c commit ca32c9f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
17 changes: 9 additions & 8 deletions src/containers/ConfirmSignUp/ConfirmSignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export const ConfirmSignUp: FC<ConfirmSignUpProps> = ({
resendButtonColor = 'default',
...rest
}) => {
const confirmSignUp = useCallback(
async (values: any) =>
Auth.confirmSignUp(values.email, values.code).then(async (result) => {
onSubmitResult && (await onSubmitResult(result));
return onSuccessLoginMsg;
}),
[],
);
const confirmSignUp = useCallback(async (values: any) => {
const { email, code } = values;
const formattedEmail = email.trim().toLowerCase();

return Auth.confirmSignUp(formattedEmail, code).then(async (result) => {
onSubmitResult && (await onSubmitResult(result));
return onSuccessLoginMsg;
});
}, []);

const formActionsBeforeConfirm = (
<ResendConfirmationCodeButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const ResendConfirmationCodeButton: FC<ResendConfirmationCodeProps> = ({

const resendCode = useCallback(async () => {
setInternalLoading(true);
await Auth.resendSignUp(values.email)
const { email } = values;
const formattedEmail = email.trim().toLowerCase();

await Auth.resendSignUp(formattedEmail)
.then(() => {
showSnackbar({ message: onSuccessResendMsg, severity: 'success' });
})
Expand Down
29 changes: 15 additions & 14 deletions src/containers/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ export const SignIn: FC<SignInProps> = ({
const [cognitoUserSession, setCognitoUserSession] = useState<CognitoUser>();
const [loggedIn, setLoggedIn] = useState(false);

const signIn = useCallback(
async (values): Promise<string> =>
Auth.signIn({
username: values.email.trim().toLowerCase(),
password: values.password,
}).then(async (user) => {
setCognitoUser(user);
setCognitoUserSession(user.signInUserSession);
setLoggedIn(true);
onSubmitResult && (await onSubmitResult(user));
return onSuccessLoginMsg;
}),
[],
);
const signIn = useCallback(async (values): Promise<string> => {
const { email, password } = values;
const formattedEmail = email.trim().toLowerCase();

return Auth.signIn({
username: formattedEmail,
password,
}).then(async (user) => {
setCognitoUser(user);
setCognitoUserSession(user.signInUserSession);
setLoggedIn(true);
onSubmitResult && (await onSubmitResult(user));
return onSuccessLoginMsg;
});
}, []);

return (
<Form
Expand Down
35 changes: 18 additions & 17 deletions src/containers/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,24 @@ export const SignUp: FC<SignUpProps> = ({
const [cognitoUserSession, setCognitoUserSession] = useState<any>();
const [loggedIn, setLoggedIn] = useState(false);

const signUp = useCallback(
async (values: any): Promise<string> =>
Auth.signUp({
username: values.email,
password: values.password,
attributes: {
email: values.email,
},
}).then(async (result) => {
setCognitoUser(result.user);
setCognitoUserSession(result.user.getSignInUserSession());
setLoggedIn(true);
onSubmitResult && (await onSubmitResult(result));
return onSuccessLoginMsg;
}),
[],
);
const signUp = useCallback(async (values: any): Promise<string> => {
const { email, password } = values;
const formattedEmail = email.trim().toLowerCase();

return Auth.signUp({
username: formattedEmail,
password,
attributes: {
email: formattedEmail,
},
}).then(async (result) => {
setCognitoUser(result.user);
setCognitoUserSession(result.user.getSignInUserSession());
setLoggedIn(true);
onSubmitResult && (await onSubmitResult(result));
return onSuccessLoginMsg;
});
}, []);

const SubheaderContent = () => (
<>
Expand Down

0 comments on commit ca32c9f

Please sign in to comment.