feat: implement admin authentication services and tenant impersonation logic

This commit is contained in:
john kevin asprec
2026-06-16 22:33:02 +08:00
parent 5cdbd36999
commit c09d3723c3
2 changed files with 4 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import {
import { JwtService } from '@nestjs/jwt'; import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import * as bcrypt from 'bcrypt'; import * as bcrypt from 'bcrypt';
import { randomUUID } from 'crypto';
import { AdminPrismaService } from '../prisma/admin-prisma.service'; import { AdminPrismaService } from '../prisma/admin-prisma.service';
@Injectable() @Injectable()
@@ -119,6 +120,7 @@ export class AuthService {
sub: adminId, sub: adminId,
email, email,
type: 'super_admin', type: 'super_admin',
jti: randomUUID(),
}); });
const refreshSecret = this.config.get<string>( const refreshSecret = this.config.get<string>(
@@ -131,7 +133,7 @@ export class AuthService {
); );
const refreshToken = this.jwt.sign( const refreshToken = this.jwt.sign(
{ sub: adminId, email, type: 'super_admin' }, { sub: adminId, email, type: 'super_admin', jti: randomUUID() },
{ {
secret: refreshSecret, secret: refreshSecret,
expiresIn: refreshExpiresIn as any, expiresIn: refreshExpiresIn as any,

View File

@@ -15,7 +15,7 @@ export class ImpersonateService {
private readonly audit: AuditService, private readonly audit: AuditService,
) { ) {
// Use the MAIN API's JWT secret so the token works with the tenant API // Use the MAIN API's JWT secret so the token works with the tenant API
this.mainJwtSecret = this.config.get<string>('JWT_SECRET', 'dev-jwt-secret-not-for-production'); this.mainJwtSecret = this.config.get<string>('MAIN_API_JWT_SECRET', 'your-secret-key');
} }
async startImpersonation(tenantId: string, adminId: string, adminName: string) { async startImpersonation(tenantId: string, adminId: string, adminName: string) {