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
- const authClient = createAuthClient({
6
- plugins: [adminClient()]
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 session = authClient.useSession();
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 authClient.signOut();
42
+ await client.signOut();
34
43
  navigateTo("/");
35
44
  }
36
45
  async function refreshSession() {
37
- const result = await authClient.getSession({ fetchOptions: { cache: "no-store" } });
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 };
@@ -4,5 +4,5 @@
4
4
  * - Redirects banned users to /auth/banned
5
5
  * Note: Route protection is handled by layouts, not this middleware
6
6
  */
7
- declare const _default: import("#app").RouteMiddleware;
7
+ declare const _default: import("nuxt/app").RouteMiddleware;
8
8
  export default _default;
package/dist/types.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default } from './module.mjs'
2
2
 
3
- export { type BreadcrumbsConfig, type ModuleOptions, type SetupConfig } from './module.mjs'
3
+ export { type AuthClientOptions, type BreadcrumbsConfig, type ModuleOptions, type SetupConfig } from './module.mjs'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "abckit",
3
3
  "type": "module",
4
- "version": "0.0.11",
4
+ "version": "0.0.12",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {