abckit 0.0.20 → 0.0.22
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.mjs +4 -3
- package/dist/runtime/composables/useAppRouter.d.ts +18 -0
- package/dist/runtime/composables/useAppRouter.js +46 -0
- package/dist/runtime/composables/useIsMobile.d.ts +5 -0
- package/dist/runtime/composables/useIsMobile.js +5 -0
- package/dist/runtime/middleware/auth.d.ts +6 -0
- package/dist/runtime/middleware/auth.js +15 -0
- package/dist/runtime/plugins/capacitor-client.js +1 -1
- package/package.json +2 -1
- package/dist/runtime/middleware/auth.global.d.ts +0 -8
- package/dist/runtime/middleware/auth.global.js +0 -28
package/dist/module.mjs
CHANGED
|
@@ -204,6 +204,8 @@ export {}
|
|
|
204
204
|
nuxt.options.alias["abckit/components"] = resolve("./runtime/components");
|
|
205
205
|
nuxt.options.alias["abckit/shadcn"] = resolve("./runtime/components/ui");
|
|
206
206
|
nuxt.options.alias["abckit/composables"] = resolve("./runtime/composables");
|
|
207
|
+
nuxt.options.alias["abckit/middleware"] = resolve("./runtime/middleware");
|
|
208
|
+
nuxt.options.alias["abckit/plugins"] = resolve("./runtime/plugins");
|
|
207
209
|
nuxt.options.alias["abckit/graphql"] = resolve("./runtime/graphql");
|
|
208
210
|
nuxt.options.alias["abckit/stores"] = resolve("./runtime/stores");
|
|
209
211
|
nuxt.options.alias["abckit/utils"] = resolve("./runtime/utils");
|
|
@@ -243,9 +245,8 @@ export {}
|
|
|
243
245
|
};
|
|
244
246
|
addServerScanDir(resolve("./runtime/server"));
|
|
245
247
|
addRouteMiddleware({
|
|
246
|
-
name: "auth
|
|
247
|
-
path: resolve("./runtime/middleware/auth
|
|
248
|
-
global: true
|
|
248
|
+
name: "auth",
|
|
249
|
+
path: resolve("./runtime/middleware/auth")
|
|
249
250
|
});
|
|
250
251
|
}
|
|
251
252
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UseIonRouterResult } from '@ionic/vue';
|
|
2
|
+
import type { RouteLocationRaw } from 'vue-router';
|
|
3
|
+
/**
|
|
4
|
+
* Register Ionic router for mobile navigation
|
|
5
|
+
* Call this in app.vue or a plugin: setIonRouter(useIonRouter())
|
|
6
|
+
*/
|
|
7
|
+
export declare function setIonRouter(router: UseIonRouterResult): void;
|
|
8
|
+
/**
|
|
9
|
+
* Platform-aware router composable
|
|
10
|
+
* Uses Ionic router on mobile (if registered), Nuxt router on web
|
|
11
|
+
*/
|
|
12
|
+
export declare function useAppRouter(): {
|
|
13
|
+
push: (to: RouteLocationRaw) => void;
|
|
14
|
+
replace: (to: RouteLocationRaw) => void;
|
|
15
|
+
back: () => void;
|
|
16
|
+
canGoBack: () => boolean;
|
|
17
|
+
isMobile: any;
|
|
18
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { navigateTo, useRouter, useRuntimeConfig } from "#app";
|
|
2
|
+
let _ionRouter = null;
|
|
3
|
+
export function setIonRouter(router) {
|
|
4
|
+
_ionRouter = router;
|
|
5
|
+
}
|
|
6
|
+
export function useAppRouter() {
|
|
7
|
+
const config = useRuntimeConfig();
|
|
8
|
+
const isMobile = config.public.abckit?.auth?.capacitor ?? false;
|
|
9
|
+
const vueRouter = useRouter();
|
|
10
|
+
function push(to) {
|
|
11
|
+
const path = typeof to === "string" ? to : to.path || "/";
|
|
12
|
+
if (isMobile && _ionRouter) {
|
|
13
|
+
_ionRouter.push(path);
|
|
14
|
+
} else {
|
|
15
|
+
navigateTo(to);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function replace(to) {
|
|
19
|
+
const path = typeof to === "string" ? to : to.path || "/";
|
|
20
|
+
if (isMobile && _ionRouter) {
|
|
21
|
+
_ionRouter.navigate(path, "forward", "replace");
|
|
22
|
+
} else {
|
|
23
|
+
navigateTo(to, { replace: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function back() {
|
|
27
|
+
if (isMobile && _ionRouter) {
|
|
28
|
+
_ionRouter.back();
|
|
29
|
+
} else {
|
|
30
|
+
vueRouter.back();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function canGoBack() {
|
|
34
|
+
if (isMobile && _ionRouter) {
|
|
35
|
+
return _ionRouter.canGoBack();
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
push,
|
|
41
|
+
replace,
|
|
42
|
+
back,
|
|
43
|
+
canGoBack,
|
|
44
|
+
isMobile
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineNuxtRouteMiddleware } from "#app";
|
|
2
|
+
import { useAppRouter } from "../composables/useAppRouter.js";
|
|
3
|
+
import { useAuth } from "../composables/useAuth.js";
|
|
4
|
+
export default defineNuxtRouteMiddleware((to) => {
|
|
5
|
+
if (import.meta.server)
|
|
6
|
+
return;
|
|
7
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
8
|
+
if (isLoading.value)
|
|
9
|
+
return;
|
|
10
|
+
if (!isAuthenticated.value) {
|
|
11
|
+
const { replace } = useAppRouter();
|
|
12
|
+
replace(`/auth/login?redirect=${encodeURIComponent(to.fullPath)}`);
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -250,7 +250,7 @@ export function capacitorClient(opts) {
|
|
|
250
250
|
const authToken = context.response.headers.get("set-auth-token");
|
|
251
251
|
if (authToken) {
|
|
252
252
|
const prevCookie = (await Preferences.get({ key: cookieName }))?.value;
|
|
253
|
-
const tokenCookie =
|
|
253
|
+
const tokenCookie = `${cookiePrefix}.session_token=${authToken}`;
|
|
254
254
|
const newCookie = mergeCookies(tokenCookie, prevCookie ?? void 0);
|
|
255
255
|
if (hasSessionCookieChanged(prevCookie ?? null, newCookie)) {
|
|
256
256
|
await Preferences.set({ key: cookieName, value: newCookie });
|
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.22",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"@capacitor/network": "^7.0.3",
|
|
62
62
|
"@capacitor/preferences": "^7.0.1",
|
|
63
63
|
"@graphql-tools/utils": "^10.11.0",
|
|
64
|
+
"@ionic/vue": "^8.7.13",
|
|
64
65
|
"@nuxt/icon": "^2.1.0",
|
|
65
66
|
"@nuxtjs/color-mode": "^4.0.0",
|
|
66
67
|
"@nuxtjs/i18n": "^10.2.1",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global auth middleware for Better Auth
|
|
3
|
-
* - Redirects pending approval users to /auth/pending
|
|
4
|
-
* - Redirects banned users to /auth/banned
|
|
5
|
-
* Note: Route protection is handled by layouts, not this middleware
|
|
6
|
-
*/
|
|
7
|
-
declare const _default: import("nuxt/app").RouteMiddleware;
|
|
8
|
-
export default _default;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { defineNuxtRouteMiddleware, navigateTo } from "#app";
|
|
2
|
-
import { useAuth } from "abckit/composables/useAuth";
|
|
3
|
-
export default defineNuxtRouteMiddleware(async (to) => {
|
|
4
|
-
if (import.meta.server) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const { isAuthenticated, isLoading, user } = useAuth();
|
|
8
|
-
if (to.path.startsWith("/auth/") && to.path !== "/auth/pending" && to.path !== "/auth/banned") {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (isLoading.value) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (isAuthenticated.value && user.value) {
|
|
15
|
-
const userData = user.value;
|
|
16
|
-
const isBanned = userData.banned === true;
|
|
17
|
-
const isPendingApproval = isBanned && userData.banReason === "pending approval";
|
|
18
|
-
if (isPendingApproval && to.path !== "/auth/pending") {
|
|
19
|
-
return navigateTo("/auth/pending");
|
|
20
|
-
}
|
|
21
|
-
if (isBanned && !isPendingApproval && to.path !== "/auth/banned") {
|
|
22
|
-
return navigateTo("/auth/banned");
|
|
23
|
-
}
|
|
24
|
-
if (!isBanned && (to.path === "/auth/pending" || to.path === "/auth/banned")) {
|
|
25
|
-
return navigateTo("/");
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|