una-nuxt-module 3.0.34 → 3.0.35
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 +1 -1
- package/dist/runtime/auth/stores/auth.js +27 -10
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { computed, ref, useNuxtApp } from "#imports";
|
|
1
|
+
import { computed, ref, useNuxtApp, useRuntimeConfig } from "#imports";
|
|
2
2
|
import { defineStore } from "pinia";
|
|
3
3
|
import { EAuthorization } from "../../enums/EAuthorization.js";
|
|
4
|
+
const LOGOUT_ENDPOINT = "/api/usuario/logout";
|
|
4
5
|
export const useAuthStore = defineStore("AuthStore", () => {
|
|
5
6
|
const user = ref(null);
|
|
6
7
|
const authData = ref(null);
|
|
@@ -10,29 +11,45 @@ export const useAuthStore = defineStore("AuthStore", () => {
|
|
|
10
11
|
const token = computed(() => authData.value?.accessToken ?? null);
|
|
11
12
|
const logout = async () => {
|
|
12
13
|
const { $signOut } = useNuxtApp();
|
|
13
|
-
|
|
14
|
+
const runtimeConfig = useRuntimeConfig();
|
|
15
|
+
const baseURL = runtimeConfig.public.apiBaseUrl;
|
|
16
|
+
try {
|
|
17
|
+
await $fetch(LOGOUT_ENDPOINT, {
|
|
18
|
+
baseURL,
|
|
19
|
+
method: "DELETE",
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${token.value}`
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error("Error en logout:", error);
|
|
26
|
+
} finally {
|
|
27
|
+
await $signOut();
|
|
28
|
+
}
|
|
14
29
|
};
|
|
15
30
|
const update = (userInfo, data) => {
|
|
16
31
|
user.value = userInfo;
|
|
17
32
|
authData.value = data;
|
|
18
33
|
};
|
|
19
34
|
const hasResource = (resource) => {
|
|
20
|
-
return
|
|
35
|
+
return authData.value?.resources?.some(
|
|
36
|
+
(currentResource) => currentResource.nombre === resource
|
|
37
|
+
) ?? false;
|
|
21
38
|
};
|
|
22
39
|
const hasAuthorizationInResource = ({
|
|
23
40
|
resource,
|
|
24
41
|
authorization
|
|
25
42
|
}) => {
|
|
26
43
|
const resourceData = authData.value?.resources.find(
|
|
27
|
-
(
|
|
44
|
+
(currentResource) => currentResource.nombre === resource
|
|
28
45
|
);
|
|
29
46
|
if (!resourceData) return false;
|
|
30
|
-
const permissions =
|
|
31
|
-
[EAuthorization.CREATE
|
|
32
|
-
[EAuthorization.EDIT
|
|
33
|
-
[EAuthorization.DELETE
|
|
34
|
-
|
|
35
|
-
return permissions
|
|
47
|
+
const permissions = {
|
|
48
|
+
[EAuthorization.CREATE]: resourceData.permisoInsertar,
|
|
49
|
+
[EAuthorization.EDIT]: resourceData.permisoModificar,
|
|
50
|
+
[EAuthorization.DELETE]: resourceData.permisoEliminar
|
|
51
|
+
};
|
|
52
|
+
return permissions[authorization] ?? false;
|
|
36
53
|
};
|
|
37
54
|
return {
|
|
38
55
|
user,
|