@mezo-org/passport 0.17.3-dev.1.no-ui → 0.17.3-dev.2.no-ui
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/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -1
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +23 -19
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +131 -1
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useGetSession.js +4 -2
- package/dist/src/hooks/useGetSession.js.map +1 -1
- package/dist/src/hooks/useSignOut.d.ts.map +1 -1
- package/dist/src/hooks/useSignOut.js +1 -0
- package/dist/src/hooks/useSignOut.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +30 -29
- package/src/hooks/useGetSession.ts +5 -2
- package/src/hooks/useSignOut.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEnsureNoSessionAndFetchNonce.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEnsureNoSessionAndFetchNonce.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEnsureNoSessionAndFetchNonce.d.ts","sourceRoot":"","sources":["../../../src/hooks/useEnsureNoSessionAndFetchNonce.ts"],"names":[],"mappings":"AAKA,iBAAS,+BAA+B;;EAwCvC;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAA"}
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
2
3
|
import { useGetSession } from "./useGetSession";
|
|
3
4
|
import { useSignOut } from "./useSignOut";
|
|
4
5
|
function useEnsureNoSessionAndFetchNonce() {
|
|
5
|
-
const { data: session,
|
|
6
|
+
const { data: session, queryKey: sessionQueryKey } = useGetSession(undefined, {
|
|
6
7
|
retry: false,
|
|
7
8
|
});
|
|
8
|
-
const { signOutAsync } = useSignOut(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (getSessionResult.error) {
|
|
13
|
-
throw new Error(`Sign in error: Failed to fetch the current session: ${getSessionResult.error}`);
|
|
14
|
-
}
|
|
15
|
-
if (!getSessionResult.data) {
|
|
16
|
-
throw new Error("Sign in error: Failed to fetch the current session; no data returned.");
|
|
17
|
-
}
|
|
18
|
-
return getSessionResult.data;
|
|
19
|
-
}, [getSession]);
|
|
9
|
+
const { signOutAsync } = useSignOut({
|
|
10
|
+
onSuccess: () => console.log("sign out success"),
|
|
11
|
+
});
|
|
12
|
+
const queryClient = useQueryClient();
|
|
20
13
|
const ensureNoSessionAndFetchNonce = useCallback(async () => {
|
|
21
14
|
if (!session || !("nonce" in session)) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
try {
|
|
16
|
+
console.log("signing out...");
|
|
17
|
+
// If there is active session we are terminating it
|
|
18
|
+
await signOutAsync();
|
|
19
|
+
console.log("signed out");
|
|
20
|
+
console.log("fetching session...");
|
|
21
|
+
// Because we signed out we can assume nonce will be returned here
|
|
22
|
+
const getSessionResult = await queryClient.fetchQuery({
|
|
23
|
+
queryKey: sessionQueryKey,
|
|
24
|
+
});
|
|
25
|
+
console.log("session fetched: ", getSessionResult);
|
|
26
|
+
return getSessionResult.nonce;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`Sign in error: Failed to ensure no session and fetch nonce: ${error}`);
|
|
30
|
+
}
|
|
27
31
|
}
|
|
28
32
|
return session.nonce;
|
|
29
|
-
}, [
|
|
33
|
+
}, [queryClient, session, sessionQueryKey, signOutAsync]);
|
|
30
34
|
return { ensureNoSessionAndFetchNonce };
|
|
31
35
|
}
|
|
32
36
|
export { useEnsureNoSessionAndFetchNonce };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEnsureNoSessionAndFetchNonce.js","sourceRoot":"","sources":["../../../src/hooks/useEnsureNoSessionAndFetchNonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,SAAS,+BAA+B;IACtC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useEnsureNoSessionAndFetchNonce.js","sourceRoot":"","sources":["../../../src/hooks/useEnsureNoSessionAndFetchNonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,SAAS,+BAA+B;IACtC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,aAAa,CAChE,SAAS,EACT;QACE,KAAK,EAAE,KAAK;KACb,CACF,CAAA;IACD,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC;QAClC,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;KACjD,CAAC,CAAA;IACF,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,MAAM,4BAA4B,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QAC1D,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;gBAC7B,mDAAmD;gBACnD,MAAM,YAAY,EAAE,CAAA;gBACpB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;gBACzB,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;gBAClC,kEAAkE;gBAClE,MAAM,gBAAgB,GAAG,MAAM,WAAW,CAAC,UAAU,CAElD;oBACD,QAAQ,EAAE,eAAe;iBAC1B,CAAC,CAAA;gBACF,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAA;gBAElD,OAAO,gBAAgB,CAAC,KAAK,CAAA;YAC/B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CACb,+DAA+D,KAAK,EAAE,CACvE,CAAA;YACH,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC,KAAK,CAAA;IACtB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC,CAAA;IAEzD,OAAO,EAAE,4BAA4B,EAAE,CAAA;AACzC,CAAC;AAED,OAAO,EAAE,+BAA+B,EAAE,CAAA"}
|
|
@@ -1,4 +1,134 @@
|
|
|
1
1
|
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
2
|
import type { GetSessionResponse } from "../api";
|
|
3
|
-
export declare function useGetSession(code?: string, queryOptions?: Omit<UseBaseQueryOptions<GetSessionResponse>, "queryKey" | "queryFn">):
|
|
3
|
+
export declare function useGetSession(code?: string, queryOptions?: Omit<UseBaseQueryOptions<GetSessionResponse>, "queryKey" | "queryFn">): {
|
|
4
|
+
queryKey: (string | undefined)[];
|
|
5
|
+
data: GetSessionResponse;
|
|
6
|
+
error: Error;
|
|
7
|
+
isError: true;
|
|
8
|
+
isPending: false;
|
|
9
|
+
isLoading: false;
|
|
10
|
+
isLoadingError: false;
|
|
11
|
+
isRefetchError: true;
|
|
12
|
+
isSuccess: false;
|
|
13
|
+
status: "error";
|
|
14
|
+
dataUpdatedAt: number;
|
|
15
|
+
errorUpdatedAt: number;
|
|
16
|
+
failureCount: number;
|
|
17
|
+
failureReason: Error | null;
|
|
18
|
+
errorUpdateCount: number;
|
|
19
|
+
isFetched: boolean;
|
|
20
|
+
isFetchedAfterMount: boolean;
|
|
21
|
+
isFetching: boolean;
|
|
22
|
+
isInitialLoading: boolean;
|
|
23
|
+
isPaused: boolean;
|
|
24
|
+
isPlaceholderData: boolean;
|
|
25
|
+
isRefetching: boolean;
|
|
26
|
+
isStale: boolean;
|
|
27
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<GetSessionResponse, Error>>;
|
|
28
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
29
|
+
} | {
|
|
30
|
+
queryKey: (string | undefined)[];
|
|
31
|
+
data: GetSessionResponse;
|
|
32
|
+
error: null;
|
|
33
|
+
isError: false;
|
|
34
|
+
isPending: false;
|
|
35
|
+
isLoading: false;
|
|
36
|
+
isLoadingError: false;
|
|
37
|
+
isRefetchError: false;
|
|
38
|
+
isSuccess: true;
|
|
39
|
+
status: "success";
|
|
40
|
+
dataUpdatedAt: number;
|
|
41
|
+
errorUpdatedAt: number;
|
|
42
|
+
failureCount: number;
|
|
43
|
+
failureReason: Error | null;
|
|
44
|
+
errorUpdateCount: number;
|
|
45
|
+
isFetched: boolean;
|
|
46
|
+
isFetchedAfterMount: boolean;
|
|
47
|
+
isFetching: boolean;
|
|
48
|
+
isInitialLoading: boolean;
|
|
49
|
+
isPaused: boolean;
|
|
50
|
+
isPlaceholderData: boolean;
|
|
51
|
+
isRefetching: boolean;
|
|
52
|
+
isStale: boolean;
|
|
53
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<GetSessionResponse, Error>>;
|
|
54
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
55
|
+
} | {
|
|
56
|
+
queryKey: (string | undefined)[];
|
|
57
|
+
data: undefined;
|
|
58
|
+
error: Error;
|
|
59
|
+
isError: true;
|
|
60
|
+
isPending: false;
|
|
61
|
+
isLoading: false;
|
|
62
|
+
isLoadingError: true;
|
|
63
|
+
isRefetchError: false;
|
|
64
|
+
isSuccess: false;
|
|
65
|
+
status: "error";
|
|
66
|
+
dataUpdatedAt: number;
|
|
67
|
+
errorUpdatedAt: number;
|
|
68
|
+
failureCount: number;
|
|
69
|
+
failureReason: Error | null;
|
|
70
|
+
errorUpdateCount: number;
|
|
71
|
+
isFetched: boolean;
|
|
72
|
+
isFetchedAfterMount: boolean;
|
|
73
|
+
isFetching: boolean;
|
|
74
|
+
isInitialLoading: boolean;
|
|
75
|
+
isPaused: boolean;
|
|
76
|
+
isPlaceholderData: boolean;
|
|
77
|
+
isRefetching: boolean;
|
|
78
|
+
isStale: boolean;
|
|
79
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<GetSessionResponse, Error>>;
|
|
80
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
81
|
+
} | {
|
|
82
|
+
queryKey: (string | undefined)[];
|
|
83
|
+
data: undefined;
|
|
84
|
+
error: null;
|
|
85
|
+
isError: false;
|
|
86
|
+
isPending: true;
|
|
87
|
+
isLoading: true;
|
|
88
|
+
isLoadingError: false;
|
|
89
|
+
isRefetchError: false;
|
|
90
|
+
isSuccess: false;
|
|
91
|
+
status: "pending";
|
|
92
|
+
dataUpdatedAt: number;
|
|
93
|
+
errorUpdatedAt: number;
|
|
94
|
+
failureCount: number;
|
|
95
|
+
failureReason: Error | null;
|
|
96
|
+
errorUpdateCount: number;
|
|
97
|
+
isFetched: boolean;
|
|
98
|
+
isFetchedAfterMount: boolean;
|
|
99
|
+
isFetching: boolean;
|
|
100
|
+
isInitialLoading: boolean;
|
|
101
|
+
isPaused: boolean;
|
|
102
|
+
isPlaceholderData: boolean;
|
|
103
|
+
isRefetching: boolean;
|
|
104
|
+
isStale: boolean;
|
|
105
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<GetSessionResponse, Error>>;
|
|
106
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
107
|
+
} | {
|
|
108
|
+
queryKey: (string | undefined)[];
|
|
109
|
+
data: undefined;
|
|
110
|
+
error: null;
|
|
111
|
+
isError: false;
|
|
112
|
+
isPending: true;
|
|
113
|
+
isLoadingError: false;
|
|
114
|
+
isRefetchError: false;
|
|
115
|
+
isSuccess: false;
|
|
116
|
+
status: "pending";
|
|
117
|
+
dataUpdatedAt: number;
|
|
118
|
+
errorUpdatedAt: number;
|
|
119
|
+
failureCount: number;
|
|
120
|
+
failureReason: Error | null;
|
|
121
|
+
errorUpdateCount: number;
|
|
122
|
+
isFetched: boolean;
|
|
123
|
+
isFetchedAfterMount: boolean;
|
|
124
|
+
isFetching: boolean;
|
|
125
|
+
isLoading: boolean;
|
|
126
|
+
isInitialLoading: boolean;
|
|
127
|
+
isPaused: boolean;
|
|
128
|
+
isPlaceholderData: boolean;
|
|
129
|
+
isRefetching: boolean;
|
|
130
|
+
isStale: boolean;
|
|
131
|
+
refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<GetSessionResponse, Error>>;
|
|
132
|
+
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
133
|
+
};
|
|
4
134
|
//# sourceMappingURL=useGetSession.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAEhD,wBAAgB,aAAa,CAC3B,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,kBAAkB,CAAC,EACvC,UAAU,GAAG,SAAS,CAClB
|
|
1
|
+
{"version":3,"file":"useGetSession.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAEhD,wBAAgB,aAAa,CAC3B,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,kBAAkB,CAAC,EACvC,UAAU,GAAG,SAAS,CAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAaP"}
|
|
@@ -3,13 +3,15 @@ import { useAuthApiClient } from "./useAuthApiClient";
|
|
|
3
3
|
import { QUERY_KEYS } from "./constants";
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time";
|
|
5
5
|
export function useGetSession(code, queryOptions = {}) {
|
|
6
|
+
const queryKey = [QUERY_KEYS.SESSION, code];
|
|
6
7
|
const authApiClient = useAuthApiClient();
|
|
7
|
-
|
|
8
|
-
queryKey
|
|
8
|
+
const query = useQuery({
|
|
9
|
+
queryKey,
|
|
9
10
|
queryFn: () => authApiClient.getSession(code),
|
|
10
11
|
staleTime: ONE_MINUTE_MS,
|
|
11
12
|
retry: 1,
|
|
12
13
|
...queryOptions,
|
|
13
14
|
});
|
|
15
|
+
return { ...query, queryKey };
|
|
14
16
|
}
|
|
15
17
|
//# sourceMappingURL=useGetSession.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetSession.js","sourceRoot":"","sources":["../../../src/hooks/useGetSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuB,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,MAAM,UAAU,aAAa,CAC3B,IAAa,EACb,eAGI,EAAE;IAEN,MAAM,
|
|
1
|
+
{"version":3,"file":"useGetSession.js","sourceRoot":"","sources":["../../../src/hooks/useGetSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuB,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,MAAM,UAAU,aAAa,CAC3B,IAAa,EACb,eAGI,EAAE;IAEN,MAAM,QAAQ,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3C,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,KAAK,GAAG,QAAQ,CAAC;QACrB,QAAQ;QACR,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC;QAC7C,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,CAAC;QACR,GAAG,YAAY;KAChB,CAAC,CAAA;IAEF,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAA;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGhB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAEnD,wBAAgB,UAAU,CACxB,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,qBAAqB,CAAC,EACtC,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGhB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAEnD,wBAAgB,UAAU,CACxB,eAAe,GAAE,IAAI,CACnB,eAAe,CAAC,qBAAqB,CAAC,EACtC,YAAY,GAAG,aAAa,CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBP"}
|
|
@@ -14,6 +14,7 @@ export function useSignOut(mutationOptions = {}) {
|
|
|
14
14
|
await queryClient.resetQueries({
|
|
15
15
|
queryKey: [QUERY_KEYS.ACCOUNT, QUERY_KEYS.CURRENT],
|
|
16
16
|
});
|
|
17
|
+
console.log("all queries resetted");
|
|
17
18
|
if (customOnSuccess)
|
|
18
19
|
customOnSuccess(data, variables, context);
|
|
19
20
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignOut.js","sourceRoot":"","sources":["../../../src/hooks/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,cAAc,GACf,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,UAAU,UAAU,CACxB,kBAGI,EAAE;IAEN,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,EAAE,GAAG,eAAe,CAAA;IAE9E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE;QAC/C,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YAC5C,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;YACnC,MAAM,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAClE,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAA;YAC3C,MAAM,WAAW,CAAC,YAAY,CAAC;gBAC7B,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;aACnD,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"useSignOut.js","sourceRoot":"","sources":["../../../src/hooks/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,cAAc,GACf,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,UAAU,UAAU,CACxB,kBAGI,EAAE;IAEN,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,EAAE,GAAG,eAAe,CAAA;IAE9E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE;QAC/C,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;YAC5C,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;YACnC,MAAM,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAClE,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAA;YAC3C,MAAM,WAAW,CAAC,YAAY,CAAC;gBAC7B,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC;aACnD,CAAC,CAAA;YACF,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;YAEnC,IAAI,eAAe;gBAAE,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;QAChE,CAAC;QACD,GAAG,mBAAmB;KACvB,CAAC,CAAA;IAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AAChE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
1
|
import { useCallback } from "react"
|
|
2
|
+
import { useQueryClient } from "@tanstack/react-query"
|
|
2
3
|
import { useGetSession } from "./useGetSession"
|
|
3
4
|
import { useSignOut } from "./useSignOut"
|
|
4
5
|
|
|
5
6
|
function useEnsureNoSessionAndFetchNonce() {
|
|
6
|
-
const { data: session,
|
|
7
|
-
|
|
7
|
+
const { data: session, queryKey: sessionQueryKey } = useGetSession(
|
|
8
|
+
undefined,
|
|
9
|
+
{
|
|
10
|
+
retry: false,
|
|
11
|
+
},
|
|
12
|
+
)
|
|
13
|
+
const { signOutAsync } = useSignOut({
|
|
14
|
+
onSuccess: () => console.log("sign out success"),
|
|
8
15
|
})
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const getAndValidateSession = useCallback(async () => {
|
|
12
|
-
const getSessionResult = await getSession()
|
|
13
|
-
|
|
14
|
-
// TODO: We should create a separate endpoint that will always return nonce
|
|
15
|
-
if (getSessionResult.error) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Sign in error: Failed to fetch the current session: ${getSessionResult.error}`,
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
if (!getSessionResult.data) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
"Sign in error: Failed to fetch the current session; no data returned.",
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return getSessionResult.data
|
|
27
|
-
}, [getSession])
|
|
16
|
+
const queryClient = useQueryClient()
|
|
28
17
|
|
|
29
18
|
const ensureNoSessionAndFetchNonce = useCallback(async () => {
|
|
30
19
|
if (!session || !("nonce" in session)) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
try {
|
|
21
|
+
console.log("signing out...")
|
|
22
|
+
// If there is active session we are terminating it
|
|
23
|
+
await signOutAsync()
|
|
24
|
+
console.log("signed out")
|
|
25
|
+
console.log("fetching session...")
|
|
26
|
+
// Because we signed out we can assume nonce will be returned here
|
|
27
|
+
const getSessionResult = await queryClient.fetchQuery<{
|
|
28
|
+
nonce: string
|
|
29
|
+
}>({
|
|
30
|
+
queryKey: sessionQueryKey,
|
|
31
|
+
})
|
|
32
|
+
console.log("session fetched: ", getSessionResult)
|
|
33
|
+
|
|
34
|
+
return getSessionResult.nonce
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Sign in error: Failed to ensure no session and fetch nonce: ${error}`,
|
|
38
|
+
)
|
|
36
39
|
}
|
|
37
|
-
|
|
38
|
-
return getSessionResult.nonce
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
return session.nonce
|
|
42
|
-
}, [
|
|
43
|
+
}, [queryClient, session, sessionQueryKey, signOutAsync])
|
|
43
44
|
|
|
44
45
|
return { ensureNoSessionAndFetchNonce }
|
|
45
46
|
}
|
|
@@ -11,12 +11,15 @@ export function useGetSession(
|
|
|
11
11
|
"queryKey" | "queryFn"
|
|
12
12
|
> = {},
|
|
13
13
|
) {
|
|
14
|
+
const queryKey = [QUERY_KEYS.SESSION, code]
|
|
14
15
|
const authApiClient = useAuthApiClient()
|
|
15
|
-
|
|
16
|
-
queryKey
|
|
16
|
+
const query = useQuery({
|
|
17
|
+
queryKey,
|
|
17
18
|
queryFn: () => authApiClient.getSession(code),
|
|
18
19
|
staleTime: ONE_MINUTE_MS,
|
|
19
20
|
retry: 1,
|
|
20
21
|
...queryOptions,
|
|
21
22
|
})
|
|
23
|
+
|
|
24
|
+
return { ...query, queryKey }
|
|
22
25
|
}
|
package/src/hooks/useSignOut.ts
CHANGED