@n42/cli 0.1.33 → 0.1.38
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 +1 -1
- package/src/auth.js +12 -7
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -57,7 +57,7 @@ async function refreshSession() {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const payload = {
|
|
60
|
-
|
|
60
|
+
token: refreshToken,
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const res = await fetch(`${API_URL}/${EP_REFRESH}`, {
|
|
@@ -86,17 +86,14 @@ async function refreshSession() {
|
|
|
86
86
|
idToken: data.idToken
|
|
87
87
|
})
|
|
88
88
|
);
|
|
89
|
-
//console.log("Token refreshed");
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
return true;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
async function fetchWithAuth(url, options = {}) {
|
|
96
|
-
|
|
97
|
-
if (!accessToken) {
|
|
98
|
-
//console.log("Token missing...");
|
|
99
|
-
|
|
95
|
+
let { accessToken } = loadAuth();
|
|
96
|
+
if (!accessToken) {
|
|
100
97
|
handleError({ code: "N42E-9032" });
|
|
101
98
|
return;
|
|
102
99
|
}
|
|
@@ -115,9 +112,17 @@ async function fetchWithAuth(url, options = {}) {
|
|
|
115
112
|
|
|
116
113
|
const refreshed = await refreshSession();
|
|
117
114
|
if (!refreshed) { // N42E-9033
|
|
118
|
-
//console.log("Token expired...");
|
|
119
115
|
return res;
|
|
120
116
|
}
|
|
117
|
+
|
|
118
|
+
accessToken = loadAuth().accessToken;
|
|
119
|
+
return fetch(url, {
|
|
120
|
+
...options,
|
|
121
|
+
headers: {
|
|
122
|
+
...(options.headers || {}),
|
|
123
|
+
Authorization: `Bearer ${accessToken}`
|
|
124
|
+
}
|
|
125
|
+
});
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
module.exports = { loadAuth, checkAuth, fetchWithAuth };
|