@multiplatform.one/keycloak 0.7.15 → 0.7.16
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/package.json +26 -26
- package/routes/index.d.ts +22 -0
- package/routes/index.js +22 -0
- package/src/Authenticated.tsx +27 -17
- package/src/authConfig.ts +3 -9
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useTokensFromQuery/index.ts +1 -0
- package/src/hooks/useTokensFromState.ts +1 -1
- package/src/index.ts +3 -0
- package/src/{@types/coreJsPure.d.ts → keycloak/context.ts} +6 -11
- package/{lib/@types/expoKeycloakAuth.d.d.mts → src/keycloak/index.ts} +4 -7
- package/src/keycloak/keycloak.native.ts +148 -0
- package/src/keycloak/keycloak.ts +175 -0
- package/src/provider/AfterAuth.tsx +63 -0
- package/src/provider/{keycloakProvider.native.tsx → AuthProvider/AuthProvider.native.tsx} +8 -16
- package/src/provider/{keycloakProvider.tsx → AuthProvider/AuthProvider.tsx} +81 -94
- package/{lib/@types/expoKeycloakAuth.d.d.ts → src/provider/AuthProvider/index.ts} +4 -7
- package/src/provider/KeycloakProvider.tsx +53 -0
- package/src/{hooks/useCurrentRouteName/index.native.ts → provider/index.ts} +6 -11
- package/src/routes.ts +163 -0
- package/src/session/index.ts +22 -0
- package/src/session/session.native.ts +31 -0
- package/src/session/session.ts +68 -0
- package/src/{state/index.ts → state.ts} +5 -4
- package/src/{util.ts → token.ts} +25 -11
- package/src/types.ts +4 -1
- package/lib/@types/coreJsPure.d.d.mts +0 -2
- package/lib/@types/coreJsPure.d.d.ts +0 -2
- package/lib/@types/coreJsPure.d.js +0 -1
- package/lib/@types/coreJsPure.d.mjs +0 -0
- package/lib/@types/expoKeycloakAuth.d.js +0 -1
- package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
- package/lib/Authenticated.d.mts +0 -33
- package/lib/Authenticated.d.ts +0 -33
- package/lib/Authenticated.js +0 -19
- package/lib/Authenticated.mjs +0 -20
- package/lib/authConfig.d.mts +0 -14
- package/lib/authConfig.d.ts +0 -14
- package/lib/authConfig.js +0 -8
- package/lib/authConfig.mjs +0 -9
- package/lib/chunk-2GUOEPFY.mjs +0 -0
- package/lib/chunk-3ZPHNEJL.js +0 -11
- package/lib/chunk-64PPU7Q3.mjs +0 -13
- package/lib/chunk-6NDWOV55.js +0 -1
- package/lib/chunk-7MTPH6XK.mjs +0 -26
- package/lib/chunk-A7UBOIAL.js +0 -13
- package/lib/chunk-AD6VPMID.mjs +0 -20
- package/lib/chunk-AUUZ6BI7.js +0 -78
- package/lib/chunk-AYKQVWMR.mjs +0 -0
- package/lib/chunk-BVB33X7V.mjs +0 -265
- package/lib/chunk-C2FNSVJO.js +0 -17
- package/lib/chunk-J4CCMILN.mjs +0 -41
- package/lib/chunk-K33RKJZX.js +0 -443
- package/lib/chunk-KLLABHIC.js +0 -13
- package/lib/chunk-L5HMOY4M.mjs +0 -18
- package/lib/chunk-MZ6E62HK.js +0 -33
- package/lib/chunk-NWRANDZ6.js +0 -98
- package/lib/chunk-NXTVYIBR.mjs +0 -11
- package/lib/chunk-OYWAYMFN.js +0 -17
- package/lib/chunk-RPUOO7AV.mjs +0 -10
- package/lib/chunk-RYM7KERK.mjs +0 -52
- package/lib/chunk-UBVYEZI3.js +0 -1
- package/lib/chunk-UHTKOFS6.mjs +0 -84
- package/lib/chunk-UL6L5ONI.js +0 -460
- package/lib/chunk-UOKDJT5L.mjs +0 -16
- package/lib/chunk-W5DJLFTQ.js +0 -56
- package/lib/chunk-WT5W6BSZ.js +0 -161
- package/lib/chunk-XEO3YXBM.js +0 -22
- package/lib/chunk-XO4W2SMN.mjs +0 -50
- package/lib/chunk-XVPWAAZ4.mjs +0 -76
- package/lib/chunk-Y4XMF3R6.mjs +0 -13
- package/lib/chunk-YGNNHTFE.js +0 -12
- package/lib/hooks/index.d.mts +0 -9
- package/lib/hooks/index.d.ts +0 -9
- package/lib/hooks/index.js +0 -23
- package/lib/hooks/index.mjs +0 -34
- package/lib/hooks/useAuthConfig.d.mts +0 -6
- package/lib/hooks/useAuthConfig.d.ts +0 -6
- package/lib/hooks/useAuthConfig.js +0 -8
- package/lib/hooks/useAuthConfig.mjs +0 -8
- package/lib/hooks/useCurrentRouteName/index.d.mts +0 -3
- package/lib/hooks/useCurrentRouteName/index.d.ts +0 -3
- package/lib/hooks/useCurrentRouteName/index.js +0 -7
- package/lib/hooks/useCurrentRouteName/index.mjs +0 -7
- package/lib/hooks/useCurrentRouteName/index.native.d.mts +0 -3
- package/lib/hooks/useCurrentRouteName/index.native.d.ts +0 -3
- package/lib/hooks/useCurrentRouteName/index.native.js +0 -14
- package/lib/hooks/useCurrentRouteName/index.native.mjs +0 -14
- package/lib/hooks/useKeycloak/index.d.mts +0 -46
- package/lib/hooks/useKeycloak/index.d.ts +0 -46
- package/lib/hooks/useKeycloak/index.js +0 -11
- package/lib/hooks/useKeycloak/index.mjs +0 -12
- package/lib/hooks/useKeycloak/useKeycloak.d.mts +0 -2
- package/lib/hooks/useKeycloak/useKeycloak.d.ts +0 -2
- package/lib/hooks/useKeycloak/useKeycloak.js +0 -10
- package/lib/hooks/useKeycloak/useKeycloak.mjs +0 -11
- package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +0 -20
- package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +0 -20
- package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -80
- package/lib/hooks/useKeycloak/useKeycloak.native.mjs +0 -69
- package/lib/hooks/useLogin.d.mts +0 -3
- package/lib/hooks/useLogin.d.ts +0 -3
- package/lib/hooks/useLogin.js +0 -11
- package/lib/hooks/useLogin.mjs +0 -11
- package/lib/hooks/useTokensFromQuery/index.d.mts +0 -3
- package/lib/hooks/useTokensFromQuery/index.d.ts +0 -3
- package/lib/hooks/useTokensFromQuery/index.js +0 -7
- package/lib/hooks/useTokensFromQuery/index.mjs +0 -7
- package/lib/hooks/useTokensFromQuery/index.native.d.mts +0 -3
- package/lib/hooks/useTokensFromQuery/index.native.d.ts +0 -3
- package/lib/hooks/useTokensFromQuery/index.native.js +0 -10
- package/lib/hooks/useTokensFromQuery/index.native.mjs +0 -7
- package/lib/hooks/useTokensFromState.d.mts +0 -3
- package/lib/hooks/useTokensFromState.d.ts +0 -3
- package/lib/hooks/useTokensFromState.js +0 -9
- package/lib/hooks/useTokensFromState.mjs +0 -9
- package/lib/index.d.mts +0 -13
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -34
- package/lib/index.mjs +0 -56
- package/lib/provider/afterAuth.d.mts +0 -29
- package/lib/provider/afterAuth.d.ts +0 -29
- package/lib/provider/afterAuth.js +0 -18
- package/lib/provider/afterAuth.mjs +0 -18
- package/lib/provider/index.d.mts +0 -39
- package/lib/provider/index.d.ts +0 -39
- package/lib/provider/index.js +0 -22
- package/lib/provider/index.mjs +0 -25
- package/lib/provider/keycloakProvider.d.mts +0 -42
- package/lib/provider/keycloakProvider.d.ts +0 -42
- package/lib/provider/keycloakProvider.js +0 -20
- package/lib/provider/keycloakProvider.mjs +0 -21
- package/lib/provider/keycloakProvider.native.d.mts +0 -29
- package/lib/provider/keycloakProvider.native.d.ts +0 -29
- package/lib/provider/keycloakProvider.native.js +0 -87
- package/lib/provider/keycloakProvider.native.mjs +0 -30
- package/lib/state/index.d.mts +0 -11
- package/lib/state/index.d.ts +0 -11
- package/lib/state/index.js +0 -7
- package/lib/state/index.mjs +0 -7
- package/lib/types.d.mts +0 -17
- package/lib/types.d.ts +0 -17
- package/lib/types.js +0 -8
- package/lib/types.mjs +0 -7
- package/lib/util.d.mts +0 -4
- package/lib/util.d.ts +0 -4
- package/lib/util.js +0 -8
- package/lib/util.mjs +0 -9
- package/src/hooks/useCurrentRouteName/index.ts +0 -34
- package/src/hooks/useKeycloak/index.ts +0 -47
- package/src/hooks/useKeycloak/useKeycloak.native.ts +0 -95
- package/src/hooks/useKeycloak/useKeycloak.ts +0 -106
- package/src/hooks/useLogin.ts +0 -47
- package/src/provider/afterAuth.tsx +0 -65
- package/src/provider/index.tsx +0 -117
package/lib/chunk-BVB33X7V.mjs
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AfterAuth
|
|
3
|
-
} from "./chunk-XO4W2SMN.mjs";
|
|
4
|
-
import {
|
|
5
|
-
useAuthConfig
|
|
6
|
-
} from "./chunk-Y4XMF3R6.mjs";
|
|
7
|
-
import {
|
|
8
|
-
useAuthState
|
|
9
|
-
} from "./chunk-AD6VPMID.mjs";
|
|
10
|
-
import {
|
|
11
|
-
validToken
|
|
12
|
-
} from "./chunk-7MTPH6XK.mjs";
|
|
13
|
-
|
|
14
|
-
// src/provider/keycloakProvider.tsx
|
|
15
|
-
import Keycloak from "@bitspur/keycloak-js";
|
|
16
|
-
import React, { useMemo, useEffect, useState, useCallback } from "react";
|
|
17
|
-
import { MultiPlatform } from "multiplatform.one";
|
|
18
|
-
import { ReactKeycloakProvider } from "@bitspur/react-keycloak-web";
|
|
19
|
-
import { SSRKeycloakProvider, SSRCookies } from "@bitspur/react-keycloak-ssr";
|
|
20
|
-
import { useRouter } from "next/router";
|
|
21
|
-
var logger = console;
|
|
22
|
-
function KeycloakProvider({
|
|
23
|
-
children,
|
|
24
|
-
cookies,
|
|
25
|
-
keycloakConfig,
|
|
26
|
-
keycloakInitOptions,
|
|
27
|
-
loadingComponent,
|
|
28
|
-
onEvent,
|
|
29
|
-
onTokens
|
|
30
|
-
}) {
|
|
31
|
-
const { debug, ensureFreshness, persist, messageHandlerKeys, ssr } = useAuthConfig();
|
|
32
|
-
const authState = useAuthState();
|
|
33
|
-
const LoadingComponent = loadingComponent || (() => /* @__PURE__ */ React.createElement(React.Fragment, null, debug ? "authenticating" : null));
|
|
34
|
-
const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
|
|
35
|
-
const [refreshToken, setRefreshToken] = useState(
|
|
36
|
-
validToken(
|
|
37
|
-
ensureFreshness && ("refreshToken" in query && (query.refreshToken?.toString() || true) || persist && authState.refreshToken) || false
|
|
38
|
-
)
|
|
39
|
-
);
|
|
40
|
-
const [idToken, setIdToken] = useState(
|
|
41
|
-
validToken(
|
|
42
|
-
"idToken" in query && (query.idToken?.toString() || true) || persist && authState.idToken || false,
|
|
43
|
-
refreshToken
|
|
44
|
-
)
|
|
45
|
-
);
|
|
46
|
-
const [token, setToken] = useState(
|
|
47
|
-
validToken(
|
|
48
|
-
"token" in query && (query.token?.toString() || true) || persist && authState.token || false,
|
|
49
|
-
refreshToken
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (token !== true && refreshToken !== true && idToken !== true)
|
|
54
|
-
return;
|
|
55
|
-
if (debug)
|
|
56
|
-
logger.debug("post message", JSON.stringify({ type: "LOADED" }));
|
|
57
|
-
(messageHandlerKeys || []).forEach((key) => {
|
|
58
|
-
window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
59
|
-
});
|
|
60
|
-
window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
61
|
-
window?.parent?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
62
|
-
}, []);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (refreshToken !== true)
|
|
65
|
-
return;
|
|
66
|
-
const messageCallback = (e) => {
|
|
67
|
-
let data = e?.data || null;
|
|
68
|
-
if (typeof data === "string") {
|
|
69
|
-
try {
|
|
70
|
-
data = JSON.parse(data);
|
|
71
|
-
} catch (err) {
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (debug)
|
|
75
|
-
logger.debug("received message", JSON.stringify(data));
|
|
76
|
-
const message = data;
|
|
77
|
-
if (!message.type)
|
|
78
|
-
return;
|
|
79
|
-
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
80
|
-
if (debug)
|
|
81
|
-
logger.debug("setting refresh token", message.payload);
|
|
82
|
-
setRefreshToken(validToken(message.payload));
|
|
83
|
-
window.removeEventListener("message", messageCallback);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
if (debug) {
|
|
87
|
-
logger.debug(
|
|
88
|
-
"listening for message",
|
|
89
|
-
JSON.stringify({
|
|
90
|
-
type: "REFRESH_TOKEN",
|
|
91
|
-
payload: "<some_refresh_token>"
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
window.addEventListener("message", messageCallback);
|
|
96
|
-
return () => {
|
|
97
|
-
window.removeEventListener("message", messageCallback);
|
|
98
|
-
};
|
|
99
|
-
}, []);
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (token !== true)
|
|
102
|
-
return;
|
|
103
|
-
const messageCallback = (e) => {
|
|
104
|
-
let data = e?.data || null;
|
|
105
|
-
if (typeof data === "string") {
|
|
106
|
-
try {
|
|
107
|
-
data = JSON.parse(data);
|
|
108
|
-
} catch (err) {
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (debug)
|
|
112
|
-
logger.debug("received message", JSON.stringify(data));
|
|
113
|
-
const message = data;
|
|
114
|
-
if (!message.type)
|
|
115
|
-
return;
|
|
116
|
-
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
117
|
-
if (debug)
|
|
118
|
-
logger.debug("setting token", message.payload);
|
|
119
|
-
setToken(validToken(message.payload, refreshToken));
|
|
120
|
-
window.removeEventListener("message", messageCallback);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
if (debug) {
|
|
124
|
-
logger.debug(
|
|
125
|
-
"listening for message",
|
|
126
|
-
JSON.stringify({
|
|
127
|
-
type: "TOKEN",
|
|
128
|
-
payload: "<some_token>"
|
|
129
|
-
})
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
window.addEventListener("message", messageCallback);
|
|
133
|
-
return () => {
|
|
134
|
-
window.removeEventListener("message", messageCallback);
|
|
135
|
-
};
|
|
136
|
-
}, []);
|
|
137
|
-
useEffect(() => {
|
|
138
|
-
if (idToken !== true)
|
|
139
|
-
return;
|
|
140
|
-
const messageCallback = (e) => {
|
|
141
|
-
let data = e?.data || null;
|
|
142
|
-
if (typeof data === "string") {
|
|
143
|
-
try {
|
|
144
|
-
data = JSON.parse(data);
|
|
145
|
-
} catch (err) {
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (debug)
|
|
149
|
-
logger.debug("received message", JSON.stringify(data));
|
|
150
|
-
const message = data;
|
|
151
|
-
if (!message.type)
|
|
152
|
-
return;
|
|
153
|
-
if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
|
|
154
|
-
if (debug)
|
|
155
|
-
logger.debug("setting id token", message.payload);
|
|
156
|
-
setIdToken(validToken(message.payload, refreshToken));
|
|
157
|
-
window.removeEventListener("message", messageCallback);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
if (debug) {
|
|
161
|
-
logger.debug(
|
|
162
|
-
"listening for message",
|
|
163
|
-
JSON.stringify({
|
|
164
|
-
type: "ID_TOKEN",
|
|
165
|
-
payload: "<some_id_token>"
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
window.addEventListener("message", messageCallback);
|
|
170
|
-
return () => {
|
|
171
|
-
window.removeEventListener("message", messageCallback);
|
|
172
|
-
};
|
|
173
|
-
}, []);
|
|
174
|
-
const handleEvent = useCallback((eventType, error) => {
|
|
175
|
-
if (error) {
|
|
176
|
-
if (typeof error === "string")
|
|
177
|
-
throw new Error(error);
|
|
178
|
-
const err = new Error(error.error);
|
|
179
|
-
err.errorDescription = error.error_description;
|
|
180
|
-
throw err;
|
|
181
|
-
}
|
|
182
|
-
if (onEvent)
|
|
183
|
-
onEvent(eventType, error);
|
|
184
|
-
}, []);
|
|
185
|
-
const keycloak = useMemo(
|
|
186
|
-
() => typeof window !== "undefined" && new Keycloak({
|
|
187
|
-
url: keycloakConfig.url,
|
|
188
|
-
realm: keycloakConfig.realm,
|
|
189
|
-
clientId: keycloakConfig.clientId
|
|
190
|
-
}),
|
|
191
|
-
[keycloakInitOptions, token, refreshToken, idToken]
|
|
192
|
-
);
|
|
193
|
-
const initOptions = useMemo(() => {
|
|
194
|
-
const initOptions2 = {
|
|
195
|
-
...defaultKeycloakInitOptions,
|
|
196
|
-
...keycloakInitOptions
|
|
197
|
-
};
|
|
198
|
-
if (debug)
|
|
199
|
-
initOptions2.enableLogging = true;
|
|
200
|
-
if (token && typeof token === "string") {
|
|
201
|
-
initOptions2.token = token;
|
|
202
|
-
initOptions2.timeSkew = 0;
|
|
203
|
-
if (idToken && typeof idToken === "string")
|
|
204
|
-
initOptions2.idToken = idToken;
|
|
205
|
-
if (refreshToken && typeof refreshToken === "string")
|
|
206
|
-
initOptions2.refreshToken = refreshToken;
|
|
207
|
-
}
|
|
208
|
-
if (typeof window !== "undefined" && window.self !== window.top || token && !refreshToken) {
|
|
209
|
-
initOptions2.checkLoginIframe = false;
|
|
210
|
-
initOptions2.flow = "implicit";
|
|
211
|
-
initOptions2.onLoad = void 0;
|
|
212
|
-
}
|
|
213
|
-
return initOptions2;
|
|
214
|
-
}, [keycloakInitOptions, token, refreshToken, idToken]);
|
|
215
|
-
if (token === true || idToken === true || refreshToken === true)
|
|
216
|
-
return /* @__PURE__ */ React.createElement(LoadingComponent, null);
|
|
217
|
-
if (cookies && ssr) {
|
|
218
|
-
return (
|
|
219
|
-
// @ts-ignore
|
|
220
|
-
/* @__PURE__ */ React.createElement(
|
|
221
|
-
SSRKeycloakProvider,
|
|
222
|
-
{
|
|
223
|
-
LoadingComponent: /* @__PURE__ */ React.createElement(LoadingComponent, null),
|
|
224
|
-
autoRefreshToken: initOptions.checkLoginIframe,
|
|
225
|
-
initOptions,
|
|
226
|
-
onEvent: handleEvent,
|
|
227
|
-
onTokens,
|
|
228
|
-
persistor: SSRCookies(cookies),
|
|
229
|
-
keycloakConfig: {
|
|
230
|
-
clientId: keycloakConfig.clientId,
|
|
231
|
-
realm: keycloakConfig.realm,
|
|
232
|
-
url: keycloakConfig.url
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
/* @__PURE__ */ React.createElement(AfterAuth, null, children)
|
|
236
|
-
)
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
if (!keycloak)
|
|
240
|
-
return /* @__PURE__ */ React.createElement(LoadingComponent, null);
|
|
241
|
-
return /* @__PURE__ */ React.createElement(
|
|
242
|
-
ReactKeycloakProvider,
|
|
243
|
-
{
|
|
244
|
-
LoadingComponent: /* @__PURE__ */ React.createElement(LoadingComponent, null),
|
|
245
|
-
authClient: keycloak,
|
|
246
|
-
autoRefreshToken: initOptions.checkLoginIframe,
|
|
247
|
-
initOptions,
|
|
248
|
-
onEvent: handleEvent,
|
|
249
|
-
onTokens
|
|
250
|
-
},
|
|
251
|
-
/* @__PURE__ */ React.createElement(AfterAuth, null, children)
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
var defaultKeycloakInitOptions = {
|
|
255
|
-
checkLoginIframe: true,
|
|
256
|
-
checkLoginIframeInterval: 5,
|
|
257
|
-
enableLogging: false,
|
|
258
|
-
onLoad: "check-sso",
|
|
259
|
-
pkceMethod: "S256"
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
export {
|
|
263
|
-
KeycloakProvider,
|
|
264
|
-
defaultKeycloakInitOptions
|
|
265
|
-
};
|
package/lib/chunk-C2FNSVJO.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
}); // src/state/index.ts
|
|
5
|
-
var _zustand = require("multiplatform.one/zustand");
|
|
6
|
-
var _config = require("app/config");
|
|
7
|
-
var useStore = _zustand.createStateStore.call(void 0, "auth", {
|
|
8
|
-
idToken: "",
|
|
9
|
-
refreshToken: "",
|
|
10
|
-
token: ""
|
|
11
|
-
}, void 0, {
|
|
12
|
-
persist: _config.config.get("KEYCLOAK_PERSIST") === "1"
|
|
13
|
-
}).useStore;
|
|
14
|
-
function useAuthState() {
|
|
15
|
-
return useStore();
|
|
16
|
-
}
|
|
17
|
-
exports.useAuthState = useAuthState;
|
package/lib/chunk-J4CCMILN.mjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCurrentRouteName
|
|
3
|
-
} from "./chunk-L5HMOY4M.mjs";
|
|
4
|
-
import {
|
|
5
|
-
useKeycloak
|
|
6
|
-
} from "./chunk-UHTKOFS6.mjs";
|
|
7
|
-
import {
|
|
8
|
-
useAuthConfig
|
|
9
|
-
} from "./chunk-Y4XMF3R6.mjs";
|
|
10
|
-
|
|
11
|
-
// src/hooks/useLogin.ts
|
|
12
|
-
import { MultiPlatform } from "multiplatform.one";
|
|
13
|
-
import { useRouter } from "solito/router";
|
|
14
|
-
function useLogin(loginRoute) {
|
|
15
|
-
if (MultiPlatform.isStorybook)
|
|
16
|
-
return () => null;
|
|
17
|
-
const keycloak = useKeycloak();
|
|
18
|
-
const authConfig = useAuthConfig();
|
|
19
|
-
const currentRouteName = useCurrentRouteName();
|
|
20
|
-
const router = useRouter();
|
|
21
|
-
return () => {
|
|
22
|
-
if (!loginRoute)
|
|
23
|
-
loginRoute = authConfig.loginRoute;
|
|
24
|
-
if (!loginRoute) {
|
|
25
|
-
keycloak.login();
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const url = new URL(`x://${loginRoute}`);
|
|
29
|
-
const searchParams = new URLSearchParams(url.search);
|
|
30
|
-
if (currentRouteName)
|
|
31
|
-
searchParams.append("backTo", currentRouteName);
|
|
32
|
-
let query = searchParams.toString();
|
|
33
|
-
if (query.length)
|
|
34
|
-
query = `?${query}`;
|
|
35
|
-
router.push(`${url.pathname.substring(2)}${query}`);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
useLogin
|
|
41
|
-
};
|