Files
band-management/resources/vuexy-admin-v10.11.1/nuxt-version/javascript-version/full-version/server/api/login.post.js

32 lines
775 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { db } from '@/server/fake-db/auth'
export default defineEventHandler(async event => {
const { email, password } = await readBody(event)
if (!email || !password) {
throw createError({
statusCode: 403,
statusMessage: 'Email and Password is required to login',
data: {
email: ['Email and Password is required to login'],
},
})
}
const dbUser = db.users.find(u => u.email === email && u.password === password)
if (!dbUser) {
throw createError({
statusCode: 403,
statusMessage: 'Invalid email or password',
data: {
email: ['Invalid email or password'],
},
})
}
// Don't send password in response
const { password: _, ...user } = dbUser
return {
user,
}
})