You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.1 KiB
67 lines
2.1 KiB
import { effects } from "redux-saga"; |
|
import { |
|
isSendingAuthRequest, |
|
setAuthRequestError, |
|
setAuthRequestSuccess, |
|
setEmailVerificationError, |
|
setEmailVerificationSuccess, |
|
clearAuthRequestError, |
|
clearEmailVerificationError, |
|
clearAuthRequestSuccess, |
|
clearEmailVerificationSuccess, |
|
setFormEmail, |
|
setFormPassword, |
|
setFormPasswordConfirmation, |
|
setFormEmailVerification |
|
} from "../actions/auth/reducer.actions"; |
|
import { registerUser, verifyEmail } from "../api/auth.api"; |
|
|
|
function* registerUserCall(postBody) { |
|
yield effects.put(isSendingAuthRequest(true)); |
|
const { email, password1, password2 } = postBody; |
|
try { |
|
return yield effects.call(registerUser, email, password1, password2); |
|
} catch (exception) { |
|
yield effects.put(setAuthRequestError(exception)); |
|
return false; |
|
} finally { |
|
yield effects.put(isSendingAuthRequest(false)); |
|
} |
|
} |
|
|
|
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)); |
|
yield effects.put(clearAuthRequestError()); |
|
yield effects.put(setFormEmail("")); |
|
yield effects.put(setFormPassword("")); |
|
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("")); |
|
} |
|
}
|
|
|