Skip to content

Commit

Permalink
fix(admin-server): auto prolong auth cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Jul 26, 2024
1 parent 261f2a9 commit dab0de6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ee/admin-server/src/services/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LoginController } from '../controllers/LoginController'
import { LegacyController } from '../controllers/LegacyController'
import { PanelController } from '../controllers/PanelController'
import { ProjectController } from '../controllers/ProjectController'
import { refreshAuthCookie } from '../utils/cookies'

export class Router {
constructor(
Expand All @@ -25,6 +26,7 @@ export class Router {
}

async handle(req: IncomingMessage, res: ServerResponse) {
refreshAuthCookie(req, res)
try {
const url = new URL(req.url ?? '/', `http://${req.headers.host}`)
const [prefix, ...rest] = url.pathname.substring(1).split('/')
Expand Down
7 changes: 7 additions & 0 deletions ee/admin-server/src/utils/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ export function writeAuthCookie(req: IncomingMessage, res: OutgoingMessage, toke
}),
)
}

export const refreshAuthCookie = (req: IncomingMessage, res: OutgoingMessage): void => {
const token = readAuthCookie(req)
if (token !== null) {
writeAuthCookie(req, res, token)
}
}

0 comments on commit dab0de6

Please sign in to comment.