fix : reduce calls to discord api
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
Redirect,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { UserResponseDTO } from '../../events/dto/userresponse.dto';
|
||||
@@ -15,6 +16,7 @@ import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { SessionData } from 'express-session';
|
||||
import { AuthGuard } from './guards/auth.guard';
|
||||
|
||||
const configService = new ConfigService();
|
||||
|
||||
@@ -39,13 +41,17 @@ export class UsersController {
|
||||
}
|
||||
|
||||
@Get('/whoami')
|
||||
@UseGuards(AuthGuard)
|
||||
async remove(@Session() session: SessionData): Promise<UserResponseDTO> {
|
||||
if (!session.tokenData) {
|
||||
if (!session.tokenData || !session.user) {
|
||||
throw new HttpException(
|
||||
"Session doesn't contains auth information",
|
||||
HttpStatus.UNAUTHORIZED,
|
||||
);
|
||||
}
|
||||
if (new Date(session.tokenData.expires) > new Date()) {
|
||||
return this.usersService.findUser(session.user.id);
|
||||
}
|
||||
await this.usersService.discordLogin(session);
|
||||
return new UserResponseDTO(session.user);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user