routes/apiHandlers.js
/**
 * Check the validity and blockchain availability of a username
 * Accounts created with the faucet can book a username for one week
 */
Check the validity and blockchain availability of a username
Accounts created with the faucet can book a username for one week
Check the validity and blockchain availability of a username Accounts created with the faucet can book a username for one week
async function handleCheckUsername(req) {
    const { username } = req.body;
    await database.logAction({
        action: 'check_username',
        ip: req.ip,
        metadata: { username },
    });
    try {
        accountNameIsValid(username);
    } catch (e) {
        throw new ApiError({
            type: e.message,
            status: 200,
        });
    }
    const userExists = await services.checkUsername(username);
    if (userExists) {
        throw new ApiError({
            type: 'error_api_username_used',
            status: 200,
        });
    }
    const usernameIsBooked = await database.usernameIsBooked(username);
    if (usernameIsBooked) {
        throw new ApiError({
            type: 'error_api_username_reserved',
            status: 200,
        });
    }
    return { success: true };
}
async function handleCheckUsername ( req ) { const { username } = req . body ; await database . logAction ( { action : 'check_username' , ip : req . ip , metadata : { username } , } ) ; try { accountNameIsValid ( username ) ; } catch ( e ) { throw new ApiError ( { type : e . message , status : 200 , } ) ; } const userExists = await services . checkUsername ( username ) ; if ( userExists ) { throw new ApiError ( { type : 'error_api_username_used' , status : 200 , } ) ; } const usernameIsBooked = await database . usernameIsBooked ( username ) ; if ( usernameIsBooked ) { throw new ApiError ( { type : 'error_api_username_reserved' , status : 200 , } ) ; } return { success : true } ; }
Check the validity and blockchain availability of a username
 Accounts created with the faucet can book a username for one week
Check the validity and blockchain availability of a username Accounts created with the faucet can book a username for one week