This commit is contained in:
2025-10-05 15:00:21 +02:00
parent 4588c2b9e9
commit 1fd568c562
5 changed files with 2 additions and 35 deletions

View File

@@ -101,12 +101,8 @@ export default async function authRoutes(server: FastifyInstance) {
.select("*, tenants!auth_tenant_users(*)")
.eq("email", body.email)
console.log(data)
console.log(error)
// @ts-ignore
user = (data || []).find(i => i.tenants.find(x => x.id === req.tenant.id))
console.log(user)
if(error) {
// @ts-ignore
return reply.code(500).send({ error: "Internal Server Error" });
@@ -120,7 +116,6 @@ export default async function authRoutes(server: FastifyInstance) {
.single();
user = data
if(error) {
console.log(error);
// @ts-ignore
return reply.code(500).send({ error: "Internal Server Error" });
}
@@ -131,18 +126,15 @@ export default async function authRoutes(server: FastifyInstance) {
return reply.code(401).send({ error: "Invalid credentials" });
} else {
console.log(user);
console.log(body)
const valid = await bcrypt.compare(body.password, user.password_hash);
if (!valid) {
// @ts-ignore
return reply.code(401).send({ error: "Invalid credentials" });
} else {
const token = jwt.sign(
{ user_id: user.id, email: user.email, tenant_id: req.tenant ? req.tenant.id : null },
{ user_id: user.id, email: user.email, tenant_id: req.tenant?.id ? req.tenant.id : null },
secrets.JWT_SECRET!,
{ expiresIn: "3h" }
{ expiresIn: "6h" }
);
reply.setCookie("token", token, {