Add metrics
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { verify } from 'argon2';
|
||||
import { useValidatedBody, z } from 'h3-zod';
|
||||
import prisma from '~~/lib/prisma';
|
||||
import { logins } from '~~/server/metrics';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { email, password } = await useValidatedBody(
|
||||
@@ -25,10 +26,12 @@ export default defineEventHandler(async (event) => {
|
||||
});
|
||||
if (!user || user.password.length <= 0) {
|
||||
console.warn(`Failed login attempted: Unknown email: ${email}`);
|
||||
logins.inc({ success: 'false' });
|
||||
throw createError({ status: 404, statusText: 'Not found!' });
|
||||
}
|
||||
if (!(await verify(user.password, password))) {
|
||||
console.warn(`Failed login attempted: Wrong password: ${email}`);
|
||||
logins.inc({ success: 'false' });
|
||||
throw createError({ status: 404, statusText: 'Not found!' });
|
||||
}
|
||||
|
||||
@@ -41,6 +44,7 @@ export default defineEventHandler(async (event) => {
|
||||
},
|
||||
loggedInAt: new Date()
|
||||
});
|
||||
logins.inc({ success: 'true' });
|
||||
|
||||
return { success: true, user: { id: user.id } };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user