routes/apiHandlers.js
/**
 * Verifies that the json webtoken passed was signed by us and
 * optionally that it has the correct type.
 */
Verifies that the json webtoken passed was signed by us and
optionally that it has the correct type.
Verifies that the json webtoken passed was signed by us and optionally that it has the correct type .
function verifyToken(token, type) {
    if (!token) {
        throw new ApiError({
            type: 'error_api_token_required',
            field: 'phoneNumber',
        });
    }
    let decoded;
    try {
        decoded = jwt.verify(token, process.env.JWT_SECRET);
    } catch (cause) {
        throw new ApiError({
            type: 'error_api_token_invalid',
            field: 'phoneNumber',
            cause,
        });
    }
    if (type && decoded.type !== type) {
        throw new ApiError({
            field: 'phoneNumber',
            type: 'error_api_token_invalid_type',
        });
    }
    return decoded;
}
function verifyToken ( token , type ) { if ( ! token ) { throw new ApiError ( { type : 'error_api_token_required' , field : 'phoneNumber' , } ) ; } let decoded ; try { decoded = jwt . verify ( token , process . env . JWT_SECRET ) ; } catch ( cause ) { throw new ApiError ( { type : 'error_api_token_invalid' , field : 'phoneNumber' , cause , } ) ; } if ( type && decoded . type !== type ) { throw new ApiError ( { field : 'phoneNumber' , type : 'error_api_token_invalid_type' , } ) ; } return decoded ; }
Verifies that the json webtoken passed was signed by us and
 optionally that it has the correct type.
Verifies that the json webtoken passed was signed by us and optionally that it has the correct type .