This commit is contained in:
2025-11-09 18:47:30 +01:00
parent 572d564135
commit 29cfaccd02

View File

@@ -1,7 +1,7 @@
import { FastifyInstance } from "fastify";
import fp from "fastify-plugin";
import jwt from "jsonwebtoken";
import { secrets } from "../utils/secrets.js";
import { secrets } from "../utils/secrets";
export default fp(async (server: FastifyInstance) => {
server.addHook("preHandler", async (req, reply) => {
@@ -15,6 +15,16 @@ export default fp(async (server: FastifyInstance) => {
const token =
headerToken && headerToken.length > 10 ? headerToken : cookieToken || null;
/*let token = null
if(headerToken !== null && headerToken.length > 10){
token = headerToken
} else if(cookieToken ){
token = cookieToken
}*/
if (!token) {
return reply.code(401).send({ error: "Authentication required" });
}
@@ -27,7 +37,10 @@ export default fp(async (server: FastifyInstance) => {
tenant_id: number;
};
console.log("payload", payload);
if (!payload?.user_id || !payload.tenant_id) {
console.log(payload)
return reply.code(401).send({ error: "Invalid token" });
}