Browse Source

refactor: separate auth module

pull/8542/head
mertmit 7 months ago
parent
commit
fe1da3c5a3
  1. 12
      packages/nocodb/src/app.module.ts
  2. 7
      packages/nocodb/src/modules/auth/auth.controller.ts
  3. 31
      packages/nocodb/src/modules/auth/auth.module.ts
  4. 0
      packages/nocodb/src/modules/auth/auth.service.spec.ts
  5. 0
      packages/nocodb/src/modules/auth/auth.service.ts
  6. 0
      packages/nocodb/src/modules/auth/ui/auth/emailVerify.ts
  7. 0
      packages/nocodb/src/modules/auth/ui/auth/resetPassword.ts
  8. 0
      packages/nocodb/src/modules/auth/ui/emailTemplates/forgotPassword.ts
  9. 0
      packages/nocodb/src/modules/auth/ui/emailTemplates/invite.ts
  10. 0
      packages/nocodb/src/modules/auth/ui/emailTemplates/verify.ts
  11. 16
      packages/nocodb/src/modules/noco.module.ts
  12. 7
      packages/nocodb/src/services/users/users.service.ts
  13. 2
      packages/nocodb/src/strategies/local.strategy.ts

12
packages/nocodb/src/app.module.ts

@ -6,24 +6,21 @@ import { EventEmitterModule as NestJsEventEmitter } from '@nestjs/event-emitter'
import { SentryModule } from '@ntegral/nestjs-sentry'; import { SentryModule } from '@ntegral/nestjs-sentry';
import type { MiddlewareConsumer } from '@nestjs/common'; import type { MiddlewareConsumer } from '@nestjs/common';
import { NocoModule } from '~/modules/noco.module'; import { NocoModule } from '~/modules/noco.module';
import { AuthModule } from '~/modules/auth/auth.module';
import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter'; import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter';
import { GlobalMiddleware } from '~/middlewares/global/global.middleware'; import { GlobalMiddleware } from '~/middlewares/global/global.middleware';
import { GuiMiddleware } from '~/middlewares/gui/gui.middleware'; import { GuiMiddleware } from '~/middlewares/gui/gui.middleware';
import { EventEmitterModule } from '~/modules/event-emitter/event-emitter.module'; import { EventEmitterModule } from '~/modules/event-emitter/event-emitter.module';
import { AuthService } from '~/services/auth.service';
import { LocalStrategy } from '~/strategies/local.strategy';
import { AuthTokenStrategy } from '~/strategies/authtoken.strategy/authtoken.strategy';
import { BaseViewStrategy } from '~/strategies/base-view.strategy/base-view.strategy';
import { JobsModule } from '~/modules/jobs/jobs.module'; import { JobsModule } from '~/modules/jobs/jobs.module';
import appConfig from '~/app.config'; import appConfig from '~/app.config';
import { ExtractIdsMiddleware } from '~/middlewares/extract-ids/extract-ids.middleware'; import { ExtractIdsMiddleware } from '~/middlewares/extract-ids/extract-ids.middleware';
import { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy';
import { packageInfo } from '~/utils/packageVersion'; import { packageInfo } from '~/utils/packageVersion';
export const ceModuleConfig = { export const ceModuleConfig = {
imports: [ imports: [
AuthModule,
NocoModule, NocoModule,
EventEmitterModule, EventEmitterModule,
JobsModule, JobsModule,
@ -45,7 +42,6 @@ export const ceModuleConfig = {
: []), : []),
], ],
providers: [ providers: [
AuthService,
{ {
provide: APP_FILTER, provide: APP_FILTER,
useClass: GlobalExceptionFilter, useClass: GlobalExceptionFilter,
@ -54,10 +50,6 @@ export const ceModuleConfig = {
provide: APP_GUARD, provide: APP_GUARD,
useClass: ExtractIdsMiddleware, useClass: ExtractIdsMiddleware,
}, },
LocalStrategy,
AuthTokenStrategy,
BaseViewStrategy,
BasicStrategy,
], ],
}; };

7
packages/nocodb/src/controllers/auth/auth.controller.ts → packages/nocodb/src/modules/auth/auth.controller.ts

@ -232,11 +232,14 @@ export class AuthController {
): Promise<any> { ): Promise<any> {
try { try {
res.send( res.send(
ejs.render((await import('./ui/auth/resetPassword')).default, { ejs.render(
(await import('~/modules/auth/ui/auth/resetPassword')).default,
{
ncPublicUrl: process.env.NC_PUBLIC_URL || '', ncPublicUrl: process.env.NC_PUBLIC_URL || '',
token: JSON.stringify(tokenId), token: JSON.stringify(tokenId),
baseUrl: `/`, baseUrl: `/`,
}), },
),
); );
} catch (e) { } catch (e) {
return res.status(400).json({ msg: e.message }); return res.status(400).json({ msg: e.message });

31
packages/nocodb/src/modules/auth/auth.module.ts

@ -0,0 +1,31 @@
import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { NocoModule } from '~/modules/noco.module';
import { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy';
import { LocalStrategy } from '~/strategies/local.strategy';
import { AuthTokenStrategy } from '~/strategies/authtoken.strategy/authtoken.strategy';
import { BaseViewStrategy } from '~/strategies/base-view.strategy/base-view.strategy';
import { GoogleStrategyProvider } from '~/strategies/google.strategy/google.strategy';
import { AuthService } from '~/modules/auth/auth.service';
import { AuthController } from '~/modules/auth/auth.controller';
export const authModuleMetadata = {
imports: [PassportModule, NocoModule],
controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true' ? [AuthController] : []),
],
providers: [
AuthService,
LocalStrategy,
AuthTokenStrategy,
BaseViewStrategy,
BasicStrategy,
GoogleStrategyProvider,
],
exports: [],
};
@Module(authModuleMetadata)
export class AuthModule {}

0
packages/nocodb/src/services/auth.service.spec.ts → packages/nocodb/src/modules/auth/auth.service.spec.ts

0
packages/nocodb/src/services/auth.service.ts → packages/nocodb/src/modules/auth/auth.service.ts

0
packages/nocodb/src/controllers/auth/ui/auth/emailVerify.ts → packages/nocodb/src/modules/auth/ui/auth/emailVerify.ts

0
packages/nocodb/src/controllers/auth/ui/auth/resetPassword.ts → packages/nocodb/src/modules/auth/ui/auth/resetPassword.ts

0
packages/nocodb/src/controllers/auth/ui/emailTemplates/forgotPassword.ts → packages/nocodb/src/modules/auth/ui/emailTemplates/forgotPassword.ts

0
packages/nocodb/src/controllers/auth/ui/emailTemplates/invite.ts → packages/nocodb/src/modules/auth/ui/emailTemplates/invite.ts

0
packages/nocodb/src/controllers/auth/ui/emailTemplates/verify.ts → packages/nocodb/src/modules/auth/ui/emailTemplates/verify.ts

16
packages/nocodb/src/modules/noco.module.ts

@ -1,6 +1,5 @@
import multer from 'multer'; import multer from 'multer';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { MulterModule } from '@nestjs/platform-express'; import { MulterModule } from '@nestjs/platform-express';
/* Modules */ /* Modules */
@ -24,6 +23,7 @@ import { UsersService } from '~/services/users/users.service';
/* Metas */ /* Metas */
import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants'; import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants';
import { MetaService } from '~/meta/meta.service';
import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller'; import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller';
import { ApiTokensController } from '~/controllers/api-tokens.controller'; import { ApiTokensController } from '~/controllers/api-tokens.controller';
import { AttachmentsController } from '~/controllers/attachments.controller'; import { AttachmentsController } from '~/controllers/attachments.controller';
@ -120,15 +120,10 @@ import { PublicDatasService } from '~/services/public-datas.service';
import { CalendarDatasController } from '~/controllers/calendars-datas.controller'; import { CalendarDatasController } from '~/controllers/calendars-datas.controller';
import { CalendarDatasService } from '~/services/calendar-datas.service'; import { CalendarDatasService } from '~/services/calendar-datas.service';
/* Auth */
import { GoogleStrategyProvider } from '~/strategies/google.strategy/google.strategy';
import { AuthController } from '~/controllers/auth/auth.controller';
export const nocoModuleMetadata = { export const nocoModuleMetadata = {
imports: [ imports: [
EventEmitterModule, EventEmitterModule,
JobsModule, JobsModule,
PassportModule,
MulterModule.register({ MulterModule.register({
storage: multer.diskStorage({}), storage: multer.diskStorage({}),
limits: { limits: {
@ -193,16 +188,12 @@ export const nocoModuleMetadata = {
OldDatasController, OldDatasController,
PublicDatasController, PublicDatasController,
PublicDatasExportController, PublicDatasExportController,
/* Auth */
AuthController,
] ]
: []), : []),
], ],
providers: [ providers: [
/* Generic */ /* Generic */
InitMetaServiceProvider, InitMetaServiceProvider,
AppHooksService,
JwtStrategyProvider, JwtStrategyProvider,
GlobalGuard, GlobalGuard,
SocketGateway, SocketGateway,
@ -263,12 +254,10 @@ export const nocoModuleMetadata = {
OldDatasService, OldDatasService,
PublicDatasService, PublicDatasService,
PublicDatasExportService, PublicDatasExportService,
/* Auth */
GoogleStrategyProvider,
], ],
exports: [ exports: [
/* Generic */ /* Generic */
AppHooksService,
TelemetryService, TelemetryService,
HookHandlerService, HookHandlerService,
JwtStrategy, JwtStrategy,
@ -277,6 +266,7 @@ export const nocoModuleMetadata = {
UsersService, UsersService,
/* Metas */ /* Metas */
MetaService,
TablesService, TablesService,
ColumnsService, ColumnsService,
FiltersService, FiltersService,

7
packages/nocodb/src/services/users/users.service.ts

@ -229,7 +229,7 @@ export class UsersService {
}); });
try { try {
const template = ( const template = (
await import('~/controllers/auth/ui/emailTemplates/forgotPassword') await import('~/modules/auth/ui/emailTemplates/forgotPassword')
).default; ).default;
await NcPluginMgrv2.emailAdapter().then((adapter) => await NcPluginMgrv2.emailAdapter().then((adapter) =>
adapter.mailSend({ adapter.mailSend({
@ -475,9 +475,8 @@ export class UsersService {
user = await User.getByEmail(email); user = await User.getByEmail(email);
try { try {
const template = ( const template = (await import('~/modules/auth/ui/emailTemplates/verify'))
await import('~/controllers/auth/ui/emailTemplates/verify') .default;
).default;
await ( await (
await NcPluginMgrv2.emailAdapter() await NcPluginMgrv2.emailAdapter()
).mailSend({ ).mailSend({

2
packages/nocodb/src/strategies/local.strategy.ts

@ -4,7 +4,7 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { extractRolesObj } from 'nocodb-sdk'; import { extractRolesObj } from 'nocodb-sdk';
import type { AppConfig } from '~/interface/config'; import type { AppConfig } from '~/interface/config';
import { AuthService } from '~/services/auth.service'; import { AuthService } from '~/modules/auth/auth.service';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
@Injectable() @Injectable()

Loading…
Cancel
Save