@pagamio/frontend-commons-lib 0.8.255 → 0.8.256

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.
@@ -60,27 +60,30 @@ export class TokenManager {
60
60
  }
61
61
  async refreshTokens() {
62
62
  try {
63
+ // The refresh token is stored as an httpOnly cookie and cannot be read
64
+ // by JS. We send `credentials: 'include'` so the browser attaches it
65
+ // automatically, and `x-origin-web` so the backend reads from cookies.
63
66
  const oldRefreshToken = this.getRefreshToken();
64
- if (!oldRefreshToken) {
65
- this.clearAllTokens();
66
- throw new Error('No refresh token available');
67
- }
68
67
  const response = await fetch(`${this.baseUrl}${this.refreshEndpoint}`, {
69
68
  method: 'POST',
69
+ credentials: 'include',
70
70
  headers: {
71
71
  'Content-Type': 'application/json',
72
+ 'x-origin-web': 'web-client',
72
73
  },
73
- body: JSON.stringify({ refreshToken: oldRefreshToken }),
74
+ body: JSON.stringify(oldRefreshToken ? { refreshToken: oldRefreshToken } : {}),
74
75
  });
75
76
  const data = await response.json();
76
77
  if (!response.ok) {
77
- throw new Error(data.error || 'Failed to refresh token');
78
+ throw new Error(data.error || data.message || 'Failed to refresh token');
78
79
  }
79
- const { accessToken, refreshToken: newRefreshToken, accessTokenExpiresIn, refreshTokenExpiresIn } = data;
80
+ const { accessToken, accessTokenExpiresIn, refreshToken: newRefreshToken, refreshTokenExpiresIn } = data;
81
+ // Default to 1 hour if the backend doesn't return accessTokenExpiresIn
82
+ const expiresIn = accessTokenExpiresIn || 3600;
80
83
  this.handleAuthTokens({
81
84
  accessToken: {
82
85
  token: accessToken,
83
- expiresIn: accessTokenExpiresIn,
86
+ expiresIn,
84
87
  },
85
88
  ...(newRefreshToken && refreshTokenExpiresIn
86
89
  ? {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagamio/frontend-commons-lib",
3
3
  "description": "Pagamio library for Frontend reusable components like the form engine and table container",
4
- "version": "0.8.255",
4
+ "version": "0.8.256",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false