Skip to content

Commit

Permalink
refactor: separate auth module
Browse files Browse the repository at this point in the history
  • Loading branch information
mertmit committed May 21, 2024
1 parent e580c9c commit fe1da3c
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 33 deletions.
12 changes: 2 additions & 10 deletions packages/nocodb/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,7 +42,6 @@ export const ceModuleConfig = {
: []),
],
providers: [
AuthService,
{
provide: APP_FILTER,
useClass: GlobalExceptionFilter,
Expand All @@ -54,10 +50,6 @@ export const ceModuleConfig = {
provide: APP_GUARD,
useClass: ExtractIdsMiddleware,
},
LocalStrategy,
AuthTokenStrategy,
BaseViewStrategy,
BasicStrategy,
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,14 @@ export class AuthController {
): Promise<any> {
try {
res.send(
ejs.render((await import('./ui/auth/resetPassword')).default, {
ncPublicUrl: process.env.NC_PUBLIC_URL || '',
token: JSON.stringify(tokenId),
baseUrl: `/`,
}),
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 });
Expand Down
31 changes: 31 additions & 0 deletions packages/nocodb/src/modules/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
16 changes: 3 additions & 13 deletions packages/nocodb/src/modules/noco.module.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -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';
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -193,16 +188,12 @@ export const nocoModuleMetadata = {
OldDatasController,
PublicDatasController,
PublicDatasExportController,

/* Auth */
AuthController,
]
: []),
],
providers: [
/* Generic */
InitMetaServiceProvider,
AppHooksService,
JwtStrategyProvider,
GlobalGuard,
SocketGateway,
Expand Down Expand Up @@ -263,12 +254,10 @@ export const nocoModuleMetadata = {
OldDatasService,
PublicDatasService,
PublicDatasExportService,

/* Auth */
GoogleStrategyProvider,
],
exports: [
/* Generic */
AppHooksService,
TelemetryService,
HookHandlerService,
JwtStrategy,
Expand All @@ -277,6 +266,7 @@ export const nocoModuleMetadata = {
UsersService,

/* Metas */
MetaService,
TablesService,
ColumnsService,
FiltersService,
Expand Down
7 changes: 3 additions & 4 deletions packages/nocodb/src/services/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/nocodb/src/strategies/local.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

1 comment on commit fe1da3c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR changes have been deployed. Please run the following command to verify:

docker run -d -p 8888:8080 nocodb/nocodb-timely:0.207.1-pr-8542-20240521-2004

Please sign in to comment.