una-nuxt-module 3.0.40 → 3.0.41
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/module.json +1 -1
- package/dist/module.mjs +2 -2
- package/dist/runtime/repository-pattern/plugins/{api-public-fetch.d.ts → api-fetch-auth.d.ts} +2 -0
- package/dist/runtime/repository-pattern/plugins/api-fetch-auth.js +30 -0
- package/dist/runtime/repository-pattern/plugins/api-fetch.js +2 -18
- package/package.json +1 -1
- package/dist/runtime/repository-pattern/plugins/api-public-fetch.js +0 -11
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -167,7 +167,7 @@ function addTemplates() {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
const name = "una-nuxt-module";
|
|
170
|
-
const version = "3.0.
|
|
170
|
+
const version = "3.0.41";
|
|
171
171
|
const description = "Módulo Nuxt para desarrollo.";
|
|
172
172
|
const repository = {
|
|
173
173
|
type: "git",
|
|
@@ -572,7 +572,7 @@ const module$1 = defineNuxtModule({
|
|
|
572
572
|
addPlugin({
|
|
573
573
|
name: "api-fetch",
|
|
574
574
|
src: resolve(
|
|
575
|
-
`./runtime/repository-pattern/plugins/${options.auth?.enabled ? "api-fetch" : "api-
|
|
575
|
+
`./runtime/repository-pattern/plugins/${options.auth?.enabled ? "api-fetch-auth" : "api-fetch"}`
|
|
576
576
|
),
|
|
577
577
|
mode: "client"
|
|
578
578
|
});
|
package/dist/runtime/repository-pattern/plugins/{api-public-fetch.d.ts → api-fetch-auth.d.ts}
RENAMED
|
@@ -2,10 +2,12 @@ import { type $Fetch } from '#app';
|
|
|
2
2
|
declare const _default: import("#app").Plugin<{
|
|
3
3
|
api: {
|
|
4
4
|
fetch: $Fetch<unknown, "">;
|
|
5
|
+
publicFetch: $Fetch<unknown, "">;
|
|
5
6
|
};
|
|
6
7
|
}> & import("#app").ObjectPlugin<{
|
|
7
8
|
api: {
|
|
8
9
|
fetch: $Fetch<unknown, "">;
|
|
10
|
+
publicFetch: $Fetch<unknown, "">;
|
|
9
11
|
};
|
|
10
12
|
}>;
|
|
11
13
|
export default _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useNuxtApp } from "#app";
|
|
2
|
+
import { useAuthStore } from "#imports";
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
+
const fetch = $fetch.create({
|
|
5
|
+
baseURL: nuxtApp.$config.public.apiBaseUrl,
|
|
6
|
+
onRequest({ options }) {
|
|
7
|
+
const { $pinia } = useNuxtApp();
|
|
8
|
+
const authStore = useAuthStore($pinia);
|
|
9
|
+
if (!authStore.isAuthenticated) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
options.headers.set("Authorization", `Bearer ${authStore.token}`);
|
|
13
|
+
},
|
|
14
|
+
async onResponseError({ response }) {
|
|
15
|
+
if (response?.status === 401) {
|
|
16
|
+
const { $pinia } = useNuxtApp();
|
|
17
|
+
const authStore = useAuthStore($pinia);
|
|
18
|
+
await authStore.logout();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const publicFetch = $fetch.create({
|
|
23
|
+
baseURL: nuxtApp.$config.public.apiBaseUrl
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
provide: {
|
|
27
|
+
api: { fetch, publicFetch }
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import { defineNuxtPlugin
|
|
2
|
-
import { useAuthStore } from "#imports";
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
3
2
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
3
|
const fetch = $fetch.create({
|
|
5
|
-
baseURL: nuxtApp.$config.public.apiBaseUrl
|
|
6
|
-
onRequest({ options }) {
|
|
7
|
-
const { $pinia } = useNuxtApp();
|
|
8
|
-
const authStore = useAuthStore($pinia);
|
|
9
|
-
if (!authStore.isAuthenticated) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
options.headers.set("Authorization", `Bearer ${authStore.token}`);
|
|
13
|
-
},
|
|
14
|
-
async onResponseError({ response }) {
|
|
15
|
-
if (response?.status === 401) {
|
|
16
|
-
const { $pinia } = useNuxtApp();
|
|
17
|
-
const authStore = useAuthStore($pinia);
|
|
18
|
-
await authStore.logout();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
4
|
+
baseURL: nuxtApp.$config.public.apiBaseUrl
|
|
21
5
|
});
|
|
22
6
|
return {
|
|
23
7
|
provide: {
|
package/package.json
CHANGED