Skip to content

Commit

Permalink
feat: invalidate cookies when refresh token is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-tkachenko committed Nov 17, 2023
1 parent f6718e9 commit e7119d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/handlers/LoginHandler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { IncomingMessage, ServerResponse } from "http";
import { HttpMethod, ProxyRequest, RequestHandlerConfig } from "prxi";
import { getConfig } from "../config/getConfig";
import { invalidateAuthCookies, sendRedirect } from "../utils/ResponseUtils";
import { sendRedirect } from "../utils/ResponseUtils";
import { OpenIDUtils } from "../utils/OpenIDUtils";
import { Logger } from "pino";
import getLogger from "../Logger";
import { JwtPayload, verify } from "jsonwebtoken";
import { RequestUtils } from "../utils/RequestUtils";

export class LoginHandler implements RequestHandlerConfig {
private logger: Logger;
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/ProxyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class ProxyHandler implements RequestHandlerConfig {
accessToken = context.accessToken = null;
idToken = context.idToken = null;
refreshToken = context.refreshToken = null;
invalidateAuthCookies(res);

accessTokenVerificationResult = JWTVerificationResult.MISSING;
}
Expand Down Expand Up @@ -204,8 +205,9 @@ export class ProxyHandler implements RequestHandlerConfig {
delete context.accessTokenJWT;
}
} else if (accessTokenVerificationResult !== JWTVerificationResult.SUCCESS) {
invalidateAuthCookies(res);

if (context.page) {
invalidateAuthCookies(res);
await sendRedirect(res, OpenIDUtils.getAuthorizationUrl());
} else {
sendErrorResponse(req, 401, 'Unauthorized', res);
Expand Down

0 comments on commit e7119d2

Please sign in to comment.