From 0317f3a508dc88ffe2c33413704f7df03a2372ea Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Sat, 4 Mar 2023 23:40:02 +0100 Subject: [PATCH] fix: frontend error when user deleted --- backend/src/user/user.controller.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/user/user.controller.ts b/backend/src/user/user.controller.ts index 08ebf73f..5088b45b 100644 --- a/backend/src/user/user.controller.ts +++ b/backend/src/user/user.controller.ts @@ -6,9 +6,11 @@ import { Param, Patch, Post, + Res, UseGuards, } from "@nestjs/common"; import { User } from "@prisma/client"; +import { Response } from "express"; import { GetUser } from "src/auth/decorator/getUser.decorator"; import { AdministratorGuard } from "src/auth/guard/isAdmin.guard"; import { JwtGuard } from "src/auth/guard/jwt.guard"; @@ -40,7 +42,16 @@ export class UserController { @Delete("me") @UseGuards(JwtGuard) - async deleteCurrentUser(@GetUser() user: User) { + async deleteCurrentUser( + @GetUser() user: User, + @Res({ passthrough: true }) response: Response + ) { + response.cookie("access_token", "accessToken", { maxAge: -1 }); + response.cookie("refresh_token", "", { + path: "/api/auth/token", + httpOnly: true, + maxAge: -1, + }); return new UserDTO().from(await this.userService.delete(user.id)); }