routes/apiHandlers.js
/**
 * Called both after email and phone verification,
 * if both steps are completed classifies the signup and sets the user state.
 */
Called both after email and phone verification,
if both steps are completed classifies the signup and sets the user state.
Called both after email and phone verification if both steps are completed classifies the signup and sets the user state .
async function finalizeSignup(user, req) {
    if (!user.phone_number_is_verified || !user.email_is_verified) {
        return false;
    }
    try {
        const signupInGatekeeper = await services.gatekeeperSignupCreate(user);
        user.set('gatekeeper_id', signupInGatekeeper.id);
    } catch (error) {
        logger.warn({ error }, 'gatekeeper.signup_create failed');
    }
    let result;
    try {
        result = await services.gatekeeperCheck(user);
        if (
            !['manual_review', 'approved', 'rejected'].includes(result.status)
        ) {
            throw new Error('Got invalid response from gatekeeper');
        }
    } catch (error) {
        req.log.warn(error, 'Classification failed, setting to manual_review');
        result = { status: 'manual_review', note: `ERROR: ${error.message}` };
    }
    if (result.status === 'approved') {
        await services.sendApprovalEmail(
            user.email,
            `${req.protocol}://${req.get('host')}`
        );
    }
    user.status = result.status;
    user.review_note = result.note;
    await user.save();
    return true;
}
async function finalizeSignup ( user , req ) { if ( ! user . phone_number_is_verified || ! user . email_is_verified ) { return false ; } try { const signupInGatekeeper = await services . gatekeeperSignupCreate ( user ) ; user . set ( 'gatekeeper_id' , signupInGatekeeper . id ) ; } catch ( error ) { logger . warn ( { error } , 'gatekeeper.signup_create failed' ) ; } let result ; try { result = await services . gatekeeperCheck ( user ) ; if ( ! [ 'manual_review' , 'approved' , 'rejected' ] . includes ( result . status ) ) { throw new Error ( 'Got invalid response from gatekeeper' ) ; } } catch ( error ) { req . log . warn ( error , 'Classification failed, setting to manual_review' ) ; result = { status : 'manual_review' , note : ` ${ error . message } ` } ; } if ( result . status === 'approved' ) { await services . sendApprovalEmail ( user . email , ` ${ req . protocol } ${ req . get ( 'host' ) } ` ) ; } user . status = result . status ; user . review_note = result . note ; await user . save ( ) ; return true ; }
Called both after email and phone verification,
 if both steps are completed classifies the signup and sets the user state.
Called both after email and phone verification if both steps are completed classifies the signup and sets the user state .
// only act if both email and phone is verified // First, create the completed signup request in Gatekeeper. // Allow Gatekeeper to relate it to other data based on the // "faucet session id", in the form of `${email}+faucetsession` (used in frontend) // Finally, ask Gatekeeper for its judgement.