@multiplatform.one/keycloak 0.7.0 → 0.7.2

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.
Files changed (101) hide show
  1. package/lib/@types/coreJsPure.d.d.ts +2 -0
  2. package/lib/@types/coreJsPure.d.js +1 -0
  3. package/lib/@types/coreJsPure.d.mjs +0 -0
  4. package/lib/@types/expoKeycloakAuth.d.d.ts +28 -0
  5. package/lib/@types/expoKeycloakAuth.d.js +1 -0
  6. package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
  7. package/lib/Authenticated.d.ts +36 -0
  8. package/lib/Authenticated.js +19 -0
  9. package/lib/Authenticated.mjs +20 -0
  10. package/lib/authConfig.d.ts +37 -0
  11. package/lib/authConfig.js +8 -0
  12. package/lib/authConfig.mjs +9 -0
  13. package/lib/chunk-2GUOEPFY.mjs +0 -0
  14. package/lib/chunk-3ZPHNEJL.js +11 -0
  15. package/lib/chunk-64PPU7Q3.mjs +13 -0
  16. package/lib/chunk-6NDWOV55.js +1 -0
  17. package/lib/chunk-6QZDLO3M.mjs +41 -0
  18. package/lib/chunk-73FF4BX7.js +78 -0
  19. package/lib/chunk-7MTPH6XK.mjs +26 -0
  20. package/lib/chunk-A7UBOIAL.js +13 -0
  21. package/lib/chunk-AD6VPMID.mjs +20 -0
  22. package/lib/chunk-AYKQVWMR.mjs +0 -0
  23. package/lib/chunk-BTHRDOLL.mjs +84 -0
  24. package/lib/chunk-C2FNSVJO.js +17 -0
  25. package/lib/chunk-CLO6HIJN.mjs +52 -0
  26. package/lib/chunk-DJW5IKQS.mjs +265 -0
  27. package/lib/chunk-JLIMB5OD.js +56 -0
  28. package/lib/chunk-JYEIPNPN.mjs +76 -0
  29. package/lib/chunk-K2MQYDVB.mjs +50 -0
  30. package/lib/chunk-KLLABHIC.js +13 -0
  31. package/lib/chunk-L5HMOY4M.mjs +18 -0
  32. package/lib/chunk-NHABU752.mjs +10 -0
  33. package/lib/chunk-NRD376XV.js +33 -0
  34. package/lib/chunk-NWRANDZ6.js +98 -0
  35. package/lib/chunk-NXTVYIBR.mjs +11 -0
  36. package/lib/chunk-OYWAYMFN.js +17 -0
  37. package/lib/chunk-QFP2JWHZ.js +443 -0
  38. package/lib/chunk-RTZ3CZKS.js +161 -0
  39. package/lib/chunk-S3M2DZ6G.js +460 -0
  40. package/lib/chunk-UBVYEZI3.js +1 -0
  41. package/lib/chunk-UOKDJT5L.mjs +16 -0
  42. package/lib/chunk-XXPGZHWZ.js +22 -0
  43. package/lib/chunk-Y4XMF3R6.mjs +13 -0
  44. package/lib/chunk-YGNNHTFE.js +12 -0
  45. package/lib/hooks/index.d.ts +9 -0
  46. package/lib/hooks/index.js +23 -0
  47. package/lib/hooks/index.mjs +34 -0
  48. package/lib/hooks/useAuthConfig.d.ts +29 -0
  49. package/lib/hooks/useAuthConfig.js +8 -0
  50. package/lib/hooks/useAuthConfig.mjs +8 -0
  51. package/lib/hooks/useCurrentRouteName/index.d.ts +26 -0
  52. package/lib/hooks/useCurrentRouteName/index.js +7 -0
  53. package/lib/hooks/useCurrentRouteName/index.mjs +7 -0
  54. package/lib/hooks/useCurrentRouteName/index.native.d.ts +26 -0
  55. package/lib/hooks/useCurrentRouteName/index.native.js +14 -0
  56. package/lib/hooks/useCurrentRouteName/index.native.mjs +14 -0
  57. package/lib/hooks/useKeycloak/index.d.ts +70 -0
  58. package/lib/hooks/useKeycloak/index.js +11 -0
  59. package/lib/hooks/useKeycloak/index.mjs +12 -0
  60. package/lib/hooks/useKeycloak/useKeycloak.d.ts +2 -0
  61. package/lib/hooks/useKeycloak/useKeycloak.js +10 -0
  62. package/lib/hooks/useKeycloak/useKeycloak.mjs +11 -0
  63. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +44 -0
  64. package/lib/hooks/useKeycloak/useKeycloak.native.js +80 -0
  65. package/lib/hooks/useKeycloak/useKeycloak.native.mjs +69 -0
  66. package/lib/hooks/useLogin.d.ts +26 -0
  67. package/lib/hooks/useLogin.js +11 -0
  68. package/lib/hooks/useLogin.mjs +11 -0
  69. package/lib/hooks/useTokensFromQuery/index.d.ts +26 -0
  70. package/lib/hooks/useTokensFromQuery/index.js +7 -0
  71. package/lib/hooks/useTokensFromQuery/index.mjs +7 -0
  72. package/lib/hooks/useTokensFromQuery/index.native.d.ts +26 -0
  73. package/lib/hooks/useTokensFromQuery/index.native.js +10 -0
  74. package/lib/hooks/useTokensFromQuery/index.native.mjs +7 -0
  75. package/lib/hooks/useTokensFromState.d.ts +26 -0
  76. package/lib/hooks/useTokensFromState.js +9 -0
  77. package/lib/hooks/useTokensFromState.mjs +9 -0
  78. package/lib/index.d.ts +13 -0
  79. package/lib/index.mjs +56 -0
  80. package/lib/provider/afterAuth.d.ts +32 -0
  81. package/lib/provider/afterAuth.js +18 -0
  82. package/lib/provider/afterAuth.mjs +18 -0
  83. package/lib/provider/index.d.ts +42 -0
  84. package/lib/provider/index.js +22 -0
  85. package/lib/provider/index.mjs +25 -0
  86. package/lib/provider/keycloakProvider.d.ts +45 -0
  87. package/lib/provider/keycloakProvider.js +20 -0
  88. package/lib/provider/keycloakProvider.mjs +21 -0
  89. package/lib/provider/keycloakProvider.native.d.ts +32 -0
  90. package/lib/provider/keycloakProvider.native.js +87 -0
  91. package/lib/provider/keycloakProvider.native.mjs +30 -0
  92. package/lib/state/index.d.ts +34 -0
  93. package/lib/state/index.js +7 -0
  94. package/lib/state/index.mjs +7 -0
  95. package/lib/types.d.ts +40 -0
  96. package/lib/types.js +8 -0
  97. package/lib/types.mjs +7 -0
  98. package/lib/util.d.ts +27 -0
  99. package/lib/util.js +8 -0
  100. package/lib/util.mjs +9 -0
  101. package/package.json +5 -3
