1 Commits
dev ... main

Author SHA1 Message Date
kevin-asprec
155f7af5ac feat: seed superadmin user on fresh deploy 2026-04-15 16:13:23 +08:00
5 changed files with 17 additions and 29 deletions

View File

@@ -39,4 +39,4 @@ COPY --from=builder /app/dist ./dist
ENV NODE_ENV=production ENV NODE_ENV=production
EXPOSE 3004 EXPOSE 3004
ENTRYPOINT ["dumb-init", "--"] ENTRYPOINT ["dumb-init", "--"]
CMD ["sh", "-c", "cd packages/admin-db && npx prisma migrate deploy && if [ \"$RUN_SEED\" = \"true\" ]; then echo 'Seeding admin database...' && npx tsx prisma/seed.ts; fi && cd /app && node dist/main.js"] CMD ["sh", "-c", "cd packages/admin-db && npx prisma migrate deploy && cd /app && node dist/main.js"]

View File

@@ -1,24 +0,0 @@
-- CreateTable: support_ticket_attachments
CREATE TABLE "support_ticket_attachments" (
"id" TEXT NOT NULL,
"ticketId" TEXT NOT NULL,
"commentId" TEXT,
"fileName" TEXT NOT NULL,
"originalName" TEXT NOT NULL,
"mimeType" TEXT NOT NULL,
"sizeBytes" INTEGER NOT NULL,
"uploadedBy" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "support_ticket_attachments_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "support_ticket_attachments_ticketId_idx" ON "support_ticket_attachments"("ticketId");
CREATE INDEX "support_ticket_attachments_commentId_idx" ON "support_ticket_attachments"("commentId");
-- AddForeignKey
ALTER TABLE "support_ticket_attachments" ADD CONSTRAINT "support_ticket_attachments_ticketId_fkey"
FOREIGN KEY ("ticketId") REFERENCES "support_tickets"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "support_ticket_attachments" ADD CONSTRAINT "support_ticket_attachments_commentId_fkey"
FOREIGN KEY ("commentId") REFERENCES "support_ticket_comments"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,14 @@
-- Seed the platform superadmin user
-- Password: SuperAdmin@123 (bcrypt hash)
INSERT INTO "super_admins" ("id", "email", "password", "firstName", "lastName", "isActive", "createdAt", "updatedAt")
VALUES (
gen_random_uuid(),
'superadmin@fiberops.dev',
'$2b$12$wiW.foGm.5MD6FNz/HmBvuPaXJS56YPxxq5OEVCO6UXLOxTMvxL8S',
'Super',
'Admin',
true,
NOW(),
NOW()
)
ON CONFLICT ("email") DO NOTHING;

View File

@@ -6,7 +6,6 @@ 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()
@@ -120,7 +119,6 @@ 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>(
@@ -133,7 +131,7 @@ export class AuthService {
); );
const refreshToken = this.jwt.sign( const refreshToken = this.jwt.sign(
{ sub: adminId, email, type: 'super_admin', jti: randomUUID() }, { sub: adminId, email, type: 'super_admin' },
{ {
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>('MAIN_API_JWT_SECRET', 'your-secret-key'); this.mainJwtSecret = this.config.get<string>('JWT_SECRET', 'dev-jwt-secret-not-for-production');
} }
async startImpersonation(tenantId: string, adminId: string, adminName: string) { async startImpersonation(tenantId: string, adminId: string, adminName: string) {