Fixes
This commit is contained in:
@@ -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" });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user