abckit 0.0.11 → 0.0.12
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.
|
@@ -2,11 +2,20 @@ import { navigateTo, useRuntimeConfig } from "#app";
|
|
|
2
2
|
import { adminClient } from "better-auth/client/plugins";
|
|
3
3
|
import { createAuthClient } from "better-auth/vue";
|
|
4
4
|
import { computed, watch } from "vue";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let authClient = null;
|
|
6
|
+
function getAuthClient() {
|
|
7
|
+
if (authClient) return authClient;
|
|
8
|
+
const config = useRuntimeConfig();
|
|
9
|
+
const baseURL = config.public.abckit?.auth?.baseURL;
|
|
10
|
+
authClient = createAuthClient({
|
|
11
|
+
baseURL,
|
|
12
|
+
plugins: [adminClient()]
|
|
13
|
+
});
|
|
14
|
+
return authClient;
|
|
15
|
+
}
|
|
8
16
|
export function useAuth() {
|
|
9
|
-
const
|
|
17
|
+
const client = getAuthClient();
|
|
18
|
+
const session = client.useSession();
|
|
10
19
|
const config = useRuntimeConfig();
|
|
11
20
|
const isLoading = computed(() => session.value.isPending);
|
|
12
21
|
const isAuthenticated = computed(() => !!session.value.data?.user);
|
|
@@ -30,11 +39,11 @@ export function useAuth() {
|
|
|
30
39
|
navigateTo(`/auth/register${query}`);
|
|
31
40
|
}
|
|
32
41
|
async function logout() {
|
|
33
|
-
await
|
|
42
|
+
await client.signOut();
|
|
34
43
|
navigateTo("/");
|
|
35
44
|
}
|
|
36
45
|
async function refreshSession() {
|
|
37
|
-
const result = await
|
|
46
|
+
const result = await client.getSession({ fetchOptions: { cache: "no-store" } });
|
|
38
47
|
return result;
|
|
39
48
|
}
|
|
40
49
|
return {
|
|
@@ -46,8 +55,17 @@ export function useAuth() {
|
|
|
46
55
|
register,
|
|
47
56
|
logout,
|
|
48
57
|
refreshSession,
|
|
49
|
-
authClient
|
|
58
|
+
authClient: client
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function getAuthClientExports() {
|
|
62
|
+
const client = getAuthClient();
|
|
63
|
+
return {
|
|
64
|
+
signIn: client.signIn,
|
|
65
|
+
signUp: client.signUp,
|
|
66
|
+
signOut: client.signOut,
|
|
67
|
+
useSession: client.useSession,
|
|
68
|
+
getSession: client.getSession,
|
|
69
|
+
authClient: client
|
|
50
70
|
};
|
|
51
71
|
}
|
|
52
|
-
export const { signIn, signUp, signOut, useSession, getSession } = authClient;
|
|
53
|
-
export { authClient };
|
package/dist/types.d.mts
CHANGED