fix npm run build
This commit is contained in:
@@ -7,7 +7,7 @@ import { PrismaService } from '../../shared/prisma.service';
|
||||
import { RedisPkceStore } from './pkce/redis-pkce.store';
|
||||
import { InMemoryRefreshStore } from './refresh/inmemory-refresh.store';
|
||||
|
||||
import { Issuer, generators, TokenSet } from 'openid-client';
|
||||
const openidClient: any = require('openid-client');
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -28,7 +28,7 @@ export class AuthService {
|
||||
if (this.issuer) return this.issuer;
|
||||
const issuerUrl = this.config.get<string>('AUTHENTIK_ISSUER');
|
||||
if (!issuerUrl) throw new Error('AUTHENTIK_ISSUER not configured');
|
||||
this.issuer = await Issuer.discover(issuerUrl);
|
||||
this.issuer = await openidClient.Issuer.discover(issuerUrl);
|
||||
return this.issuer;
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ export class AuthService {
|
||||
const redirectUri = this.config.get<string>('AUTH_CALLBACK_URL') || `${this.config.get('APP_URL') || ''}/auth/callback`;
|
||||
|
||||
const state = require('crypto').randomUUID();
|
||||
const code_verifier = generators.codeVerifier();
|
||||
const code_challenge = await generators.codeChallenge(code_verifier);
|
||||
const nonce = generators.nonce();
|
||||
const code_verifier = openidClient.generators.codeVerifier();
|
||||
const code_challenge = await openidClient.generators.codeChallenge(code_verifier);
|
||||
const nonce = openidClient.generators.nonce();
|
||||
|
||||
await this.pkceStore.save(state, { code_verifier, nonce, returnTo }, 300);
|
||||
|
||||
@@ -77,7 +77,7 @@ export class AuthService {
|
||||
const redirectUri = this.config.get<string>('AUTH_CALLBACK_URL') || `${this.config.get('APP_URL') || ''}/auth/callback`;
|
||||
|
||||
// exchange code
|
||||
const tokenSet: TokenSet = await client.callback(redirectUri, { code, state }, { code_verifier: pkce.code_verifier, nonce: pkce.nonce });
|
||||
const tokenSet: any = await client.callback(redirectUri, { code, state }, { code_verifier: pkce.code_verifier, nonce: pkce.nonce });
|
||||
|
||||
// verify id_token and get claims
|
||||
const claims = tokenSet.claims();
|
||||
@@ -144,7 +144,7 @@ export class AuthService {
|
||||
|
||||
const userId = data.userId;
|
||||
// load user
|
||||
const domainUser = await this.userRepository.findById(userId);
|
||||
const domainUser = await this.userRepository.getById(userId);
|
||||
if (!domainUser) throw new UnauthorizedException('User not found');
|
||||
if (!domainUser.isActive) throw new UnauthorizedException('User is not active');
|
||||
|
||||
@@ -183,7 +183,7 @@ export class AuthService {
|
||||
if (!token) throw new UnauthorizedException('Missing token');
|
||||
try {
|
||||
const payload: any = this.jwtService.verify(token);
|
||||
const user = await this.userRepository.findById(payload.sub);
|
||||
const user = await this.userRepository.getById(payload.sub);
|
||||
if (!user) throw new UnauthorizedException('User not found');
|
||||
return { id: user.id, username: user.username, email: user.email, roles: user.roles || [] };
|
||||
} catch (e) {
|
||||
|
||||
@@ -3,15 +3,16 @@ import { PermissionData } from '../../domain/entities/permission.entity';
|
||||
|
||||
export class PrismaRoleMapper {
|
||||
static toDomain(model: any): RoleData {
|
||||
const permissions: PermissionData[] = (model.permissions || []).map((p: any) =>
|
||||
PermissionData.restore({
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
description: p.description,
|
||||
createdAt: p.createdAt,
|
||||
updatedAt: p.updatedAt,
|
||||
}),
|
||||
);
|
||||
const permissions: PermissionData[] = (model.permissions || []).map((p: any) => {
|
||||
const perm = p.permission || p; // p may be RolePermission with nested permission or permission itself
|
||||
return PermissionData.restore({
|
||||
id: perm.id,
|
||||
name: perm.name,
|
||||
description: perm.description,
|
||||
createdAt: perm.createdAt,
|
||||
updatedAt: perm.updatedAt,
|
||||
});
|
||||
});
|
||||
|
||||
return RoleData.restore({
|
||||
id: model.id,
|
||||
|
||||
@@ -11,7 +11,7 @@ export class PrismaRoleRepository implements IRole {
|
||||
async getDefaultRole() {
|
||||
const role = await this.prisma.role.findFirst({
|
||||
where: { isDefault: true },
|
||||
include: { permissions: true },
|
||||
include: { permissions: { include: { permission: true } } },
|
||||
});
|
||||
|
||||
if (!role) return null;
|
||||
@@ -22,7 +22,7 @@ export class PrismaRoleRepository implements IRole {
|
||||
async findById(roleId: string) {
|
||||
const role = await this.prisma.role.findUnique({
|
||||
where: { id: roleId },
|
||||
include: { permissions: true },
|
||||
include: { permissions: { include: { permission: true } } },
|
||||
});
|
||||
|
||||
if (!role) throw new Error('Role not found.');
|
||||
@@ -45,7 +45,7 @@ export class PrismaRoleRepository implements IRole {
|
||||
|
||||
const [total, items] = await Promise.all([
|
||||
this.prisma.role.count({ where }),
|
||||
this.prisma.role.findMany({ where, skip: (page - 1) * limit, take: limit, orderBy: { createdAt: 'desc' }, include: { permissions: true } }),
|
||||
this.prisma.role.findMany({ where, skip: (page - 1) * limit, take: limit, orderBy: { createdAt: 'desc' }, include: { permissions: { include: { permission: true } } } }),
|
||||
]);
|
||||
|
||||
return { data: items.map(i => PrismaRoleMapper.toDomain(i)!), total };
|
||||
@@ -66,7 +66,7 @@ export class PrismaRoleRepository implements IRole {
|
||||
};
|
||||
}
|
||||
|
||||
const created = await this.prisma.role.create({ data: base, include: { permissions: true } });
|
||||
const created = await this.prisma.role.create({ data: base, include: { permissions: { include: { permission: true } } } });
|
||||
return PrismaRoleMapper.toDomain(created)!;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ export class PrismaRoleRepository implements IRole {
|
||||
await prisma.role.update({ where: { id: role.id }, data: base });
|
||||
});
|
||||
|
||||
const updated = await this.prisma.role.findUnique({ where: { id: role.id }, include: { permissions: true } });
|
||||
const updated = await this.prisma.role.findUnique({ where: { id: role.id }, include: { permissions: { include: { permission: true } } } });
|
||||
return PrismaRoleMapper.toDomain(updated)!;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user