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