gomtm 0.0.336 → 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.
@@ -4,3 +4,8 @@ export declare function PrefetchConnectInfiniteQuery(props: {
4
4
  method: string;
5
5
  input?: any;
6
6
  } & PropsWithChildren): Promise<import("react").JSX.Element>;
7
+ export declare function PrefetchConnectQuery(props: {
8
+ svc: string;
9
+ method: string;
10
+ input?: any;
11
+ } & PropsWithChildren): Promise<import("react").JSX.Element>;
@@ -36,7 +36,7 @@ var __async = (__this, __arguments, generator) => {
36
36
  };
37
37
  import { jsx } from "react/jsx-runtime";
38
38
  import { HydrationBoundary, QueryClient, dehydrate } from "@tanstack/react-query";
39
- import { createInfiniteQueryKey, goMtmQueryFn } from "../mtmFetcher";
39
+ import { createInfiniteQueryKey, createQueryKey, goMtmQueryFn } from "../mtmFetcher";
40
40
  function PrefetchConnectInfiniteQuery(props) {
41
41
  return __async(this, null, function* () {
42
42
  const { svc, method, input, children } = props;
@@ -54,6 +54,23 @@ function PrefetchConnectInfiniteQuery(props) {
54
54
  return /* @__PURE__ */ jsx(HydrationBoundary, { state: dehydratedState, children });
55
55
  });
56
56
  }
57
+ function PrefetchConnectQuery(props) {
58
+ return __async(this, null, function* () {
59
+ const { svc, method, input, children } = props;
60
+ const queryClient = new QueryClient();
61
+ const queryKey = createQueryKey(svc, method, input);
62
+ const data = yield goMtmQueryFn({ svc, method, input });
63
+ yield queryClient.prefetchQuery({
64
+ queryKey,
65
+ queryFn: (k) => __async(this, null, function* () {
66
+ return data;
67
+ })
68
+ });
69
+ const dehydratedState = dehydrate(queryClient);
70
+ return /* @__PURE__ */ jsx(HydrationBoundary, { state: dehydratedState, children });
71
+ });
72
+ }
57
73
  export {
58
- PrefetchConnectInfiniteQuery
74
+ PrefetchConnectInfiniteQuery,
75
+ PrefetchConnectQuery
59
76
  };
@@ -41,7 +41,7 @@ function MtListView(props) {
41
41
  svc: etc.svc,
42
42
  method: etc.methodList,
43
43
  input: etc.paramsList,
44
- children: /* @__PURE__ */ jsx(ListViewRender, { children })
44
+ children: /* @__PURE__ */ jsx(ListViewRender, {})
45
45
  }
46
46
  ) }));
47
47
  }
@@ -3,4 +3,7 @@ export declare function useAuth(): {
3
3
  userId: any;
4
4
  };
5
5
  export declare function useLogout(): () => void;
6
+ export declare function useLogin(): {
7
+ login: (values: any) => Promise<void>;
8
+ };
6
9
  export declare function useIsLogined(): boolean;
@@ -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
- router.push("/");
43
- }, [router]);
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
  };
@@ -39,7 +39,9 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
  import { jsx } from "react/jsx-runtime";
41
41
  import { cookies, headers } from "next/headers";
42
+ import { PrefetchConnectQuery } from "../components/SSR";
42
43
  import { CONST_COOKIE_MtM_TOKEN_NAME, CookieConfigState } from "../consts";
44
+ import { userinfo } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
43
45
  import { ssrGetBackendUrl } from "../mtmFetcher";
44
46
  import { GoMtmAppProvider } from "../store/mtapp-store";
45
47
  function GomtmAppSS(props) {
@@ -59,7 +61,7 @@ function GomtmAppSS(props) {
59
61
  token,
60
62
  backendUrl: (cState == null ? void 0 : cState.backendUrl) || backend,
61
63
  gomtmHost,
62
- children
64
+ children: /* @__PURE__ */ jsx(PrefetchConnectQuery, { svc: userinfo.service.typeName, method: userinfo.name, children })
63
65
  })
64
66
  );
65
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,