@autobusal/providers 1.2.9 → 1.2.10

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/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to `@autobusal/providers` are documented here. This project
4
4
  adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.2.10] - 2026-07-19
8
+
9
+ ### Fixed
10
+
11
+ - Resilient bff-mode auth: on a 401 the apiClient now confirms the session with the BFF (GET /bff/session) before logging out, and transparently retries the request once if still authenticated. Prevents a transient post-login 401 (an account query racing the login cookie hand-off) from bouncing the user straight back to the login page. Bearer mode is unchanged.
7
12
  ## [1.2.9] - 2026-07-19
8
13
 
9
14
  ### Added
@@ -39,11 +39,35 @@ if (!isBffMode) {
39
39
 
40
40
  apiClient.interceptors.response.use(response => (
41
41
  response
42
- ), error => {
42
+ ), async (error) => {
43
43
  if (error.response) {
44
- // if we have a 401, we go to the logout page (if not already there)
44
+ // if we have a 401, the session is gone, so we go to the logout page.
45
45
  if (error.response.status === 401 && window.location.pathname !== '/account/logout') {
46
+ // bff mode: auth is a server-side httpOnly cookie the BFF manages. A
47
+ // request that races the login/cookie hand-off (e.g. the account queries
48
+ // fired the instant the SPA lands on /account) can 401 transiently while
49
+ // the session is actually valid - and a blind logout here would drop the
50
+ // user straight back out. So confirm with the BFF first; if we are still
51
+ // authenticated, transparently retry the request once instead of logging
52
+ // out. bearer mode has no such race (the token is attached synchronously
53
+ // from localStorage) and falls straight through to logout.
54
+ if (isBffMode && error.config && !error.config._bffAuthRetried) {
55
+ try {
56
+ const { data } = await apiClient.get('/session');
57
+
58
+ if (data?.authenticated) {
59
+ error.config._bffAuthRetried = true;
60
+
61
+ return await apiClient(error.config);
62
+ }
63
+ } catch {
64
+ // /session unreachable - fall through to logout.
65
+ }
66
+ }
67
+
46
68
  window.location.href = '/account/logout';
69
+
70
+ return Promise.reject(error);
47
71
  }
48
72
 
49
73
  // if the user is not valid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/providers",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"