@defra/lis-hubs-infra-access 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/lis-hubs-infra-access",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Shared hub access and capability resolution for the livestock platform.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -196,13 +196,18 @@ function createLogoutController({
196
196
  auth: false
197
197
  },
198
198
  async handler(request, h) {
199
- const logoutUrl = await buildLogoutUrl(request)
200
-
201
- clearHubAuthSession(request)
199
+ // Build the logout URL while the session is still alive (it reads the
200
+ // id token for id_token_hint), but invalidate the session in `finally`
201
+ // so a failure building the URL cannot leave the session replayable.
202
+ try {
203
+ const logoutUrl = await buildLogoutUrl(request)
202
204
 
203
- return h
204
- .redirect(logoutUrl)
205
- .unstate(getHubJwtCookieName(), getCookieOptions())
205
+ return h
206
+ .redirect(logoutUrl)
207
+ .unstate(getHubJwtCookieName(), getCookieOptions())
208
+ } finally {
209
+ clearHubAuthSession(request)
210
+ }
206
211
  }
207
212
  }
208
213
  }
@@ -71,10 +71,9 @@ export function setHubAuthSession(request, authSession) {
71
71
  }
72
72
 
73
73
  /**
74
- * Clears both the hub authentication session and flow from the request.
74
+ * Fully resets the request's yar session (auth session and flow included).
75
75
  * @param {object} request - The Hapi request object with yar session support.
76
76
  */
77
77
  export function clearHubAuthSession(request) {
78
- request?.yar?.clear?.(authSessionKey)
79
- clearHubAuthFlow(request)
78
+ request?.yar?.reset?.()
80
79
  }