authula 0.7.0 → 0.7.1
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/dist/plugins/index.js
CHANGED
|
@@ -2733,10 +2733,10 @@ var BearerPlugin = class {
|
|
|
2733
2733
|
if (typeof document === "undefined") return;
|
|
2734
2734
|
const headerName = this.options?.headerName ?? "Authorization";
|
|
2735
2735
|
const token = localStorage.getItem("accessToken");
|
|
2736
|
-
if (token)
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
}
|
|
2736
|
+
if (token) {
|
|
2737
|
+
if (!(ctx.init.headers instanceof Headers)) ctx.init.headers = new Headers(ctx.init.headers);
|
|
2738
|
+
ctx.init.headers.set(headerName, `Bearer ${token}`);
|
|
2739
|
+
}
|
|
2740
2740
|
});
|
|
2741
2741
|
client.registerAfterFetch(async (ctx, res) => {
|
|
2742
2742
|
if (typeof document === "undefined") return;
|
|
@@ -2762,10 +2762,8 @@ var BearerPlugin = class {
|
|
|
2762
2762
|
const refreshed = await this.refreshPromise;
|
|
2763
2763
|
if (!refreshed) return;
|
|
2764
2764
|
const headerName = this.options?.headerName ?? "Authorization";
|
|
2765
|
-
ctx.init.headers =
|
|
2766
|
-
|
|
2767
|
-
[headerName]: `Bearer ${refreshed.accessToken}`
|
|
2768
|
-
};
|
|
2765
|
+
if (!(ctx.init.headers instanceof Headers)) ctx.init.headers = new Headers(ctx.init.headers);
|
|
2766
|
+
ctx.init.headers.set(headerName, `Bearer ${refreshed.accessToken}`);
|
|
2769
2767
|
return "retry";
|
|
2770
2768
|
});
|
|
2771
2769
|
return {};
|