This commit is contained in:
Ulises Gascón
2024-02-07 12:29:54 +01:00
committed by Ulises Gascon
parent 91ba1f5054
commit 9dd233c371
143 changed files with 68070 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
import {
User
} from '../database.js'
const create = async (username, password, email) => {
const user = new User({ username, password, email })
await user.save()
return user
}
const getUserByCredentials = async (username, password) => {
const user = await User.findOne({ username })
if (!user) {
throw new Error('User not found')
}
const isMatch = await user.comparePassword(password)
if (!isMatch) {
throw new Error('Password is incorrect')
}
return user
}
export { create, getUserByCredentials }