IO-762 Validate pw reset OOB code.

This commit is contained in:
Patrick Fic
2021-03-17 14:16:11 -07:00
parent b3003249ae
commit 674dc5c83f
3 changed files with 31 additions and 2 deletions

View File

@@ -1,15 +1,17 @@
import { LockOutlined } from "@ant-design/icons"; import { LockOutlined } from "@ant-design/icons";
import { Button, Form, Input, Result, Typography } from "antd"; import { Button, Form, Input, Result, Typography } from "antd";
import React from "react"; import React, { useState, useEffect } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
import ImEXOnlineLogo from "../../assets/logo192.png"; import ImEXOnlineLogo from "../../assets/logo192.png";
import { auth } from "../../firebase/firebase.utils";
import { validatePasswordResetStart } from "../../redux/user/user.actions"; import { validatePasswordResetStart } from "../../redux/user/user.actions";
import { selectPasswordReset } from "../../redux/user/user.selectors"; import { selectPasswordReset } from "../../redux/user/user.selectors";
import AlertComponent from "../alert/alert.component"; import AlertComponent from "../alert/alert.component";
import "./user-validate-pw-reset.styles.scss"; import "./user-validate-pw-reset.styles.scss";
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
passwordReset: selectPasswordReset, passwordReset: selectPasswordReset,
@@ -25,11 +27,34 @@ export function UserValidatePwReset({
oobCode, oobCode,
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [codeValid, setCodeValid] = useState({ loading: true });
const handleFinish = (values) => { const handleFinish = (values) => {
validatePasswordReset({ code: oobCode, password: values.password }); validatePasswordReset({ code: oobCode, password: values.password });
}; };
useEffect(() => {
async function checkCodeValid() {
try {
const codeValid = await auth.checkActionCode(oobCode);
console.log("codeValid :>> ", codeValid);
setCodeValid({ loading: false, ...codeValid });
} catch (error) {
console.log("error :>> ", error);
setCodeValid({ loading: false, ...error });
}
}
checkCodeValid();
}, [oobCode]);
if (codeValid.loading) return <LoadingSpinner />;
if (codeValid.code)
return (
<div>
<Result status="error" title={codeValid.message} />
</div>
);
if (passwordReset.success) if (passwordReset.success)
return ( return (
<Result <Result

View File

@@ -195,6 +195,7 @@ export function* onValidatePasswordResetStart() {
} }
export function* validatePasswordResetStart({ payload: { password, code } }) { export function* validatePasswordResetStart({ payload: { password, code } }) {
try { try {
auth.checkActionCode(code);
yield auth.confirmPasswordReset(code, password); yield auth.confirmPasswordReset(code, password);
yield put(validatePasswordResetSuccess()); yield put(validatePasswordResetSuccess());
} catch (error) { } catch (error) {

View File

@@ -29,5 +29,8 @@ const UserActionTypes = {
VALIDATE_PASSWORD_RESET_SUCCESS: "VALIDATE_PASSWORD_RESET_SUCCESS", VALIDATE_PASSWORD_RESET_SUCCESS: "VALIDATE_PASSWORD_RESET_SUCCESS",
VALIDATE_PASSWORD_RESET_FAILURE: "VALIDATE_PASSWORD_RESET_FAILURE", VALIDATE_PASSWORD_RESET_FAILURE: "VALIDATE_PASSWORD_RESET_FAILURE",
SET_AUTH_LEVEL: "SET_AUTH_LEVEL", SET_AUTH_LEVEL: "SET_AUTH_LEVEL",
CHECK_ACTION_CODE_START: "CHECK_ACTION_CODE_START",
CHECK_ACTION_CODE_SUCCESS: "CHECK_ACTION_CODE_SUCCESS",
CHECK_ACTION_CODE_FAILURE: "CHECK_ACTION_CODE_FAILURE",
}; };
export default UserActionTypes; export default UserActionTypes;