abckit 0.0.12 → 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.
- package/dist/module.d.mts +13 -0
- package/dist/module.mjs +3 -1
- package/dist/runtime/composables/useAuth.js +42 -4
- package/package.json +4 -3
package/dist/module.d.mts
CHANGED
|
@@ -34,6 +34,17 @@ interface AuthClientOptions {
|
|
|
34
34
|
* @example 'https://api.example.com'
|
|
35
35
|
*/
|
|
36
36
|
baseURL?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Base path for Better Auth API endpoints
|
|
39
|
+
* @default '/api/auth'
|
|
40
|
+
*/
|
|
41
|
+
basePath?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Enable Capacitor mode for mobile apps
|
|
44
|
+
* When enabled, uses Bearer token auth with @capacitor/preferences storage
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
capacitor?: boolean;
|
|
37
48
|
}
|
|
38
49
|
interface ModuleOptions {
|
|
39
50
|
/**
|
|
@@ -91,6 +102,8 @@ declare module 'nuxt/schema' {
|
|
|
91
102
|
sentry: boolean;
|
|
92
103
|
auth: {
|
|
93
104
|
baseURL?: string;
|
|
105
|
+
basePath?: string;
|
|
106
|
+
capacitor?: boolean;
|
|
94
107
|
};
|
|
95
108
|
};
|
|
96
109
|
}
|
package/dist/module.mjs
CHANGED
|
@@ -30,7 +30,9 @@ const module$1 = defineNuxtModule({
|
|
|
30
30
|
nuxt.options.runtimeConfig.public.abckit = {
|
|
31
31
|
sentry: nuxt.options.runtimeConfig.public.abckit?.sentry ?? options.sentry ?? false,
|
|
32
32
|
auth: {
|
|
33
|
-
baseURL: nuxt.options.runtimeConfig.public.abckit?.auth?.baseURL ?? options.auth?.baseURL
|
|
33
|
+
baseURL: nuxt.options.runtimeConfig.public.abckit?.auth?.baseURL ?? options.auth?.baseURL,
|
|
34
|
+
basePath: nuxt.options.runtimeConfig.public.abckit?.auth?.basePath ?? options.auth?.basePath,
|
|
35
|
+
capacitor: nuxt.options.runtimeConfig.public.abckit?.auth?.capacitor ?? options.auth?.capacitor ?? false
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
nuxt.options.runtimeConfig.dragonfly = defu(nuxt.options.runtimeConfig.dragonfly, {
|
|
@@ -3,14 +3,48 @@ import { adminClient } from "better-auth/client/plugins";
|
|
|
3
3
|
import { createAuthClient } from "better-auth/vue";
|
|
4
4
|
import { computed, watch } from "vue";
|
|
5
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
|
+
}
|
|
6
14
|
function getAuthClient() {
|
|
7
|
-
if (authClient)
|
|
15
|
+
if (authClient)
|
|
16
|
+
return authClient;
|
|
8
17
|
const config = useRuntimeConfig();
|
|
9
|
-
const
|
|
10
|
-
|
|
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 = {
|
|
11
23
|
baseURL,
|
|
24
|
+
basePath,
|
|
12
25
|
plugins: [adminClient()]
|
|
13
|
-
}
|
|
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);
|
|
14
48
|
return authClient;
|
|
15
49
|
}
|
|
16
50
|
export function useAuth() {
|
|
@@ -40,6 +74,10 @@ export function useAuth() {
|
|
|
40
74
|
}
|
|
41
75
|
async function logout() {
|
|
42
76
|
await client.signOut();
|
|
77
|
+
if (config.public.abckit?.auth?.capacitor) {
|
|
78
|
+
const prefs = await getPreferences();
|
|
79
|
+
await prefs.remove({ key: "auth_token" });
|
|
80
|
+
}
|
|
43
81
|
navigateTo("/");
|
|
44
82
|
}
|
|
45
83
|
async function refreshSession() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abckit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
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": "^
|
|
122
|
+
"@types/node": "^25.0.1",
|
|
122
123
|
"@types/pg": "^8.16.0",
|
|
123
|
-
"eslint": "^9.39.
|
|
124
|
+
"eslint": "^9.39.2",
|
|
124
125
|
"h3": "^1.15.4",
|
|
125
126
|
"nuxt": "^4.2.2",
|
|
126
127
|
"typescript": "^5.9.3",
|