gomtm 0.0.337 → 0.0.338
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/esm/providers/AuthProvider.d.ts +3 -0
- package/dist/esm/providers/AuthProvider.js +50 -4
- package/dist/esm/providers/GomtmAppSS.js +1 -8
- package/dist/esm/store/mtapp-store.d.ts +1 -0
- package/dist/esm/store/mtapp-store.js +3 -2
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
var __async = (__this, __arguments, generator) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
var fulfilled = (value) => {
|
|
5
|
+
try {
|
|
6
|
+
step(generator.next(value));
|
|
7
|
+
} catch (e) {
|
|
8
|
+
reject(e);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var rejected = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.throw(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
2
23
|
import { deleteCookie } from "mtxlib/clientlib";
|
|
3
24
|
import { useMtRouter } from "mtxuilib/hooks/use-router";
|
|
25
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
4
26
|
import { useCallback, useMemo } from "react";
|
|
5
27
|
import { CONST_COOKIE_MtM_TOKEN_NAME } from "../consts";
|
|
6
28
|
import { useGomtmSuspenseQuery } from "../gomtmQuery";
|
|
@@ -30,17 +52,40 @@ function useAuth() {
|
|
|
30
52
|
return (_a = userInfoQuery.data.userInfo) == null ? void 0 : _a.ID;
|
|
31
53
|
}, [userInfoQuery.data]);
|
|
32
54
|
return {
|
|
33
|
-
// auth,
|
|
34
55
|
userId
|
|
35
|
-
// isAdmin
|
|
36
56
|
};
|
|
37
57
|
}
|
|
38
58
|
function useLogout() {
|
|
39
59
|
const router = useMtRouter();
|
|
60
|
+
const queryClient = useQueryClient();
|
|
61
|
+
const setToken = useGomtm((x) => x.setToken);
|
|
40
62
|
return useCallback(() => {
|
|
41
63
|
deleteCookie(CONST_COOKIE_MtM_TOKEN_NAME);
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
setToken("");
|
|
65
|
+
queryClient.invalidateQueries();
|
|
66
|
+
router.refresh();
|
|
67
|
+
}, [setToken, queryClient, router]);
|
|
68
|
+
}
|
|
69
|
+
function useLogin() {
|
|
70
|
+
const searchParams = useSearchParams();
|
|
71
|
+
const router = useRouter();
|
|
72
|
+
const login = useCallback((values) => __async(this, null, function* () {
|
|
73
|
+
const res = yield fetch("/api.v1/auth/login", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
body: JSON.stringify(values)
|
|
76
|
+
});
|
|
77
|
+
const { success } = yield res.json();
|
|
78
|
+
if (success) {
|
|
79
|
+
const nextUrl = searchParams.get("next");
|
|
80
|
+
router.push(nextUrl != null ? nextUrl : "/");
|
|
81
|
+
router.refresh();
|
|
82
|
+
} else {
|
|
83
|
+
alert("Login failed");
|
|
84
|
+
}
|
|
85
|
+
}), [router, searchParams]);
|
|
86
|
+
return {
|
|
87
|
+
login
|
|
88
|
+
};
|
|
44
89
|
}
|
|
45
90
|
function useIsLogined() {
|
|
46
91
|
const userInfoQuery = useGomtmSuspenseQuery(userinfo.service.typeName, userinfo.name);
|
|
@@ -54,5 +99,6 @@ export {
|
|
|
54
99
|
isRoleMatch,
|
|
55
100
|
useAuth,
|
|
56
101
|
useIsLogined,
|
|
102
|
+
useLogin,
|
|
57
103
|
useLogout
|
|
58
104
|
};
|
|
@@ -61,14 +61,7 @@ function GomtmAppSS(props) {
|
|
|
61
61
|
token,
|
|
62
62
|
backendUrl: (cState == null ? void 0 : cState.backendUrl) || backend,
|
|
63
63
|
gomtmHost,
|
|
64
|
-
children: /* @__PURE__ */ jsx(
|
|
65
|
-
PrefetchConnectQuery,
|
|
66
|
-
{
|
|
67
|
-
svc: userinfo.service.typeName,
|
|
68
|
-
method: userinfo.name,
|
|
69
|
-
children
|
|
70
|
-
}
|
|
71
|
-
)
|
|
64
|
+
children: /* @__PURE__ */ jsx(PrefetchConnectQuery, { svc: userinfo.service.typeName, method: userinfo.name, children })
|
|
72
65
|
})
|
|
73
66
|
);
|
|
74
67
|
});
|
|
@@ -28,6 +28,7 @@ interface GomtmAppState extends GomtmAppProps {
|
|
|
28
28
|
setOpenDebug: (openDebug: boolean) => void;
|
|
29
29
|
setCacheEnabled: (cacheEnabled: boolean) => void;
|
|
30
30
|
logout: () => void;
|
|
31
|
+
setToken: (token: string) => void;
|
|
31
32
|
}
|
|
32
33
|
export declare const gomtmContext: import("react").Context<(Omit<import("zustand").StoreApi<GomtmAppState>, "persist"> & {
|
|
33
34
|
persist: {
|
|
@@ -32,6 +32,7 @@ var __objRest = (source, exclude) => {
|
|
|
32
32
|
};
|
|
33
33
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
34
34
|
import { createConnectTransport } from "@connectrpc/connect-web";
|
|
35
|
+
import { deleteCookie } from "mtxlib/clientlib";
|
|
35
36
|
import { MtButton } from "mtxuilib/ui/ui-mt/Button";
|
|
36
37
|
import { createContext, useContext, useMemo, useRef } from "react";
|
|
37
38
|
import { useHotkeys } from "react-hotkeys-hook";
|
|
@@ -45,7 +46,6 @@ import { anypbTypeReg } from "../messageTypeRegistry";
|
|
|
45
46
|
import { gomtmFetcher } from "../mtmFetcher";
|
|
46
47
|
import { MtReactQueryProvider } from "../providers/ReactQueryProvider";
|
|
47
48
|
import { customCookieStorage } from "./customStorage";
|
|
48
|
-
import { deleteCookie } from "mtxlib/clientlib";
|
|
49
49
|
const createGomtmAppStore = (initProps) => {
|
|
50
50
|
const DEFAULT_PROPS = {
|
|
51
51
|
debug: false,
|
|
@@ -65,7 +65,8 @@ const createGomtmAppStore = (initProps) => {
|
|
|
65
65
|
setOpenDebug: (openDebug) => set({ openDebug }),
|
|
66
66
|
logout: () => {
|
|
67
67
|
deleteCookie(CONST_COOKIE_MtM_TOKEN_NAME);
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
|
+
setToken: (token) => set({ token })
|
|
69
70
|
}),
|
|
70
71
|
{
|
|
71
72
|
name: CookieConfigState,
|