From fd5972f17a702a53e96bec758a4d1388a339cd28 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Fri, 13 Oct 2023 12:15:33 +0300 Subject: [PATCH] apps/api: fix update token --- apps/api/src/auth/auth.controller.ts | 9 +++++---- apps/web/middleware.ts | 13 ------------- 2 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 apps/web/middleware.ts diff --git a/apps/api/src/auth/auth.controller.ts b/apps/api/src/auth/auth.controller.ts index 2b550ce..0ed2848 100644 --- a/apps/api/src/auth/auth.controller.ts +++ b/apps/api/src/auth/auth.controller.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/explicit-member-accessibility */ /* eslint-disable class-methods-use-this */ /* eslint-disable import/no-extraneous-dependencies */ import { AuthService } from './auth.service'; @@ -33,7 +34,7 @@ export class AuthController { try { const token = await this.authService.login(login, password); - return await reply.setCookie(COOKIE_TOKEN_NAME, token, this.cookieOptions).status(200).send(); + return reply.setCookie(COOKIE_TOKEN_NAME, token, this.cookieOptions).status(200).send(); } catch { throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED); } @@ -56,15 +57,15 @@ export class AuthController { try { this.authService.checkToken(token); - return await reply.send(); + return reply.send(); } catch (error) { if (error.name === 'TokenExpiredError') { const newToken = this.authService.refreshToken(token); - return await reply.setCookie(COOKIE_TOKEN_NAME, newToken, this.cookieOptions).send(); + return reply.setCookie(COOKIE_TOKEN_NAME, newToken, this.cookieOptions).send(); } - throw new HttpException('Unauthorized', HttpStatus.UNAUTHORIZED); + return reply.status(HttpStatus.UNAUTHORIZED).send(); } } } diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts deleted file mode 100644 index ddb58b1..0000000 --- a/apps/web/middleware.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { NextResponse } from 'next/server'; -import type { NextRequest } from 'next/server'; - -export function middleware(request: NextRequest) { - if (request.nextUrl.pathname === '/') { - if (request.cookies.get('token')) { - const url = request.nextUrl.clone(); - const uri = url?.searchParams.get('uri') || '/'; - - return NextResponse.redirect(new URL(uri, request.url)); - } - } -}