Skip to content

Commit 3041062

Browse files
authored
Massively Refactor Authentication internals (#3440)
2 parents b5d24d2 + 48a0263 commit 3041062

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+957
-888
lines changed

src/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Module } from '@nestjs/common';
22
import process from 'node:process';
33
import { AdminModule } from './components/admin/admin.module';
4-
import { AuthenticationModule } from './components/authentication/authentication.module';
54
import { AuthorizationModule } from './components/authorization/authorization.module';
65
import { BudgetModule } from './components/budget/budget.module';
76
import { CeremonyModule } from './components/ceremony/ceremony.module';
@@ -52,7 +51,6 @@ if (process.env.NODE_ENV !== 'production') {
5251
LoggerModule.forRoot(),
5352
CoreModule,
5453
AdminModule,
55-
AuthenticationModule,
5654
AuthorizationModule,
5755
BudgetModule,
5856
CeremonyModule,

src/common/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export * from './secured-mapper';
4949
export * from './sensitivity.enum';
5050
export * from './trace-layer';
5151
export * from './util';
52-
export { type Session } from './session';
5352
export * from './types';
5453
export * from './validators';
5554
export * from './name-field';

src/common/session.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/components/admin/admin.gel.repository.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Injectable } from '@nestjs/common';
2+
import { ModuleRef } from '@nestjs/core';
3+
import { LazyGetter as Once } from 'lazy-get-decorator';
24
import { type ID, Role } from '~/common';
5+
import { AuthenticationRepository } from '~/core/authentication/authentication.repository';
36
import { RootUserAlias } from '~/core/config/root-user.config';
47
import { DbTraceLayer, disableAccessPolicies, e, Gel } from '~/core/gel';
5-
import { AuthenticationRepository } from '../authentication/authentication.repository';
68
import { SystemAgentRepository } from '../user/system-agent.repository';
79

810
@Injectable()
@@ -11,12 +13,16 @@ export class AdminGelRepository {
1113
private readonly db: Gel;
1214
constructor(
1315
gel: Gel,
14-
readonly auth: AuthenticationRepository,
16+
private readonly moduleRef: ModuleRef,
1517
readonly agents: SystemAgentRepository,
1618
) {
1719
this.db = gel.withOptions(disableAccessPolicies);
1820
}
1921

22+
@Once() get auth() {
23+
return this.moduleRef.get(AuthenticationRepository, { strict: false });
24+
}
25+
2026
async finishing(callback: () => Promise<void>) {
2127
await this.db.waitForConnection({
2228
forever: true,

src/components/admin/admin.gel.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
Injectable,
44
type OnApplicationBootstrap,
55
} from '@nestjs/common';
6+
import { CryptoService } from '~/core/authentication/crypto.service';
67
import { ConfigService } from '~/core/config/config.service';
78
import { ILogger, Logger } from '~/core/logger';
8-
import { CryptoService } from '../authentication/crypto.service';
99
import { AdminGelRepository } from './admin.gel.repository';
1010
import { AdminRepository } from './admin.repository';
1111

src/components/admin/admin.service.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import { Injectable, type OnApplicationBootstrap } from '@nestjs/common';
2+
import { ModuleRef } from '@nestjs/core';
3+
import { LazyGetter as Once } from 'lazy-get-decorator';
24
import { DateTime } from 'luxon';
35
import { Role, ServerException } from '~/common';
6+
import { AuthenticationService } from '~/core/authentication/authentication.service';
7+
import { CryptoService } from '~/core/authentication/crypto.service';
48
import { ConfigService } from '~/core/config/config.service';
59
import { Transactional } from '~/core/database';
610
import { ILogger, Logger } from '~/core/logger';
7-
import { AuthenticationService } from '../authentication';
8-
import { CryptoService } from '../authentication/crypto.service';
911
import { AdminRepository } from './admin.repository';
1012

1113
@Injectable()
1214
export class AdminService implements OnApplicationBootstrap {
1315
constructor(
1416
private readonly config: ConfigService,
15-
private readonly authentication: AuthenticationService,
16-
private readonly crypto: CryptoService,
1717
private readonly repo: AdminRepository,
18+
private readonly moduleRef: ModuleRef,
1819
@Logger('admin:service') private readonly logger: ILogger,
1920
@Logger('admin:database') private readonly dbLogger: ILogger,
2021
) {}
2122

23+
@Once() private get authentication() {
24+
return this.moduleRef.get(AuthenticationService, { strict: false });
25+
}
26+
27+
@Once() private get crypto() {
28+
return this.moduleRef.get(CryptoService, { strict: false });
29+
}
30+
2231
async onApplicationBootstrap(): Promise<void> {
2332
if (!this.config.dbRootObjectsSync) {
2433
return;

src/components/authentication/authentication.module.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)