abckit 0.0.13 → 0.0.15
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 +0 -7
- package/dist/module.mjs +1 -2
- package/dist/runtime/composables/useAuth.js +13 -23
- package/package.json +3 -2
package/dist/module.d.mts
CHANGED
|
@@ -39,12 +39,6 @@ interface AuthClientOptions {
|
|
|
39
39
|
* @default '/api/auth'
|
|
40
40
|
*/
|
|
41
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;
|
|
48
42
|
}
|
|
49
43
|
interface ModuleOptions {
|
|
50
44
|
/**
|
|
@@ -103,7 +97,6 @@ declare module 'nuxt/schema' {
|
|
|
103
97
|
auth: {
|
|
104
98
|
baseURL?: string;
|
|
105
99
|
basePath?: string;
|
|
106
|
-
capacitor?: boolean;
|
|
107
100
|
};
|
|
108
101
|
};
|
|
109
102
|
}
|
package/dist/module.mjs
CHANGED
|
@@ -31,8 +31,7 @@ const module$1 = defineNuxtModule({
|
|
|
31
31
|
sentry: nuxt.options.runtimeConfig.public.abckit?.sentry ?? options.sentry ?? false,
|
|
32
32
|
auth: {
|
|
33
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
|
+
basePath: nuxt.options.runtimeConfig.public.abckit?.auth?.basePath ?? options.auth?.basePath
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
37
|
nuxt.options.runtimeConfig.dragonfly = defu(nuxt.options.runtimeConfig.dragonfly, {
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { navigateTo, useRuntimeConfig } from "#app";
|
|
2
|
+
import { Capacitor } from "@capacitor/core";
|
|
3
|
+
import { Preferences } from "@capacitor/preferences";
|
|
2
4
|
import { adminClient } from "better-auth/client/plugins";
|
|
3
5
|
import { createAuthClient } from "better-auth/vue";
|
|
4
6
|
import { computed, watch } from "vue";
|
|
5
7
|
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
8
|
function getAuthClient() {
|
|
15
9
|
if (authClient)
|
|
16
10
|
return authClient;
|
|
@@ -18,32 +12,29 @@ function getAuthClient() {
|
|
|
18
12
|
const authConfig = config.public.abckit?.auth;
|
|
19
13
|
const baseURL = authConfig?.baseURL;
|
|
20
14
|
const basePath = authConfig?.basePath;
|
|
21
|
-
const capacitor = authConfig?.capacitor ?? false;
|
|
22
15
|
const clientOptions = {
|
|
23
16
|
baseURL,
|
|
24
17
|
basePath,
|
|
25
|
-
plugins: [adminClient()]
|
|
26
|
-
|
|
27
|
-
if (capacitor) {
|
|
28
|
-
clientOptions.fetchOptions = {
|
|
18
|
+
plugins: [adminClient()],
|
|
19
|
+
fetchOptions: {
|
|
29
20
|
credentials: "include",
|
|
30
21
|
onSuccess: async (ctx) => {
|
|
31
22
|
const authToken = ctx.response.headers.get("set-auth-token");
|
|
32
|
-
if (authToken) {
|
|
33
|
-
|
|
34
|
-
await prefs.set({ key: "auth_token", value: authToken });
|
|
23
|
+
if (authToken && Capacitor.isNativePlatform()) {
|
|
24
|
+
await Preferences.set({ key: "auth_token", value: authToken });
|
|
35
25
|
}
|
|
36
26
|
},
|
|
37
27
|
auth: {
|
|
38
28
|
type: "Bearer",
|
|
39
29
|
token: async () => {
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
if (!Capacitor.isNativePlatform())
|
|
31
|
+
return "";
|
|
32
|
+
const result = await Preferences.get({ key: "auth_token" });
|
|
42
33
|
return result?.value || "";
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
47
38
|
authClient = createAuthClient(clientOptions);
|
|
48
39
|
return authClient;
|
|
49
40
|
}
|
|
@@ -74,9 +65,8 @@ export function useAuth() {
|
|
|
74
65
|
}
|
|
75
66
|
async function logout() {
|
|
76
67
|
await client.signOut();
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
await prefs.remove({ key: "auth_token" });
|
|
68
|
+
if (Capacitor.isNativePlatform()) {
|
|
69
|
+
await Preferences.remove({ key: "auth_token" });
|
|
80
70
|
}
|
|
81
71
|
navigateTo("/");
|
|
82
72
|
}
|
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.15",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"release": "pnpm publish --no-git-checks --access public"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@capacitor/
|
|
59
|
+
"@capacitor/core": "^7.0.1",
|
|
60
|
+
"@capacitor/preferences": "^7.0.1",
|
|
60
61
|
"@graphql-tools/utils": "^10.11.0",
|
|
61
62
|
"@nuxt/icon": "^2.1.0",
|
|
62
63
|
"@nuxtjs/color-mode": "^4.0.0",
|