mirror of
https://github.com/Floriansylvain/SnippetsManager.git
synced 2026-08-19 11:43:15 +02:00
Cleaned and added await on user creation
This commit is contained in:
@@ -48,8 +48,7 @@ async function getUserByEmail(email: string): Promise<User | null> {
|
|||||||
|
|
||||||
function parseLoginData(data: any): LoginData | undefined {
|
function parseLoginData(data: any): LoginData | undefined {
|
||||||
try {
|
try {
|
||||||
const loginData: LoginData = LoginValidator.parse(data)
|
return LoginValidator.parse(data)
|
||||||
return loginData
|
|
||||||
} catch {
|
} catch {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
@@ -63,7 +62,7 @@ export const userRouterPostLogin: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = await getUserByEmail(loginData.email)
|
const user = await getUserByEmail(loginData.email)
|
||||||
if (await isUserValid(user, loginData) === false) {
|
if (!await isUserValid(user, loginData)) {
|
||||||
res.status(400).json({ message: 'Incorrect credentials.' })
|
res.status(400).json({ message: 'Incorrect credentials.' })
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,7 @@ export const userRouterPostRegister: RequestHandler = async (req, res) => {
|
|||||||
|
|
||||||
const hashedPassword = await bcrypt.hash(loginData.password, 10)
|
const hashedPassword = await bcrypt.hash(loginData.password, 10)
|
||||||
|
|
||||||
createUser(loginData.email, hashedPassword)
|
await createUser(loginData.email, hashedPassword)
|
||||||
|
|
||||||
res.json({ message: 'User successfully created!' })
|
res.json({ message: 'User successfully created!' })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user