main
Backend Deploy 🚀 / build-and-deploy (push) Has been cancelled

This commit is contained in:
Harun CAN
2026-05-01 00:45:33 +02:00
parent 1775ac1aa1
commit 5184db32cc
33 changed files with 1852 additions and 713 deletions
+26 -14
View File
@@ -146,10 +146,12 @@ export class AuthService {
if (user.email === 'admin@contentgen.ai') {
const hasAdminRole = user.roles.some((ur) => ur.role.name === 'admin');
if (!hasAdminRole) {
const adminRole = await this.prisma.role.findUnique({ where: { name: 'admin' } });
const adminRole = await this.prisma.role.findUnique({
where: { name: 'admin' },
});
if (adminRole) {
await this.prisma.userRole.create({
data: { userId: user.id, roleId: adminRole.id }
data: { userId: user.id, roleId: adminRole.id },
});
// Refresh user object
const refreshedUser = await this.prisma.user.findUnique({
@@ -157,17 +159,25 @@ export class AuthService {
include: {
roles: {
include: {
role: { include: { permissions: { include: { permission: true } } } }
}
}
}
role: {
include: { permissions: { include: { permission: true } } },
},
},
},
},
});
if (refreshedUser) {
// Grant 999999 credits if not granted
const existingGrant = await this.prisma.creditTransaction.findFirst({
where: { userId: refreshedUser.id, type: 'grant', description: 'Admin başlangıç kredisi — sınırsız' },
});
const existingGrant = await this.prisma.creditTransaction.findFirst(
{
where: {
userId: refreshedUser.id,
type: 'grant',
description: 'Admin başlangıç kredisi — sınırsız',
},
},
);
if (!existingGrant) {
await this.prisma.creditTransaction.create({
data: {
@@ -179,7 +189,9 @@ export class AuthService {
},
});
}
return this.generateTokens(refreshedUser as unknown as UserWithRoles);
return this.generateTokens(
refreshedUser as unknown as UserWithRoles,
);
}
}
}
@@ -297,13 +309,13 @@ export class AuthService {
};
const isAdmin = roles.includes('admin');
const accessExpiration = isAdmin
? '7d'
const accessExpiration = isAdmin
? '7d'
: this.configService.get('JWT_ACCESS_EXPIRATION', '15m');
// Generate access token
const accessToken = this.jwtService.sign(payload, {
expiresIn: accessExpiration as any,
expiresIn: accessExpiration,
});
// Generate refresh token