|
|
@ -5,10 +5,11 @@ import { |
|
|
|
HttpCode, |
|
|
|
HttpCode, |
|
|
|
Param, |
|
|
|
Param, |
|
|
|
Post, |
|
|
|
Post, |
|
|
|
Request, |
|
|
|
Req, |
|
|
|
Response, |
|
|
|
Res, |
|
|
|
UseGuards, |
|
|
|
UseGuards, |
|
|
|
} from '@nestjs/common'; |
|
|
|
} from '@nestjs/common'; |
|
|
|
|
|
|
|
import { Request, Response } from 'express'; |
|
|
|
import { AuthGuard } from '@nestjs/passport'; |
|
|
|
import { AuthGuard } from '@nestjs/passport'; |
|
|
|
import { ConfigService } from '@nestjs/config'; |
|
|
|
import { ConfigService } from '@nestjs/config'; |
|
|
|
import { extractRolesObj } from 'nocodb-sdk'; |
|
|
|
import { extractRolesObj } from 'nocodb-sdk'; |
|
|
@ -41,7 +42,7 @@ export class AuthController { |
|
|
|
]) |
|
|
|
]) |
|
|
|
@UseGuards(PublicApiLimiterGuard) |
|
|
|
@UseGuards(PublicApiLimiterGuard) |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async signup(@Req() req: Request, @Response() res: any): Promise<any> { |
|
|
|
async signup(@Req() req: Request, @Res() res:Response): Promise<any> { |
|
|
|
if (this.config.get('auth', { infer: true }).disableEmailAuth) { |
|
|
|
if (this.config.get('auth', { infer: true }).disableEmailAuth) { |
|
|
|
NcError.forbidden('Email authentication is disabled'); |
|
|
|
NcError.forbidden('Email authentication is disabled'); |
|
|
|
} |
|
|
|
} |
|
|
@ -61,7 +62,7 @@ export class AuthController { |
|
|
|
]) |
|
|
|
]) |
|
|
|
@UseGuards(PublicApiLimiterGuard) |
|
|
|
@UseGuards(PublicApiLimiterGuard) |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async refreshToken(@Req() req: Request, @Response() res: any): Promise<any> { |
|
|
|
async refreshToken(@Req() req: Request, @Res() res:Response): Promise<any> { |
|
|
|
res.json( |
|
|
|
res.json( |
|
|
|
await this.usersService.refreshToken({ |
|
|
|
await this.usersService.refreshToken({ |
|
|
|
body: req.body, |
|
|
|
body: req.body, |
|
|
@ -78,7 +79,7 @@ export class AuthController { |
|
|
|
]) |
|
|
|
]) |
|
|
|
@UseGuards(PublicApiLimiterGuard, AuthGuard('local')) |
|
|
|
@UseGuards(PublicApiLimiterGuard, AuthGuard('local')) |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async signin(@Request() req, @Response() res) { |
|
|
|
async signin(@Req() req:Request, @Res() res:Response) { |
|
|
|
if (this.config.get('auth', { infer: true }).disableEmailAuth) { |
|
|
|
if (this.config.get('auth', { infer: true }).disableEmailAuth) { |
|
|
|
NcError.forbidden('Email authentication is disabled'); |
|
|
|
NcError.forbidden('Email authentication is disabled'); |
|
|
|
} |
|
|
|
} |
|
|
@ -89,7 +90,7 @@ export class AuthController { |
|
|
|
@UseGuards(GlobalGuard) |
|
|
|
@UseGuards(GlobalGuard) |
|
|
|
@Post('/api/v1/auth/user/signout') |
|
|
|
@Post('/api/v1/auth/user/signout') |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async signOut(@Request() req, @Response() res): Promise<any> { |
|
|
|
async signOut(@Req() req:Request, @Res() res:Response): Promise<any> { |
|
|
|
if (!(req as any).isAuthenticated()) { |
|
|
|
if (!(req as any).isAuthenticated()) { |
|
|
|
NcError.forbidden('Not allowed'); |
|
|
|
NcError.forbidden('Not allowed'); |
|
|
|
} |
|
|
|
} |
|
|
@ -104,7 +105,7 @@ export class AuthController { |
|
|
|
@Post(`/auth/google/genTokenByCode`) |
|
|
|
@Post(`/auth/google/genTokenByCode`) |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
@UseGuards(PublicApiLimiterGuard, AuthGuard('google')) |
|
|
|
@UseGuards(PublicApiLimiterGuard, AuthGuard('google')) |
|
|
|
async googleSignin(@Request() req, @Response() res) { |
|
|
|
async googleSignin(@Req() req:Request, @Res() res:Response) { |
|
|
|
await this.setRefreshToken({ req, res }); |
|
|
|
await this.setRefreshToken({ req, res }); |
|
|
|
res.json(await this.usersService.login(req.user, req)); |
|
|
|
res.json(await this.usersService.login(req.user, req)); |
|
|
|
} |
|
|
|
} |
|
|
@ -117,7 +118,7 @@ export class AuthController { |
|
|
|
|
|
|
|
|
|
|
|
@Get(['/auth/user/me', '/api/v1/db/auth/user/me', '/api/v1/auth/user/me']) |
|
|
|
@Get(['/auth/user/me', '/api/v1/db/auth/user/me', '/api/v1/auth/user/me']) |
|
|
|
@UseGuards(MetaApiLimiterGuard, GlobalGuard) |
|
|
|
@UseGuards(MetaApiLimiterGuard, GlobalGuard) |
|
|
|
async me(@Request() req) { |
|
|
|
async me(@Req() req:Request) { |
|
|
|
const user = { |
|
|
|
const user = { |
|
|
|
...req.user, |
|
|
|
...req.user, |
|
|
|
roles: extractRolesObj(req.user.roles), |
|
|
|
roles: extractRolesObj(req.user.roles), |
|
|
@ -228,7 +229,7 @@ export class AuthController { |
|
|
|
@UseGuards(PublicApiLimiterGuard) |
|
|
|
@UseGuards(PublicApiLimiterGuard) |
|
|
|
async renderPasswordReset( |
|
|
|
async renderPasswordReset( |
|
|
|
@Req() req: Request, |
|
|
|
@Req() req: Request, |
|
|
|
@Response() res: any, |
|
|
|
@Res() res:Response, |
|
|
|
@Param('tokenId') tokenId: string, |
|
|
|
@Param('tokenId') tokenId: string, |
|
|
|
): Promise<any> { |
|
|
|
): Promise<any> { |
|
|
|
try { |
|
|
|
try { |
|
|
|