troubleshooting on user registration flow

This commit is contained in:
Mikayla Dobson
2022-12-01 18:49:51 -06:00
parent ba4b6e08c9
commit 671e250c60
9 changed files with 60 additions and 49 deletions

View File

@@ -18,33 +18,33 @@ export default class AuthService {
data.isadmin = false;
try {
let receivedUser: IUser | undefined;
// not allowed to use email address that already exists
const user = await UserInstance.getOneByEmail(email);
if (user) throw createError('409', 'Email already in use');
// hash password and create new user record
bcrypt.genSalt(10, (err, salt) => {
const salt = await bcrypt.genSalt();
bcrypt.hash(password!, salt, async (err, hash) => {
if (err) throw err;
bcrypt.hash(password!, salt, async (err, hash) => {
if (err) throw err;
const newData = {
...data,
password: hash
}
const result: IUser = await UserInstance.post(newData);
const newData = {
...data,
password: hash
}
// basic profile setup
await CollectionInstance.post({
name: `${data.firstname}'s Collection`,
active: true,
ismaincollection: true,
ownerid: result.id!.toString(),
datecreated: now,
datemodified: now
});
const res: IUser | null = await UserInstance.post(newData);
if (res) receivedUser = res;
return result;
})
// basic profile setup
res && await CollectionInstance.post({
name: `${data.firstname}'s Collection`,
active: true,
ismaincollection: true,
ownerid: res.id!.toString(),
datecreated: now,
datemodified: now
});
})
return true;