Browse Source

fix: signin api response code correction

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
2154e7e202
  1. 4
      packages/nocodb-nest/src/app.module.ts
  2. 6
      packages/nocodb-nest/src/modules/auth/auth.service.ts
  3. 1
      packages/nocodb-nest/src/modules/users/users.controller.ts
  4. 50
      packages/nocodb-nest/src/modules/utils/utils.controller.ts
  5. 45
      packages/nocodb-nest/src/modules/utils/utils.service.ts

4
packages/nocodb-nest/src/app.module.ts

@ -6,6 +6,7 @@ import { GlobalExceptionFilter } from './filters/global-exception/global-excepti
import { GlobalMiddleware } from './middlewares/global/global.middleware';
import { AuthModule } from './modules/auth/auth.module';
import { ExtractProjectIdMiddleware } from './middlewares/extract-project-id/extract-project-id.middleware';
import { AuthService } from './modules/auth/auth.service'
import { UsersModule } from './modules/users/users.module';
import { MetaService } from './meta/meta.service';
import { UsersService } from './modules/users/users.service';
@ -50,6 +51,7 @@ import { CachesModule } from './modules/caches/caches.module';
import { TestModule } from './modules/test/test.module';
import { PluginsModule } from './modules/plugins/plugins.module';
import { GlobalModule } from './modules/global/global.module';
import { LocalStrategy } from './strategies/local.strategy'
import NcConfigFactory from './utils/NcConfigFactory'
import NcUpgrader from './version-upgrader/NcUpgrader';
import type {
@ -123,11 +125,13 @@ export const JwtStrategyProvider: Provider = {
],
controllers: [],
providers: [
AuthService,
{
provide: APP_FILTER,
useClass: GlobalExceptionFilter,
},
JwtStrategyProvider,
LocalStrategy,
ExtractProjectIdMiddleware,
],
})

6
packages/nocodb-nest/src/modules/auth/auth.service.ts

@ -5,6 +5,8 @@ import * as bcrypt from 'bcryptjs';
import { JwtService } from '@nestjs/jwt';
import { v4 as uuidv4 } from 'uuid';
import Noco from '../../Noco'
import { genJwt } from '../users/helpers'
import { UsersService } from '../users/users.service';
import { Connection } from '../../connection/connection';
import type { CreateUserDto } from './auth.controller';
@ -13,7 +15,7 @@ import type { CreateUserDto } from './auth.controller';
export class AuthService {
constructor(
private usersService: UsersService,
private jwtService: JwtService,
// private jwtService: JwtService,
private connection: Connection,
) {}
@ -35,7 +37,7 @@ export class AuthService {
delete user.salt;
const payload = user;
return {
token: this.jwtService.sign(payload),
token: genJwt(payload, Noco.getConfig()),
};
}

1
packages/nocodb-nest/src/modules/users/users.controller.ts

@ -106,6 +106,7 @@ export class UsersController {
'/api/v1/auth/user/signin',
])
@UseGuards(AuthGuard('local'))
@HttpCode(200)
async signin(@Request() req) {
return this.usersService.login(req.user);
}

50
packages/nocodb-nest/src/modules/utils/utils.controller.ts

@ -1,4 +1,16 @@
import { Controller, Get, Request } from '@nestjs/common';
import {
Body,
Controller,
Get,
Post,
Request,
UseGuards,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
ExtractProjectIdMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { UtilsService } from './utils.service';
@Controller()
@ -16,4 +28,40 @@ export class UtilsController {
version() {
return this.utilsService.versionInfo();
}
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
@Post('/api/v1/db/meta/connection/test')
@Acl('testConnection')
async testConnection(@Body() body: any) {
return await this.utilsService.testConnection({ body });
}
@Get('/api/v1/db/meta/nocodb/info')
async appInfo(@Request() req) {
return await this.utilsService.appInfo({
req: {
ncSiteUrl: (req as any).ncSiteUrl,
},
});
}
@Get('/api/v1/health')
async appHealth() {
return await this.utilsService.appHealth();
}
@Post('/api/v1/db/meta/axiosRequestMake')
async axiosRequestMake(@Body() body: any) {
return await this.utilsService.axiosRequestMake({ body });
}
@Get('/api/v1/aggregated-meta-info')
async aggregatedMetaInfo() {
return await this.utilsService.aggregatedMetaInfo();
}
@Post('/api/v1/url_to_config')
async urlToDbConfig(@Body() body: any) {
return await this.utilsService.urlToDbConfig({
body,
});
}
}

45
packages/nocodb-nest/src/modules/utils/utils.service.ts

@ -2,8 +2,10 @@ import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { compareVersions, validate } from 'compare-versions';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
import SqlMgrv2 from '../../db/sql-mgr/v2/SqlMgrv2'
import { NcError } from '../../helpers/catchError';
import { User } from '../../models';
import Noco from '../../Noco'
import NcConfigFactory from '../../utils/NcConfigFactory';
import { packageVersion } from '../../utils/packageVersion';
// import { packageVersion } from '../packageVersion';
@ -381,4 +383,47 @@ export class UtilsService {
return null;
});
};
async testConnection(param: { body: any }) {
return await SqlMgrv2.testConnection(param.body);
}
async appInfo(param: { req: { ncSiteUrl: string } }) {
const projectHasAdmin = !(await User.isFirst());
const result = {
authType: 'jwt',
projectHasAdmin,
firstUser: !projectHasAdmin,
type: 'rest',
env: process.env.NODE_ENV,
googleAuthEnabled: !!(
process.env.NC_GOOGLE_CLIENT_ID && process.env.NC_GOOGLE_CLIENT_SECRET
),
githubAuthEnabled: !!(
process.env.NC_GITHUB_CLIENT_ID && process.env.NC_GITHUB_CLIENT_SECRET
),
oneClick: !!process.env.NC_ONE_CLICK,
connectToExternalDB: !process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED,
version: packageVersion,
defaultLimit: Math.max(
Math.min(
+process.env.DB_QUERY_LIMIT_DEFAULT || 25,
+process.env.DB_QUERY_LIMIT_MAX || 100,
),
+process.env.DB_QUERY_LIMIT_MIN || 1,
),
timezone: defaultConnectionConfig.timezone,
ncMin: !!process.env.NC_MIN,
teleEnabled: process.env.NC_DISABLE_TELE !== 'true',
auditEnabled: process.env.NC_DISABLE_AUDIT !== 'true',
ncSiteUrl: (param.req as any).ncSiteUrl,
ee: Noco.isEE(),
ncAttachmentFieldSize: NC_ATTACHMENT_FIELD_SIZE,
ncMaxAttachmentsAllowed: +(process.env.NC_MAX_ATTACHMENTS_ALLOWED || 10),
isCloud: process.env.NC_CLOUD === 'true',
automationLogLevel: process.env.NC_AUTOMATION_LOG_LEVEL || 'OFF',
};
return result;
}
}

Loading…
Cancel
Save