fix: replace client and username with email
fix: error handling in lamassu-register
This commit is contained in:
parent
5ff676553e
commit
4a630f0f53
4 changed files with 30 additions and 23 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
const { asyncLocalStorage, defaultStore } = require('../lib/async-storage')
|
||||
const userManagement = require('../lib/new-admin/graphql/modules/userManagement')
|
||||
const authErrors = require('../lib/new-admin/graphql/errors/authentication')
|
||||
const options = require('../lib/options')
|
||||
|
||||
const name = process.argv[2]
|
||||
|
|
@ -14,29 +15,25 @@ if (!domain) {
|
|||
}
|
||||
|
||||
if (!name || !role) {
|
||||
console.log('Usage: lamassu-register <username> <role>')
|
||||
console.log('Usage: lamassu-register <email> <role>')
|
||||
console.log('<role> must be \'user\' or \'superuser\'')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||
|
||||
if (!emailRegex.test(name)) {
|
||||
console.log('Usage: <name> should be in an email format')
|
||||
console.log('Usage: <email> must be in an email format')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
if (role !== 'user' && role !== 'superuser') {
|
||||
console.log('Usage: <role> has two possible values: user | superuser')
|
||||
console.log('Usage: <role> must be \'user\' or \'superuser\'')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
asyncLocalStorage.run(defaultStore(), () => {
|
||||
userManagement.createRegisterToken(name, role).then(token => {
|
||||
if (!token) {
|
||||
console.log(`A user named ${name} already exists!`)
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
if (domain === 'localhost') {
|
||||
console.log(`https://${domain}:3001/register?t=${token.token}`)
|
||||
} else {
|
||||
|
|
@ -45,6 +42,12 @@ asyncLocalStorage.run(defaultStore(), () => {
|
|||
|
||||
process.exit(0)
|
||||
}).catch(err => {
|
||||
|
||||
if (err instanceof authErrors.UserAlreadyExistsError){
|
||||
console.log(`A user with email ${name} already exists!`)
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
console.log('Error: %s', err)
|
||||
process.exit(3)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue