」 feat: added 2fa checker

This commit is contained in:
2025-10-23 17:56:28 +02:00
parent 9ea154492c
commit d0862a5098
2 changed files with 30 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import fastifyJWT from '@fastify/jwt';
import fastifyCookie from '@fastify/cookie';
import cors from '@fastify/cors';
import { totpCheck } from './totpCheck.js';
import { register } from './register.js';
import { login } from './login.js';
import { gRedir } from './gRedir.js';
@ -54,6 +55,9 @@ export default async function(fastify, options) {
fastify.get('/me', { preHandler: [fastify.authenticate] }, async (request, reply) => {
return { user: request.user };
});
fastify.get('/2fa', { preHandler: [fastify.authenticate] }, async (request, reply) => {
return totpCheck(request, reply);
});
// GOOGLE sign in
fastify.get('/login/google', async (request, reply) => {

24
src/api/auth/totpCheck.js Normal file
View File

@ -0,0 +1,24 @@
import authDB from '../../utils/authDB.js';
/**
* @param {import('fastify').FastifyRequest} request
* @param {import('fastify').FastifyReply} reply
*/
export async function totpCheck(request, reply) {
try {
const user = request.user;
if (authDB.checkUser(user) === false) {
return reply.code(400).send({ error: "User does not exist" });
}
return reply
.code(200)
.send({
totp: authDB.isTOTPEnabled(user)
});
} catch (err) {
fastify.log.error(err);
return reply.code(500).send({ error: "Internal server error" });
}
}