@@ -0,0 +1,265 @@
1
+ import {
2
+ AfterAuth
3
+ } from "./chunk-K2MQYDVB.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
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _interopRequireDefault(obj) {
6
+ return obj && obj.__esModule ? obj : {
7
+ default: obj
8
+ };
9
+ }
10
+ var _chunkS3M2DZ6Gjs = require("./chunk-S3M2DZ6G.js");
11
+ var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
12
+ var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
13
+ // src/provider/afterAuth.tsx
14
+ var _react = require("react");
15
+ var _react2 = _interopRequireDefault(_react);
16
+ var logger = console;
17
+ var AfterAuth = function(param) {
18
+ var children = param.children;
19
+ var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
20
+ var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
21
+ var _chunkS3M2DZ6Gjs_useKeycloak_call = _chunkS3M2DZ6Gjs.useKeycloak.call(void 0), token = _chunkS3M2DZ6Gjs_useKeycloak_call.token, refreshToken = _chunkS3M2DZ6Gjs_useKeycloak_call.refreshToken, authenticated = _chunkS3M2DZ6Gjs_useKeycloak_call.authenticated, idToken = _chunkS3M2DZ6Gjs_useKeycloak_call.idToken;
22
+ _react.useEffect.call(void 0, function() {
23
+ if (!authenticated) return;
24
+ if (authConfig.persist && token) {
25
+ authState.setToken(token);
26
+ if (idToken) authState.setIdToken(idToken);
27
+ if (authConfig.ensureFreshness && refreshToken) authState.setRefreshToken(refreshToken);
28
+ }
29
+ }, [
30
+ token,
31
+ refreshToken,
32
+ idToken
33
+ ]);
34
+ _react.useEffect.call(void 0, function() {
35
+ if (authConfig.debug && authState.token) logger.debug("token", authState.token);
36
+ }, [
37
+ authState.token
38
+ ]);
39
+ _react.useEffect.call(void 0, function() {
40
+ if (authConfig.debug && authState.idToken) logger.debug("idToken", authState.idToken);
41
+ }, [
42
+ authState.idToken
43
+ ]);
44
+ _react.useEffect.call(void 0, function() {
45
+ if (authConfig.debug && authState.refreshToken) logger.debug("refreshToken", authState.refreshToken);
46
+ }, [
47
+ authState.refreshToken
48
+ ]);
49
+ _react.useEffect.call(void 0, function() {
50
+ if (authConfig.debug) logger.debug("authenticated", authenticated);
51
+ }, [
52
+ authenticated
53
+ ]);
54
+ return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
55
+ };
56
+ exports.AfterAuth = AfterAuth;
@@ -0,0 +1,76 @@
1
+ import {
2
+ KeycloakProvider
3
+ } from "./chunk-DJW5IKQS.mjs";
4
+ import {
5
+ useTokensFromQuery
6
+ } from "./chunk-NXTVYIBR.mjs";
7
+ import {
8
+ useTokensFromState
9
+ } from "./chunk-UOKDJT5L.mjs";
10
+ import {
11
+ AuthConfigContext,
12
+ defaultAuthConfig
13
+ } from "./chunk-64PPU7Q3.mjs";
14
+
15
+ // src/provider/index.tsx
16
+ import React, { useMemo } from "react";
17
+ import { config } from "app/config";
18
+ var persist = config.get("KEYCLOAK_PERSIST") === "1";
19
+ var AuthProvider = ({
20
+ // keycloak config
21
+ realm,
22
+ clientId,
23
+ baseUrl,
24
+ // auth config
25
+ debug,
26
+ ensureFreshness,
27
+ loginRoute,
28
+ messageHandlerKeys,
29
+ ssr,
30
+ // props
31
+ children,
32
+ cookies,
33
+ disabled,
34
+ loadingComponent,
35
+ onEvent,
36
+ onTokens,
37
+ ...keycloakInitOptions
38
+ }) => {
39
+ const tokensFromQuery = useTokensFromQuery();
40
+ const tokensFromState = useTokensFromState();
41
+ const authConfig = useMemo(
42
+ () => ({
43
+ ...defaultAuthConfig,
44
+ ...typeof debug !== "undefined" ? { debug } : {},
45
+ ...typeof ensureFreshness !== "undefined" ? { ensureFreshness } : {},
46
+ ...typeof loginRoute !== "undefined" ? { loginRoute } : {},
47
+ ...typeof messageHandlerKeys !== "undefined" ? { messageHandlerKeys } : {},
48
+ persist: !tokensFromState && !tokensFromQuery && cookies && ssr ? false : typeof persist !== "undefined" ? persist : defaultAuthConfig.persist,
49
+ ssr: !tokensFromState && !tokensFromQuery && cookies ? typeof ssr !== "undefined" ? ssr : defaultAuthConfig.ssr : false
50
+ }),
51
+ [debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr]
52
+ );
53
+ if (disabled) {
54
+ return /* @__PURE__ */ React.createElement(AuthConfigContext.Provider, { value: authConfig }, children);
55
+ }
56
+ return /* @__PURE__ */ React.createElement(AuthConfigContext.Provider, { value: authConfig }, /* @__PURE__ */ React.createElement(
57
+ KeycloakProvider,
58
+ {
59
+ cookies,
60
+ keycloakConfig: {
61
+ realm: realm || "main",
62
+ clientId: clientId || "app",
63
+ url: baseUrl
64
+ },
65
+ keycloakInitOptions,
66
+ loadingComponent,
67
+ onEvent,
68
+ onTokens
69
+ },
70
+ children
71
+ ));
72
+ };
73
+
74
+ export {
75
+ AuthProvider
76
+ };
@@ -0,0 +1,50 @@
1
+ import {
2
+ useKeycloak
3
+ } from "./chunk-BTHRDOLL.mjs";
4
+ import {
5
+ useAuthConfig
6
+ } from "./chunk-Y4XMF3R6.mjs";
7
+ import {
8
+ useAuthState
9
+ } from "./chunk-AD6VPMID.mjs";
10
+
11
+ // src/provider/afterAuth.tsx
12
+ import React, { useEffect } from "react";
13
+ var logger = console;
14
+ var AfterAuth = ({ children }) => {
15
+ const authConfig = useAuthConfig();
16
+ const authState = useAuthState();
17
+ const { token, refreshToken, authenticated, idToken } = useKeycloak();
18
+ useEffect(() => {
19
+ if (!authenticated)
20
+ return;
21
+ if (authConfig.persist && token) {
22
+ authState.setToken(token);
23
+ if (idToken)
24
+ authState.setIdToken(idToken);
25
+ if (authConfig.ensureFreshness && refreshToken)
26
+ authState.setRefreshToken(refreshToken);
27
+ }
28
+ }, [token, refreshToken, idToken]);
29
+ useEffect(() => {
30
+ if (authConfig.debug && authState.token)
31
+ logger.debug("token", authState.token);
32
+ }, [authState.token]);
33
+ useEffect(() => {
34
+ if (authConfig.debug && authState.idToken)
35
+ logger.debug("idToken", authState.idToken);
36
+ }, [authState.idToken]);
37
+ useEffect(() => {
38
+ if (authConfig.debug && authState.refreshToken)
39
+ logger.debug("refreshToken", authState.refreshToken);
40
+ }, [authState.refreshToken]);
41
+ useEffect(() => {
42
+ if (authConfig.debug)
43
+ logger.debug("authenticated", authenticated);
44
+ }, [authenticated]);
45
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
46
+ };
47
+
48
+ export {
49
+ AfterAuth
50
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ }); // src/hooks/useTokensFromQuery/index.ts
5
+ var _multiplatformone = require("multiplatform.one");
6
+ var _router = require("next/router");
7
+ function useTokensFromQuery() {
8
+ var query = (_multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0) : {
9
+ query: {}
10
+ }).query;
11
+ return "idToken" in query || "token" in query || "refreshToken" in query;
12
+ }
13
+ exports.useTokensFromQuery = useTokensFromQuery;
@@ -0,0 +1,18 @@
1
+ // src/hooks/useCurrentRouteName/index.ts
2
+ import { MultiPlatform } from "multiplatform.one";
3
+ import { useRoute } from "@react-navigation/native";
4
+ import { useRouter } from "next/router";
5
+ function useCurrentRouteName() {
6
+ if (MultiPlatform.isStorybook)
7
+ return null;
8
+ if (MultiPlatform.isNext) {
9
+ const router = useRouter();
10
+ return router.route;
11
+ }
12
+ const route = useRoute();
13
+ return route.name;
14
+ }
15
+
16
+ export {
17
+ useCurrentRouteName
18
+ };
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+
8
+ export {
9
+ __publicField
10
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _chunkOYWAYMFNjs = require("./chunk-OYWAYMFN.js");
6
+ var _chunkS3M2DZ6Gjs = require("./chunk-S3M2DZ6G.js");
7
+ var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
8
+ // src/hooks/useLogin.ts
9
+ var _multiplatformone = require("multiplatform.one");
10
+ var _router = require("solito/router");
11
+ function useLogin(loginRoute) {
12
+ if (_multiplatformone.MultiPlatform.isStorybook) return function() {
13
+ return null;
14
+ };
15
+ var keycloak = _chunkS3M2DZ6Gjs.useKeycloak.call(void 0);
16
+ var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
17
+ var currentRouteName = _chunkOYWAYMFNjs.useCurrentRouteName.call(void 0);
18
+ var router = _router.useRouter.call(void 0);
19
+ return function() {
20
+ if (!loginRoute) loginRoute = authConfig.loginRoute;
21
+ if (!loginRoute) {
22
+ keycloak.login();
23
+ return;
24
+ }
25
+ var url = new URL("x://".concat(loginRoute));
26
+ var searchParams = new URLSearchParams(url.search);
27
+ if (currentRouteName) searchParams.append("backTo", currentRouteName);
28
+ var query = searchParams.toString();
29
+ if (query.length) query = "?".concat(query);
30
+ router.push("".concat(url.pathname.substring(2)).concat(query));
31
+ };
32
+ }
33
+ exports.useLogin = useLogin;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_without_holes(arr) {
8
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
9
+ }
10
+ function _instanceof(left, right) {
11
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
12
+ return !!right[Symbol.hasInstance](left);
13
+ } else {
14
+ return left instanceof right;
15
+ }
16
+ }
17
+ function _iterable_to_array(iter) {
18
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
19
+ }
20
+ function _non_iterable_spread() {
21
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
22
+ }
23
+ function _to_consumable_array(arr) {
24
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
25
+ }
26
+ function _unsupported_iterable_to_array(o, minLen) {
27
+ if (!o) return;
28
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
29
+ var n = Object.prototype.toString.call(o).slice(8, -1);
30
+ if (n === "Object" && o.constructor) n = o.constructor.name;
31
+ if (n === "Map" || n === "Set") return Array.from(n);
32
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
33
+ }
34
+ Object.defineProperty(exports, "__esModule", {
35
+ value: true
36
+ });
37
+ function _optionalChain(ops) {
38
+ var lastAccessLHS = undefined;
39
+ var value = ops[0];
40
+ var i = 1;
41
+ while(i < ops.length){
42
+ var op = ops[i];
43
+ var fn = ops[i + 1];
44
+ i += 2;
45
+ if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
46
+ return undefined;
47
+ }
48
+ if (op === "access" || op === "optionalAccess") {
49
+ lastAccessLHS = value;
50
+ value = fn(value);
51
+ } else if (op === "call" || op === "optionalCall") {
52
+ var _value;
53
+ value = fn(function() {
54
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
55
+ args[_key] = arguments[_key];
56
+ }
57
+ return (_value = value).call.apply(_value, [
58
+ lastAccessLHS
59
+ ].concat(_to_consumable_array(args)));
60
+ });
61
+ lastAccessLHS = undefined;
62
+ }
63
+ }
64
+ return value;
65
+ } // src/util.ts
66
+ function validToken(token, refreshToken) {
67
+ if (typeof token !== "string") return token;
68
+ if (refreshToken) {
69
+ if (refreshToken === true || isTokenValid(refreshToken)) return token;
70
+ return false;
71
+ }
72
+ return isTokenValid(token) ? token : false;
73
+ }
74
+ function isTokenValid(token) {
75
+ try {
76
+ var exp = JSON.parse(Buffer.from(_optionalChain([
77
+ token,
78
+ "access",
79
+ function(_) {
80
+ return _.split;
81
+ },
82
+ "call",
83
+ function(_2) {
84
+ return _2(".");
85
+ },
86
+ "optionalAccess",
87
+ function(_3) {
88
+ return _3[1];
89
+ }
90
+ ]) || "", "base64").toString() || "{}").exp;
91
+ return Math.floor(Date.now() / 1e3) <= exp;
92
+ } catch (err) {
93
+ if (_instanceof(err, SyntaxError)) return false;
94
+ throw err;
95
+ }
96
+ }
97
+ exports.validToken = validToken;
98
+ exports.isTokenValid = isTokenValid;
@@ -0,0 +1,11 @@
1
+ // src/hooks/useTokensFromQuery/index.ts
2
+ import { MultiPlatform } from "multiplatform.one";
3
+ import { useRouter } from "next/router";
4
+ function useTokensFromQuery() {
5
+ const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
6
+ return "idToken" in query || "token" in query || "refreshToken" in query;
7
+ }
8
+
9
+ export {
10
+ useTokensFromQuery
11
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ }); // src/hooks/useCurrentRouteName/index.ts
5
+ var _multiplatformone = require("multiplatform.one");
6
+ var _native = require("@react-navigation/native");
7
+ var _router = require("next/router");
8
+ function useCurrentRouteName() {
9
+ if (_multiplatformone.MultiPlatform.isStorybook) return null;
10
+ if (_multiplatformone.MultiPlatform.isNext) {
11
+ var router = _router.useRouter.call(void 0);
12
+ return router.route;
13
+ }
14
+ var route = _native.useRoute.call(void 0);
15
+ return route.name;
16
+ }
17
+ exports.useCurrentRouteName = useCurrentRouteName;