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 type { MiddlewareConsumer } from '@nestjs/common';
import { NocoModule } from '~/modules/noco.module';
import { AuthModule } from '~/modules/auth/auth.module';
import { GlobalExceptionFilter } from '~/filters/global-exception/global-exception.filter';
import { GlobalMiddleware } from '~/middlewares/global/global.middleware';
import { GuiMiddleware } from '~/middlewares/gui/gui.middleware';
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 appConfig from '~/app.config';
import { ExtractIdsMiddleware } from '~/middlewares/extract-ids/extract-ids.middleware';
import { BasicStrategy } from '~/strategies/basic.strategy/basic.strategy';
import { packageInfo } from '~/utils/packageVersion';
export const ceModuleConfig = {
imports: [
AuthModule,
NocoModule,
EventEmitterModule,
JobsModule,
@ -45,7 +42,6 @@ export const ceModuleConfig = {
: []),
],
providers: [
AuthService,
{
provide: APP_FILTER,
useClass: GlobalExceptionFilter,
@ -54,10 +50,6 @@ export const ceModuleConfig = {
provide: APP_GUARD,
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> {
try {
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 || '',
token: JSON.stringify(tokenId),
baseUrl: `/`,
}),
},
),
);
} catch (e) {
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 { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { MulterModule } from '@nestjs/platform-express';
/* Modules */
@ -24,6 +23,7 @@ import { UsersService } from '~/services/users/users.service';
/* Metas */
import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants';
import { MetaService } from '~/meta/meta.service';
import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller';
import { ApiTokensController } from '~/controllers/api-tokens.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 { 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 = {
imports: [
EventEmitterModule,
JobsModule,
PassportModule,
MulterModule.register({
storage: multer.diskStorage({}),
limits: {
@ -193,16 +188,12 @@ export const nocoModuleMetadata = {
OldDatasController,
PublicDatasController,
PublicDatasExportController,
/* Auth */
AuthController,
]
: []),
],
providers: [
/* Generic */
InitMetaServiceProvider,
AppHooksService,
JwtStrategyProvider,
GlobalGuard,
SocketGateway,
@ -263,12 +254,10 @@ export const nocoModuleMetadata = {
OldDatasService,
PublicDatasService,
PublicDatasExportService,
/* Auth */
GoogleStrategyProvider,
],
exports: [
/* Generic */
AppHooksService,
TelemetryService,
HookHandlerService,
JwtStrategy,
@ -277,6 +266,7 @@ export const nocoModuleMetadata = {
UsersService,
/* Metas */
MetaService,
TablesService,
ColumnsService,
FiltersService,

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

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

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

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

Loading…
Cancel
Save