apps/api: fix update token
This commit is contained in:
parent
6be2af972c
commit
fd5972f17a
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user