JSFiddle - React, Tailwind, and code Playground
by timhuang
JavaScript
function createAccount(
username = '',
password = '',
nickname = '',
email = '',
gender = 'Male',
bio = '',
subscription = 'Basic',
callback,
) {
if (!username || !password || !email) {
throw new Error(
'You are missing one or all of the following fields: "username", "password", "email"',
)
}
return api
.createAccount({
username,
password,
nickname,
email,
gender,
bio,
subscription,
})
.then((result) => {
if (callback) callback(null, result)
})
.catch((error) => {
console.error(error)
if (callback) callback(error)
})
}
createAccount(
'lucas',
'applebee123x123',
'',
'[email protected]',
'',
'My bio',
'Basic',
function cb(err, data) {
if (err) {
console.error(err)
}else{
}
// do something with data
},
)