Return user and with current workspace

* Create endpoint to return user and their workspace
* Only return auth tokens on login/signup
* Allow nullable workspace name
This commit is contained in:
Philipinho
2023-08-26 23:38:14 +01:00
parent da8ee065df
commit 3e7c2de9a4
8 changed files with 85 additions and 28 deletions

View File

@ -1,11 +1,6 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
UseGuards,
HttpCode,
HttpStatus,
@ -13,11 +8,10 @@ import {
UnauthorizedException,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { JwtGuard } from '../auth/guards/JwtGuard';
import { FastifyRequest } from 'fastify';
import { User } from './entities/user.entity';
import { Workspace } from '../workspace/entities/workspace.entity';
@UseGuards(JwtGuard)
@Controller('user')
@ -36,4 +30,15 @@ export class UserController {
return { user };
}
@HttpCode(HttpStatus.OK)
@Get('info')
async getUserInfo(@Req() req: FastifyRequest) {
const jwtPayload = req['user'];
const data: { workspace: Workspace; user: User } =
await this.userService.getUserInstance(jwtPayload.sub);
return data;
}
}