Finished functionally complete email confirmation workflow
This commit is contained in:
@@ -3,17 +3,19 @@ import {
|
||||
isSendingAuthRequest,
|
||||
setAuthRequestError,
|
||||
setAuthRequestSuccess,
|
||||
setEmailVerificationError,
|
||||
setEmailVerificationSuccess,
|
||||
clearAuthRequestError,
|
||||
clearEmailVerificationError,
|
||||
clearAuthRequestSuccess,
|
||||
clearEmailVerificationSuccess,
|
||||
setFormEmail,
|
||||
setFormPassword,
|
||||
setFormPasswordConfirmation
|
||||
setFormPasswordConfirmation,
|
||||
setFormEmailVerification
|
||||
} from "../actions/auth/reducer.actions";
|
||||
import { registerUser } from "../api/auth.api";
|
||||
import { registerUser, verifyEmail } from "../api/auth.api";
|
||||
|
||||
/**
|
||||
* Saga for registering a new user.
|
||||
* @param {*} postBody
|
||||
*/
|
||||
function* registerUserCall(postBody) {
|
||||
yield effects.put(isSendingAuthRequest(true));
|
||||
const { email, password1, password2 } = postBody;
|
||||
@@ -27,7 +29,22 @@ function* registerUserCall(postBody) {
|
||||
}
|
||||
}
|
||||
|
||||
function* verifyEmailCall(postBody) {
|
||||
yield effects.put(isSendingAuthRequest(true));
|
||||
const { emailKey } = postBody;
|
||||
try {
|
||||
return yield effects.call(verifyEmail, emailKey);
|
||||
} catch (exception) {
|
||||
yield effects.put(setEmailVerificationError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingAuthRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
export function* registerUserFlow(request) {
|
||||
yield effects.put(clearAuthRequestSuccess());
|
||||
yield effects.put(clearAuthRequestError());
|
||||
const wasSucessful = yield effects.call(registerUserCall, request.data);
|
||||
if (wasSucessful) {
|
||||
yield effects.put(setAuthRequestSuccess(wasSucessful));
|
||||
@@ -37,3 +54,14 @@ export function* registerUserFlow(request) {
|
||||
yield effects.put(setFormPasswordConfirmation(""));
|
||||
}
|
||||
}
|
||||
|
||||
export function* verifyEmailFlow(request) {
|
||||
yield effects.put(clearEmailVerificationSuccess());
|
||||
yield effects.put(clearEmailVerificationError());
|
||||
const wasSucessful = yield effects.call(verifyEmailCall, request.data);
|
||||
if (wasSucessful) {
|
||||
yield effects.put(setEmailVerificationSuccess(wasSucessful));
|
||||
yield effects.put(clearEmailVerificationError());
|
||||
yield effects.put(setFormEmailVerification(""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { takeLatest } from "redux-saga/effects";
|
||||
import { SEND_REGISTER_REQUEST } from "../constants/auth.constants";
|
||||
import { registerUserFlow } from "./auth.sagas";
|
||||
import { SEND_REGISTER_REQUEST, SEND_EMAIL_VERIFICATION_REQUEST } from "../constants/auth.constants";
|
||||
import { registerUserFlow, verifyEmailFlow } from "./auth.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
yield takeLatest(SEND_REGISTER_REQUEST, registerUserFlow);
|
||||
yield takeLatest(SEND_EMAIL_VERIFICATION_REQUEST, verifyEmailFlow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user