abckit 0.0.11 → 0.0.13

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,54 @@ 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
+ let Preferences = null;
7
+ async function getPreferences() {
8
+ if (!Preferences) {
9
+ const module = await import("@capacitor/preferences");
10
+ Preferences = module.Preferences;
11
+ }
12
+ return Preferences;
13
+ }
14
+ function getAuthClient() {
15
+ if (authClient)
16
+ return authClient;
17
+ const config = useRuntimeConfig();
18
+ const authConfig = config.public.abckit?.auth;
19
+ const baseURL = authConfig?.baseURL;
20
+ const basePath = authConfig?.basePath;
21
+ const capacitor = authConfig?.capacitor ?? false;
22
+ const clientOptions = {
23
+ baseURL,
24
+ basePath,
25
+ plugins: [adminClient()]
26
+ };
27
+ if (capacitor) {
28
+ clientOptions.fetchOptions = {
29
+ credentials: "include",
30
+ onSuccess: async (ctx) => {
31
+ const authToken = ctx.response.headers.get("set-auth-token");
32
+ if (authToken) {
33
+ const prefs = await getPreferences();
34
+ await prefs.set({ key: "auth_token", value: authToken });
35
+ }
36
+ },
37
+ auth: {
38
+ type: "Bearer",
39
+ token: async () => {
40
+ const prefs = await getPreferences();
41
+ const result = await prefs.get({ key: "auth_token" });
42
+ return result?.value || "";
43
+ }
44
+ }
45
+ };
46
+ }
47
+ authClient = createAuthClient(clientOptions);
48
+ return authClient;
49
+ }
8
50
  export function useAuth() {
9
- const session = authClient.useSession();
51
+ const client = getAuthClient();
52
+ const session = client.useSession();
10
53
  const config = useRuntimeConfig();
11
54
  const isLoading = computed(() => session.value.isPending);
12
55
  const isAuthenticated = computed(() => !!session.value.data?.user);
@@ -30,11 +73,15 @@ export function useAuth() {
30
73
  navigateTo(`/auth/register${query}`);
31
74
  }
32
75
  async function logout() {
33
- await authClient.signOut();
76
+ await client.signOut();
77
+ if (config.public.abckit?.auth?.capacitor) {
78
+ const prefs = await getPreferences();
79
+ await prefs.remove({ key: "auth_token" });
80
+ }
34
81
  navigateTo("/");
35
82
  }
36
83
  async function refreshSession() {
37
- const result = await authClient.getSession({ fetchOptions: { cache: "no-store" } });
84
+ const result = await client.getSession({ fetchOptions: { cache: "no-store" } });
38
85
  return result;
39
86
  }
40
87
  return {
@@ -46,8 +93,17 @@ export function useAuth() {
46
93
  register,
47
94
  logout,
48
95
  refreshSession,
49
- authClient
96
+ authClient: client
97
+ };
98
+ }
99
+ export function getAuthClientExports() {
100
+ const client = getAuthClient();
101
+ return {
102
+ signIn: client.signIn,
103
+ signUp: client.signUp,
104
+ signOut: client.signOut,
105
+ useSession: client.useSession,
106
+ getSession: client.getSession,
107
+ authClient: client
50
108
  };
51
109
  }
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.13",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -56,6 +56,7 @@
56
56
  "release": "pnpm publish --no-git-checks --access public"
57
57
  },
58
58
  "dependencies": {
59
+ "@capacitor/preferences": "^8.0.0",
59
60
  "@graphql-tools/utils": "^10.11.0",
60
61
  "@nuxt/icon": "^2.1.0",
61
62
  "@nuxtjs/color-mode": "^4.0.0",
@@ -118,9 +119,9 @@
118
119
  "@antfu/eslint-config": "^6.6.1",
119
120
  "@nuxt/eslint": "latest",
120
121
  "@nuxt/module-builder": "^1.0.2",
121
- "@types/node": "^24.10.3",
122
+ "@types/node": "^25.0.1",
122
123
  "@types/pg": "^8.16.0",
123
- "eslint": "^9.39.1",
124
+ "eslint": "^9.39.2",
124
125
  "h3": "^1.15.4",
125
126
  "nuxt": "^4.2.2",
126
127
  "typescript": "^5.9.3",