@enfyra/sdk-nuxt 0.3.22 → 0.3.24
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/README.md +155 -328
- package/dist/module.cjs +7 -12
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +7 -12
- package/dist/runtime/composables/useEnfyra.d.ts +6 -0
- package/dist/runtime/composables/useEnfyra.d.ts.map +1 -0
- package/dist/runtime/composables/useEnfyra.js +13 -0
- package/dist/runtime/composables/useEnfyraAuth.d.ts +2 -88
- package/dist/runtime/composables/useEnfyraAuth.d.ts.map +1 -1
- package/dist/runtime/composables/useEnfyraAuth.js +35 -45
- package/package.json +1 -1
- package/src/module.ts +7 -12
- package/src/runtime/composables/useEnfyra.ts +21 -0
- package/src/runtime/composables/useEnfyraAuth.ts +39 -52
- package/dist/runtime/composables/useEnfyraApi.d.ts +0 -8
- package/dist/runtime/composables/useEnfyraApi.d.ts.map +0 -1
- package/dist/runtime/composables/useEnfyraApi.js +0 -347
- package/src/runtime/composables/useEnfyraApi.ts +0 -477
package/dist/module.cjs
CHANGED
|
@@ -61,8 +61,8 @@ enfyraSDK: {
|
|
|
61
61
|
}
|
|
62
62
|
kit.addImports([
|
|
63
63
|
{
|
|
64
|
-
name: "
|
|
65
|
-
from: resolve("./runtime/composables/
|
|
64
|
+
name: "useEnfyra",
|
|
65
|
+
from: resolve("./runtime/composables/useEnfyra")
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
name: "useEnfyraAuth",
|
|
@@ -72,18 +72,13 @@ enfyraSDK: {
|
|
|
72
72
|
kit.addTypeTemplate({
|
|
73
73
|
filename: "types/enfyra-sdk.d.ts",
|
|
74
74
|
getContents: () => `
|
|
75
|
-
import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from '@enfyra/sdk-nuxt/types'
|
|
76
|
-
|
|
77
75
|
declare module '#imports' {
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
export interface UseEnfyraReturn {
|
|
77
|
+
baseUrl: string;
|
|
78
|
+
apiPrefix: string;
|
|
79
|
+
}
|
|
82
80
|
|
|
83
|
-
export function
|
|
84
|
-
path: (() => string) | string,
|
|
85
|
-
opts?: ApiOptions<T> & { ssr?: false | undefined }
|
|
86
|
-
): UseEnfyraApiClientReturn<T>
|
|
81
|
+
export function useEnfyra(): UseEnfyraReturn
|
|
87
82
|
|
|
88
83
|
export function useEnfyraAuth(): import('@enfyra/sdk-nuxt/types').UseEnfyraAuthReturn
|
|
89
84
|
}
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,wBA6HG"}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -58,8 +58,8 @@ enfyraSDK: {
|
|
|
58
58
|
}
|
|
59
59
|
addImports([
|
|
60
60
|
{
|
|
61
|
-
name: "
|
|
62
|
-
from: resolve("./runtime/composables/
|
|
61
|
+
name: "useEnfyra",
|
|
62
|
+
from: resolve("./runtime/composables/useEnfyra")
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
name: "useEnfyraAuth",
|
|
@@ -69,18 +69,13 @@ enfyraSDK: {
|
|
|
69
69
|
addTypeTemplate({
|
|
70
70
|
filename: "types/enfyra-sdk.d.ts",
|
|
71
71
|
getContents: () => `
|
|
72
|
-
import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from '@enfyra/sdk-nuxt/types'
|
|
73
|
-
|
|
74
72
|
declare module '#imports' {
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
export interface UseEnfyraReturn {
|
|
74
|
+
baseUrl: string;
|
|
75
|
+
apiPrefix: string;
|
|
76
|
+
}
|
|
79
77
|
|
|
80
|
-
export function
|
|
81
|
-
path: (() => string) | string,
|
|
82
|
-
opts?: ApiOptions<T> & { ssr?: false | undefined }
|
|
83
|
-
): UseEnfyraApiClientReturn<T>
|
|
78
|
+
export function useEnfyra(): UseEnfyraReturn
|
|
84
79
|
|
|
85
80
|
export function useEnfyraAuth(): import('@enfyra/sdk-nuxt/types').UseEnfyraAuthReturn
|
|
86
81
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEnfyra.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyra.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,SAAS,IAAI,eAAe,CAU3C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
import { getAppUrl, normalizeUrl } from "../utils/url.js";
|
|
3
|
+
import { ENFYRA_API_PREFIX } from "../constants/config.js";
|
|
4
|
+
export function useEnfyra() {
|
|
5
|
+
const config = useRuntimeConfig().public.enfyraSDK;
|
|
6
|
+
const appUrl = getAppUrl();
|
|
7
|
+
const apiPrefix = config?.apiPrefix || ENFYRA_API_PREFIX;
|
|
8
|
+
const baseUrl = normalizeUrl(appUrl, apiPrefix);
|
|
9
|
+
return {
|
|
10
|
+
baseUrl,
|
|
11
|
+
apiPrefix
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,89 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function useEnfyraAuth():
|
|
3
|
-
readonly me: import("vue").Ref<{
|
|
4
|
-
id: string;
|
|
5
|
-
email: string;
|
|
6
|
-
isRootAdmin: boolean;
|
|
7
|
-
isSystem: boolean;
|
|
8
|
-
role?: {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
routePermissions: {
|
|
12
|
-
id: string;
|
|
13
|
-
isEnabled: boolean;
|
|
14
|
-
allowedUsers?: {
|
|
15
|
-
id: string;
|
|
16
|
-
}[] | undefined;
|
|
17
|
-
methods: {
|
|
18
|
-
id: string;
|
|
19
|
-
method: string;
|
|
20
|
-
}[];
|
|
21
|
-
route: {
|
|
22
|
-
id: string;
|
|
23
|
-
path: string;
|
|
24
|
-
};
|
|
25
|
-
}[];
|
|
26
|
-
} | undefined;
|
|
27
|
-
allowedRoutePermissions?: {
|
|
28
|
-
id: string;
|
|
29
|
-
isEnabled: boolean;
|
|
30
|
-
allowedUsers?: {
|
|
31
|
-
id: string;
|
|
32
|
-
}[] | undefined;
|
|
33
|
-
methods: {
|
|
34
|
-
id: string;
|
|
35
|
-
method: string;
|
|
36
|
-
}[];
|
|
37
|
-
route: {
|
|
38
|
-
id: string;
|
|
39
|
-
path: string;
|
|
40
|
-
};
|
|
41
|
-
}[] | undefined;
|
|
42
|
-
} | null, User | {
|
|
43
|
-
id: string;
|
|
44
|
-
email: string;
|
|
45
|
-
isRootAdmin: boolean;
|
|
46
|
-
isSystem: boolean;
|
|
47
|
-
role?: {
|
|
48
|
-
id: string;
|
|
49
|
-
name: string;
|
|
50
|
-
routePermissions: {
|
|
51
|
-
id: string;
|
|
52
|
-
isEnabled: boolean;
|
|
53
|
-
allowedUsers?: {
|
|
54
|
-
id: string;
|
|
55
|
-
}[] | undefined;
|
|
56
|
-
methods: {
|
|
57
|
-
id: string;
|
|
58
|
-
method: string;
|
|
59
|
-
}[];
|
|
60
|
-
route: {
|
|
61
|
-
id: string;
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
64
|
-
}[];
|
|
65
|
-
} | undefined;
|
|
66
|
-
allowedRoutePermissions?: {
|
|
67
|
-
id: string;
|
|
68
|
-
isEnabled: boolean;
|
|
69
|
-
allowedUsers?: {
|
|
70
|
-
id: string;
|
|
71
|
-
}[] | undefined;
|
|
72
|
-
methods: {
|
|
73
|
-
id: string;
|
|
74
|
-
method: string;
|
|
75
|
-
}[];
|
|
76
|
-
route: {
|
|
77
|
-
id: string;
|
|
78
|
-
path: string;
|
|
79
|
-
};
|
|
80
|
-
}[] | undefined;
|
|
81
|
-
} | null>;
|
|
82
|
-
readonly login: (payload: LoginPayload) => Promise<any>;
|
|
83
|
-
readonly logout: () => Promise<void>;
|
|
84
|
-
readonly fetchUser: (options?: {
|
|
85
|
-
fields?: string[];
|
|
86
|
-
}) => Promise<void>;
|
|
87
|
-
readonly isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
88
|
-
};
|
|
1
|
+
import type { UseEnfyraAuthReturn } from "../../types/auth";
|
|
2
|
+
export declare function useEnfyraAuth(): UseEnfyraAuthReturn;
|
|
89
3
|
//# sourceMappingURL=useEnfyraAuth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAOhF,wBAAgB,aAAa,IAAI,mBAAmB,CA8EnD"}
|
|
@@ -1,54 +1,22 @@
|
|
|
1
1
|
import { ref, computed } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { $fetch } from "../utils/http.js";
|
|
3
|
+
import { useEnfyra } from "./useEnfyra.js";
|
|
3
4
|
const me = ref(null);
|
|
4
5
|
const isLoading = ref(false);
|
|
5
6
|
export function useEnfyraAuth() {
|
|
6
|
-
const {
|
|
7
|
-
data: loginData,
|
|
8
|
-
execute: executeLogin,
|
|
9
|
-
error: loginError
|
|
10
|
-
} = useEnfyraApi("/login", {
|
|
11
|
-
method: "post",
|
|
12
|
-
errorContext: "Login"
|
|
13
|
-
});
|
|
14
|
-
const { execute: executeLogout } = useEnfyraApi("/logout", {
|
|
15
|
-
method: "post",
|
|
16
|
-
errorContext: "Logout"
|
|
17
|
-
});
|
|
18
|
-
const {
|
|
19
|
-
data: meData,
|
|
20
|
-
execute: executeFetchUser,
|
|
21
|
-
error: fetchUserError
|
|
22
|
-
} = useEnfyraApi("/me", {
|
|
23
|
-
errorContext: "Fetch User Profile"
|
|
24
|
-
});
|
|
25
|
-
const fetchUser = async (options) => {
|
|
26
|
-
isLoading.value = true;
|
|
27
|
-
try {
|
|
28
|
-
const queryParams = {};
|
|
29
|
-
if (options?.fields && options.fields.length > 0) {
|
|
30
|
-
queryParams.fields = options.fields.join(",");
|
|
31
|
-
}
|
|
32
|
-
await executeFetchUser({
|
|
33
|
-
query: queryParams
|
|
34
|
-
});
|
|
35
|
-
if (fetchUserError.value) {
|
|
36
|
-
me.value = null;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
me.value = meData.value?.data?.[0];
|
|
40
|
-
} finally {
|
|
41
|
-
isLoading.value = false;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
7
|
+
const { baseUrl } = useEnfyra();
|
|
44
8
|
const login = async (payload) => {
|
|
45
9
|
isLoading.value = true;
|
|
46
10
|
try {
|
|
47
|
-
await
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
11
|
+
const response = await $fetch(`${baseUrl}/login`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
body: payload
|
|
14
|
+
});
|
|
15
|
+
me.value = response?.data?.[0] || null;
|
|
16
|
+
return response;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error("[Enfyra Auth] Login error:", error);
|
|
19
|
+
return null;
|
|
52
20
|
} finally {
|
|
53
21
|
isLoading.value = false;
|
|
54
22
|
}
|
|
@@ -56,12 +24,15 @@ export function useEnfyraAuth() {
|
|
|
56
24
|
const logout = async () => {
|
|
57
25
|
isLoading.value = true;
|
|
58
26
|
try {
|
|
59
|
-
await
|
|
27
|
+
await $fetch(`${baseUrl}/logout`, {
|
|
28
|
+
method: "POST"
|
|
29
|
+
});
|
|
60
30
|
me.value = null;
|
|
61
31
|
if (typeof window !== "undefined") {
|
|
62
32
|
window.location.reload();
|
|
63
33
|
}
|
|
64
34
|
} catch (error) {
|
|
35
|
+
console.error("[Enfyra Auth] Logout error:", error);
|
|
65
36
|
me.value = null;
|
|
66
37
|
if (typeof window !== "undefined") {
|
|
67
38
|
window.location.reload();
|
|
@@ -70,6 +41,25 @@ export function useEnfyraAuth() {
|
|
|
70
41
|
isLoading.value = false;
|
|
71
42
|
}
|
|
72
43
|
};
|
|
44
|
+
const fetchUser = async (options) => {
|
|
45
|
+
isLoading.value = true;
|
|
46
|
+
try {
|
|
47
|
+
const queryParams = {};
|
|
48
|
+
if (options?.fields && options.fields.length > 0) {
|
|
49
|
+
queryParams.fields = options.fields.join(",");
|
|
50
|
+
}
|
|
51
|
+
const response = await $fetch(`${baseUrl}/me`, {
|
|
52
|
+
method: "GET",
|
|
53
|
+
query: queryParams
|
|
54
|
+
});
|
|
55
|
+
me.value = response?.data?.[0] || null;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("[Enfyra Auth] Fetch user error:", error);
|
|
58
|
+
me.value = null;
|
|
59
|
+
} finally {
|
|
60
|
+
isLoading.value = false;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
73
63
|
const isLoggedIn = computed(() => !!me.value);
|
|
74
64
|
return {
|
|
75
65
|
me,
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -89,8 +89,8 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
89
89
|
|
|
90
90
|
addImports([
|
|
91
91
|
{
|
|
92
|
-
name: "
|
|
93
|
-
from: resolve("./runtime/composables/
|
|
92
|
+
name: "useEnfyra",
|
|
93
|
+
from: resolve("./runtime/composables/useEnfyra"),
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
name: "useEnfyraAuth",
|
|
@@ -100,18 +100,13 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
100
100
|
addTypeTemplate({
|
|
101
101
|
filename: "types/enfyra-sdk.d.ts",
|
|
102
102
|
getContents: () => `
|
|
103
|
-
import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from '@enfyra/sdk-nuxt/types'
|
|
104
|
-
|
|
105
103
|
declare module '#imports' {
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
export interface UseEnfyraReturn {
|
|
105
|
+
baseUrl: string;
|
|
106
|
+
apiPrefix: string;
|
|
107
|
+
}
|
|
110
108
|
|
|
111
|
-
export function
|
|
112
|
-
path: (() => string) | string,
|
|
113
|
-
opts?: ApiOptions<T> & { ssr?: false | undefined }
|
|
114
|
-
): UseEnfyraApiClientReturn<T>
|
|
109
|
+
export function useEnfyra(): UseEnfyraReturn
|
|
115
110
|
|
|
116
111
|
export function useEnfyraAuth(): import('@enfyra/sdk-nuxt/types').UseEnfyraAuthReturn
|
|
117
112
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
import { getAppUrl, normalizeUrl } from "../utils/url";
|
|
3
|
+
import { ENFYRA_API_PREFIX } from "../constants/config";
|
|
4
|
+
|
|
5
|
+
export interface UseEnfyraReturn {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
apiPrefix: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useEnfyra(): UseEnfyraReturn {
|
|
11
|
+
const config = useRuntimeConfig().public.enfyraSDK;
|
|
12
|
+
const appUrl = getAppUrl();
|
|
13
|
+
const apiPrefix = config?.apiPrefix || ENFYRA_API_PREFIX;
|
|
14
|
+
const baseUrl = normalizeUrl(appUrl, apiPrefix);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
baseUrl,
|
|
18
|
+
apiPrefix,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -1,95 +1,82 @@
|
|
|
1
1
|
import { ref, computed } from "vue";
|
|
2
2
|
import type { LoginPayload, User, UseEnfyraAuthReturn } from "../../types/auth";
|
|
3
|
-
import {
|
|
3
|
+
import { $fetch } from "../utils/http";
|
|
4
|
+
import { useEnfyra } from "./useEnfyra";
|
|
4
5
|
|
|
5
6
|
const me = ref<User | null>(null);
|
|
6
7
|
const isLoading = ref<boolean>(false);
|
|
7
8
|
|
|
8
|
-
export function useEnfyraAuth() {
|
|
9
|
-
const {
|
|
10
|
-
data: loginData,
|
|
11
|
-
execute: executeLogin,
|
|
12
|
-
error: loginError,
|
|
13
|
-
} = useEnfyraApi("/login", {
|
|
14
|
-
method: "post",
|
|
15
|
-
errorContext: "Login",
|
|
16
|
-
});
|
|
9
|
+
export function useEnfyraAuth(): UseEnfyraAuthReturn {
|
|
10
|
+
const { baseUrl } = useEnfyra();
|
|
17
11
|
|
|
18
|
-
const
|
|
19
|
-
method: "post",
|
|
20
|
-
errorContext: "Logout",
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
data: meData,
|
|
25
|
-
execute: executeFetchUser,
|
|
26
|
-
error: fetchUserError,
|
|
27
|
-
} = useEnfyraApi("/me", {
|
|
28
|
-
errorContext: "Fetch User Profile",
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const fetchUser = async (options?: { fields?: string[] }) => {
|
|
12
|
+
const login = async (payload: LoginPayload) => {
|
|
32
13
|
isLoading.value = true;
|
|
33
14
|
|
|
34
15
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
queryParams.fields = options.fields.join(",");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
await executeFetchUser({
|
|
42
|
-
query: queryParams,
|
|
16
|
+
const response = await $fetch(`${baseUrl}/login`, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
body: payload,
|
|
43
19
|
});
|
|
44
20
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
me.value = (meData.value as any)?.data?.[0];
|
|
21
|
+
me.value = (response as any)?.data?.[0] || null;
|
|
22
|
+
return response;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("[Enfyra Auth] Login error:", error);
|
|
25
|
+
return null;
|
|
51
26
|
} finally {
|
|
52
27
|
isLoading.value = false;
|
|
53
28
|
}
|
|
54
29
|
};
|
|
55
30
|
|
|
56
|
-
const
|
|
31
|
+
const logout = async () => {
|
|
57
32
|
isLoading.value = true;
|
|
58
33
|
|
|
59
34
|
try {
|
|
60
|
-
await
|
|
35
|
+
await $fetch(`${baseUrl}/logout`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
});
|
|
38
|
+
me.value = null;
|
|
61
39
|
|
|
62
|
-
if (
|
|
63
|
-
|
|
40
|
+
if (typeof window !== "undefined") {
|
|
41
|
+
window.location.reload();
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error("[Enfyra Auth] Logout error:", error);
|
|
45
|
+
me.value = null;
|
|
46
|
+
if (typeof window !== "undefined") {
|
|
47
|
+
window.location.reload();
|
|
64
48
|
}
|
|
65
|
-
|
|
66
|
-
return loginData.value;
|
|
67
49
|
} finally {
|
|
68
50
|
isLoading.value = false;
|
|
69
51
|
}
|
|
70
52
|
};
|
|
71
53
|
|
|
72
|
-
const
|
|
54
|
+
const fetchUser = async (options?: { fields?: string[] }) => {
|
|
73
55
|
isLoading.value = true;
|
|
74
56
|
|
|
75
57
|
try {
|
|
76
|
-
|
|
77
|
-
me.value = null;
|
|
58
|
+
const queryParams: any = {};
|
|
78
59
|
|
|
79
|
-
if (
|
|
80
|
-
|
|
60
|
+
if (options?.fields && options.fields.length > 0) {
|
|
61
|
+
queryParams.fields = options.fields.join(",");
|
|
81
62
|
}
|
|
63
|
+
|
|
64
|
+
const response = await $fetch(`${baseUrl}/me`, {
|
|
65
|
+
method: "GET",
|
|
66
|
+
query: queryParams,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
me.value = (response as any)?.data?.[0] || null;
|
|
82
70
|
} catch (error) {
|
|
71
|
+
console.error("[Enfyra Auth] Fetch user error:", error);
|
|
83
72
|
me.value = null;
|
|
84
|
-
if (typeof window !== "undefined") {
|
|
85
|
-
window.location.reload();
|
|
86
|
-
}
|
|
87
73
|
} finally {
|
|
88
74
|
isLoading.value = false;
|
|
89
75
|
}
|
|
90
76
|
};
|
|
91
77
|
|
|
92
78
|
const isLoggedIn = computed(() => !!me.value);
|
|
79
|
+
|
|
93
80
|
return {
|
|
94
81
|
me,
|
|
95
82
|
login,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from "../../types";
|
|
2
|
-
export declare function useEnfyraApi<T = any>(path: (() => string) | string, opts: ApiOptions<T> & {
|
|
3
|
-
ssr: true;
|
|
4
|
-
}): UseEnfyraApiSSRReturn<T>;
|
|
5
|
-
export declare function useEnfyraApi<T = any>(path: (() => string) | string, opts?: ApiOptions<T> & {
|
|
6
|
-
ssr?: false | undefined;
|
|
7
|
-
}): UseEnfyraApiClientReturn<T>;
|
|
8
|
-
//# sourceMappingURL=useEnfyraApi.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEnfyraApi.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAGV,qBAAqB,EACrB,wBAAwB,EAEzB,MAAM,aAAa,CAAC;AA4BrB,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAClC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAE5B,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,GACjD,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
|