Skip to content

Commit a873450

Browse files
committed
fix(backend): read refresh token from same cookie set as session token
Align refreshTokenInCookie with sessionTokenInCookie by respecting usesSuffixedCookies() decision, with fallback to suffixed cookie for backwards compatibility during the transition period.
1 parent 4e683ba commit a873450

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

packages/backend/src/tokens/authenticateContext.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,14 @@ class AuthenticateContext implements AuthenticateContext {
283283
private initCookieValues() {
284284
// suffixedCookies needs to be set first because it's used in getMultipleAppsCookie
285285
this.sessionTokenInCookie = this.getSuffixedOrUnSuffixedCookie(constants.Cookies.Session);
286-
// Read the refresh token from the same cookie set as the session token, but fall back
287-
// to the suffixed cookie for backwards compatibility (FAPI always sets the suffixed
288-
// refresh cookie, so during the transition to suffixed cookies it may only exist there).
289-
this.refreshTokenInCookie =
290-
this.getSuffixedOrUnSuffixedCookie(constants.Cookies.Refresh) ||
291-
this.getSuffixedCookie(constants.Cookies.Refresh);
286+
// Read the refresh token from the same cookie set (suffixed vs unsuffixed) that
287+
// usesSuffixedCookies() selects, so it stays in sync with the session token.
288+
// When usesSuffixedCookies() is false but the unsuffixed refresh cookie doesn't
289+
// exist yet (transition period), fall back to the suffixed cookie since FAPI
290+
// always sets that one.
291+
this.refreshTokenInCookie = this.usesSuffixedCookies()
292+
? this.getSuffixedCookie(constants.Cookies.Refresh)
293+
: this.getCookie(constants.Cookies.Refresh) || this.getSuffixedCookie(constants.Cookies.Refresh);
292294
this.clientUat = Number.parseInt(this.getSuffixedOrUnSuffixedCookie(constants.Cookies.ClientUat) || '') || 0;
293295
}
294296

0 commit comments

Comments
 (0)