@multiplatform.one/keycloak 0.7.15 → 0.7.17

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 (228) hide show
  1. package/lib/@types/expoKeycloakAuth.d.js +1 -1
  2. package/lib/Authenticated.d.mts +2 -2
  3. package/lib/Authenticated.d.ts +2 -2
  4. package/lib/Authenticated.js +20 -19
  5. package/lib/Authenticated.mjs +13 -13
  6. package/lib/authConfig.d.mts +2 -4
  7. package/lib/authConfig.d.ts +2 -4
  8. package/lib/authConfig.js +9 -8
  9. package/lib/authConfig.mjs +2 -2
  10. package/lib/chunk-2BKS6UM5.js +51 -0
  11. package/lib/chunk-2BSUCVXL.js +50 -0
  12. package/lib/chunk-2L5TXBDK.mjs +7 -0
  13. package/lib/chunk-2VDDEPLF.js +27 -0
  14. package/lib/chunk-32AVT4GA.js +9 -0
  15. package/lib/chunk-3ZTSLDX7.js +13 -0
  16. package/lib/chunk-6F4PWJZI.js +1 -0
  17. package/lib/{chunk-7MTPH6XK.mjs → chunk-6FRYV4MK.mjs} +10 -9
  18. package/lib/chunk-A2V2S4HP.js +22 -0
  19. package/lib/chunk-BUZONXAW.js +1 -0
  20. package/lib/{chunk-BVB33X7V.mjs → chunk-CGLMLNUS.mjs} +61 -81
  21. package/lib/chunk-FU4CT24B.mjs +32 -0
  22. package/lib/{chunk-Y4XMF3R6.mjs → chunk-HTWZLBA4.mjs} +1 -1
  23. package/lib/chunk-I5FNGKQ6.js +16 -0
  24. package/lib/{chunk-64PPU7Q3.mjs → chunk-JAFUI2JQ.mjs} +1 -5
  25. package/lib/{chunk-NXTVYIBR.mjs → chunk-L3HTVJ4B.mjs} +2 -0
  26. package/lib/chunk-MDAAMGTE.js +1 -0
  27. package/lib/chunk-NH335CDK.js +32 -0
  28. package/lib/chunk-OA5TSQWZ.mjs +50 -0
  29. package/lib/chunk-OBB23GPX.mjs +0 -0
  30. package/lib/chunk-OZLV3US5.js +245 -0
  31. package/lib/chunk-P57PW2II.js +11 -0
  32. package/lib/chunk-TUJRPTZE.js +13 -0
  33. package/lib/chunk-UESWAK47.mjs +0 -0
  34. package/lib/chunk-UH4K7HGE.mjs +163 -0
  35. package/lib/{chunk-UOKDJT5L.mjs → chunk-UKSHA3X3.mjs} +2 -2
  36. package/lib/chunk-VS4M7GMO.js +1 -0
  37. package/lib/chunk-WBQAMGXK.mjs +0 -0
  38. package/lib/{chunk-AD6VPMID.mjs → chunk-WMH347OL.mjs} +5 -3
  39. package/lib/chunk-WS4IMGVL.js +1 -0
  40. package/lib/chunk-X53FOCXA.js +28 -0
  41. package/lib/chunk-Y23BWOII.mjs +51 -0
  42. package/lib/chunk-Y5MS3XVZ.mjs +28 -0
  43. package/lib/chunk-YACGLW5Q.js +7 -0
  44. package/lib/chunk-ZCBD6HWK.js +1 -0
  45. package/lib/chunk-ZFXKCRJC.mjs +11 -0
  46. package/lib/chunk-ZW4GP2I5.js +163 -0
  47. package/lib/hooks/index.d.mts +0 -4
  48. package/lib/hooks/index.d.ts +0 -4
  49. package/lib/hooks/index.js +19 -23
  50. package/lib/hooks/index.mjs +8 -23
  51. package/lib/hooks/useAuthConfig.js +8 -8
  52. package/lib/hooks/useAuthConfig.mjs +3 -3
  53. package/lib/hooks/useTokensFromQuery/index.js +7 -7
  54. package/lib/hooks/useTokensFromQuery/index.mjs +2 -2
  55. package/lib/hooks/useTokensFromQuery/index.native.js +5 -8
  56. package/lib/hooks/useTokensFromQuery/index.native.mjs +1 -1
  57. package/lib/hooks/useTokensFromState.js +9 -9
  58. package/lib/hooks/useTokensFromState.mjs +4 -4
  59. package/lib/index.d.mts +10 -7
  60. package/lib/index.d.ts +10 -7
  61. package/lib/index.js +62 -34
  62. package/lib/index.mjs +32 -26
  63. package/lib/keycloak/context.d.mts +12 -0
  64. package/lib/keycloak/context.d.ts +12 -0
  65. package/lib/keycloak/context.js +7 -0
  66. package/lib/keycloak/context.mjs +7 -0
  67. package/lib/keycloak/index.d.mts +7 -0
  68. package/lib/keycloak/index.d.ts +7 -0
  69. package/lib/keycloak/index.js +14 -0
  70. package/lib/keycloak/index.mjs +14 -0
  71. package/lib/keycloak/keycloak.d.mts +37 -0
  72. package/lib/keycloak/keycloak.d.ts +37 -0
  73. package/lib/keycloak/keycloak.js +13 -0
  74. package/lib/keycloak/keycloak.mjs +13 -0
  75. package/lib/keycloak/keycloak.native.d.mts +33 -0
  76. package/lib/keycloak/keycloak.native.d.ts +33 -0
  77. package/lib/keycloak/keycloak.native.js +134 -0
  78. package/lib/keycloak/keycloak.native.mjs +134 -0
  79. package/lib/provider/{afterAuth.d.ts → AfterAuth.d.mts} +6 -7
  80. package/lib/provider/{afterAuth.d.mts → AfterAuth.d.ts} +6 -7
  81. package/lib/provider/AfterAuth.js +18 -0
  82. package/lib/provider/AfterAuth.mjs +18 -0
  83. package/lib/provider/AuthProvider/AuthProvider.d.mts +37 -0
  84. package/lib/provider/AuthProvider/AuthProvider.d.ts +37 -0
  85. package/lib/provider/AuthProvider/AuthProvider.js +19 -0
  86. package/lib/provider/AuthProvider/AuthProvider.mjs +19 -0
  87. package/lib/provider/{keycloakProvider.native.d.ts → AuthProvider/AuthProvider.native.d.mts} +9 -9
  88. package/lib/provider/{keycloakProvider.native.d.mts → AuthProvider/AuthProvider.native.d.ts} +9 -9
  89. package/lib/provider/AuthProvider/AuthProvider.native.js +25 -0
  90. package/lib/provider/AuthProvider/AuthProvider.native.mjs +25 -0
  91. package/lib/provider/AuthProvider/index.d.mts +4 -0
  92. package/lib/provider/AuthProvider/index.d.ts +4 -0
  93. package/lib/provider/AuthProvider/index.js +20 -0
  94. package/lib/provider/AuthProvider/index.mjs +20 -0
  95. package/lib/provider/KeycloakProvider.d.mts +34 -0
  96. package/lib/provider/KeycloakProvider.d.ts +34 -0
  97. package/lib/provider/KeycloakProvider.js +21 -0
  98. package/lib/provider/KeycloakProvider.mjs +21 -0
  99. package/lib/provider/index.d.mts +8 -39
  100. package/lib/provider/index.d.ts +8 -39
  101. package/lib/provider/index.js +28 -22
  102. package/lib/provider/index.mjs +22 -19
  103. package/lib/routes.d.mts +28 -0
  104. package/lib/routes.d.ts +28 -0
  105. package/lib/routes.js +127 -0
  106. package/lib/routes.mjs +127 -0
  107. package/lib/session/index.d.mts +3 -0
  108. package/lib/session/index.d.ts +3 -0
  109. package/lib/session/index.js +10 -0
  110. package/lib/session/index.mjs +10 -0
  111. package/lib/session/session.d.mts +18 -0
  112. package/lib/session/session.d.ts +18 -0
  113. package/lib/session/session.js +9 -0
  114. package/lib/session/session.mjs +9 -0
  115. package/lib/session/session.native.d.mts +8 -0
  116. package/lib/session/session.native.d.ts +8 -0
  117. package/lib/session/session.native.js +13 -0
  118. package/lib/session/session.native.mjs +13 -0
  119. package/lib/{state/index.d.ts → state.d.mts} +2 -1
  120. package/lib/{state/index.d.mts → state.d.ts} +2 -1
  121. package/lib/state.js +9 -0
  122. package/lib/state.mjs +9 -0
  123. package/lib/token.d.mts +17 -0
  124. package/lib/token.d.ts +17 -0
  125. package/lib/token.js +9 -0
  126. package/lib/{util.mjs → token.mjs} +2 -2
  127. package/lib/types.d.mts +5 -2
  128. package/lib/types.d.ts +5 -2
  129. package/lib/types.js +1 -8
  130. package/lib/types.mjs +1 -7
  131. package/package.json +28 -28
  132. package/routes/index.d.ts +22 -0
  133. package/routes/index.js +22 -0
  134. package/src/Authenticated.tsx +27 -17
  135. package/src/authConfig.ts +3 -9
  136. package/src/hooks/index.ts +0 -3
  137. package/src/hooks/useTokensFromQuery/index.ts +1 -0
  138. package/src/hooks/useTokensFromState.ts +1 -1
  139. package/src/index.ts +3 -0
  140. package/src/{@types/coreJsPure.d.ts → keycloak/context.ts} +6 -11
  141. package/src/{hooks/useCurrentRouteName/index.native.ts → keycloak/index.ts} +4 -11
  142. package/src/keycloak/keycloak.native.ts +148 -0
  143. package/src/keycloak/keycloak.ts +175 -0
  144. package/src/provider/AfterAuth.tsx +63 -0
  145. package/src/provider/{keycloakProvider.native.tsx → AuthProvider/AuthProvider.native.tsx} +8 -16
  146. package/src/provider/{keycloakProvider.tsx → AuthProvider/AuthProvider.tsx} +81 -94
  147. package/src/provider/AuthProvider/index.ts +22 -0
  148. package/src/provider/KeycloakProvider.tsx +53 -0
  149. package/src/provider/index.ts +24 -0
  150. package/src/routes.ts +163 -0
  151. package/src/session/index.ts +22 -0
  152. package/src/{hooks/useCurrentRouteName/index.ts → session/session.native.ts} +11 -14
  153. package/src/session/session.ts +68 -0
  154. package/src/{state/index.ts → state.ts} +5 -4
  155. package/src/{util.ts → token.ts} +25 -11
  156. package/src/types.ts +4 -1
  157. package/lib/@types/coreJsPure.d.d.mts +0 -2
  158. package/lib/@types/coreJsPure.d.d.ts +0 -2
  159. package/lib/@types/coreJsPure.d.js +0 -1
  160. package/lib/chunk-3ZPHNEJL.js +0 -11
  161. package/lib/chunk-6NDWOV55.js +0 -1
  162. package/lib/chunk-A7UBOIAL.js +0 -13
  163. package/lib/chunk-AUUZ6BI7.js +0 -78
  164. package/lib/chunk-C2FNSVJO.js +0 -17
  165. package/lib/chunk-J4CCMILN.mjs +0 -41
  166. package/lib/chunk-K33RKJZX.js +0 -443
  167. package/lib/chunk-KLLABHIC.js +0 -13
  168. package/lib/chunk-L5HMOY4M.mjs +0 -18
  169. package/lib/chunk-MZ6E62HK.js +0 -33
  170. package/lib/chunk-NWRANDZ6.js +0 -98
  171. package/lib/chunk-OYWAYMFN.js +0 -17
  172. package/lib/chunk-RPUOO7AV.mjs +0 -10
  173. package/lib/chunk-RYM7KERK.mjs +0 -52
  174. package/lib/chunk-UBVYEZI3.js +0 -1
  175. package/lib/chunk-UHTKOFS6.mjs +0 -84
  176. package/lib/chunk-UL6L5ONI.js +0 -460
  177. package/lib/chunk-W5DJLFTQ.js +0 -56
  178. package/lib/chunk-WT5W6BSZ.js +0 -161
  179. package/lib/chunk-XEO3YXBM.js +0 -22
  180. package/lib/chunk-XO4W2SMN.mjs +0 -50
  181. package/lib/chunk-XVPWAAZ4.mjs +0 -76
  182. package/lib/chunk-YGNNHTFE.js +0 -12
  183. package/lib/hooks/useCurrentRouteName/index.d.mts +0 -3
  184. package/lib/hooks/useCurrentRouteName/index.d.ts +0 -3
  185. package/lib/hooks/useCurrentRouteName/index.js +0 -7
  186. package/lib/hooks/useCurrentRouteName/index.mjs +0 -7
  187. package/lib/hooks/useCurrentRouteName/index.native.d.mts +0 -3
  188. package/lib/hooks/useCurrentRouteName/index.native.d.ts +0 -3
  189. package/lib/hooks/useCurrentRouteName/index.native.js +0 -14
  190. package/lib/hooks/useCurrentRouteName/index.native.mjs +0 -14
  191. package/lib/hooks/useKeycloak/index.d.mts +0 -46
  192. package/lib/hooks/useKeycloak/index.d.ts +0 -46
  193. package/lib/hooks/useKeycloak/index.js +0 -11
  194. package/lib/hooks/useKeycloak/index.mjs +0 -12
  195. package/lib/hooks/useKeycloak/useKeycloak.d.mts +0 -2
  196. package/lib/hooks/useKeycloak/useKeycloak.d.ts +0 -2
  197. package/lib/hooks/useKeycloak/useKeycloak.js +0 -10
  198. package/lib/hooks/useKeycloak/useKeycloak.mjs +0 -11
  199. package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +0 -20
  200. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +0 -20
  201. package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -80
  202. package/lib/hooks/useKeycloak/useKeycloak.native.mjs +0 -69
  203. package/lib/hooks/useLogin.d.mts +0 -3
  204. package/lib/hooks/useLogin.d.ts +0 -3
  205. package/lib/hooks/useLogin.js +0 -11
  206. package/lib/hooks/useLogin.mjs +0 -11
  207. package/lib/provider/afterAuth.js +0 -18
  208. package/lib/provider/afterAuth.mjs +0 -18
  209. package/lib/provider/keycloakProvider.d.mts +0 -42
  210. package/lib/provider/keycloakProvider.d.ts +0 -42
  211. package/lib/provider/keycloakProvider.js +0 -20
  212. package/lib/provider/keycloakProvider.mjs +0 -21
  213. package/lib/provider/keycloakProvider.native.js +0 -87
  214. package/lib/provider/keycloakProvider.native.mjs +0 -30
  215. package/lib/state/index.js +0 -7
  216. package/lib/state/index.mjs +0 -7
  217. package/lib/util.d.mts +0 -4
  218. package/lib/util.d.ts +0 -4
  219. package/lib/util.js +0 -8
  220. package/src/hooks/useKeycloak/index.ts +0 -47
  221. package/src/hooks/useKeycloak/useKeycloak.native.ts +0 -95
  222. package/src/hooks/useKeycloak/useKeycloak.ts +0 -106
  223. package/src/hooks/useLogin.ts +0 -47
  224. package/src/provider/afterAuth.tsx +0 -65
  225. package/src/provider/index.tsx +0 -117
  226. /package/lib/{@types/coreJsPure.d.mjs → chunk-HH32BME2.mjs} +0 -0
  227. /package/lib/{chunk-2GUOEPFY.mjs → chunk-JPQI72HR.mjs} +0 -0
  228. /package/lib/{chunk-AYKQVWMR.mjs → chunk-OAUYHIWG.mjs} +0 -0
@@ -0,0 +1,68 @@
1
+ /*
2
+ * File: /src/session.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 10-01-2024 02:31:26
5
+ * Author: Clay Risser
6
+ * -----
7
+ * BitSpur (c) Copyright 2021 - 2024
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ import type { Session as NextSession } from 'next-auth';
23
+ import type { SessionContextValue as NextSessionContextValue, UseSessionOptions } from 'next-auth/react';
24
+ import { MultiPlatform } from 'multiplatform.one';
25
+ import { useSession as useNextSession, getSession as getNextSession } from 'next-auth/react';
26
+
27
+ let _getServerSession: (() => Promise<Session | null>) | undefined;
28
+
29
+ export async function getSession(): Promise<Session | null> {
30
+ if (MultiPlatform.isServer) {
31
+ if (typeof _getServerSession === 'function') return _getServerSession();
32
+ const getSession = (await import('next-auth')).getServerSession;
33
+ _getServerSession = () => getSession();
34
+ return _getServerSession();
35
+ }
36
+ return getNextSession();
37
+ }
38
+
39
+ export type SessionContextValue<R extends boolean> = Partial<
40
+ Omit<NextSessionContextValue<R> & { session: Session }, 'data'>
41
+ >;
42
+
43
+ let useSession = <R extends boolean>(
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
+ options?: UseSessionOptions<R>,
46
+ ): SessionContextValue<R> => {
47
+ return {};
48
+ };
49
+
50
+ if (MultiPlatform.isNext) {
51
+ useSession = <R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R> => {
52
+ const nextSession = useNextSession(options);
53
+ return {
54
+ update: nextSession.update,
55
+ status: nextSession.status,
56
+ session: nextSession.data as Session,
57
+ } as SessionContextValue<R>;
58
+ };
59
+ }
60
+
61
+ export interface Session extends NextSession {
62
+ accessToken?: string;
63
+ err?: Error;
64
+ idToken?: string;
65
+ refreshToken?: string;
66
+ }
67
+
68
+ export { useSession };
@@ -1,5 +1,5 @@
1
1
  /*
2
- * File: /src/state/index.ts
2
+ * File: /src/state.ts
3
3
  * Project: @multiplatform.one/keycloak
4
4
  * File Created: 22-06-2023 10:07:56
5
5
  * Author: Clay Risser
@@ -20,8 +20,9 @@
20
20
  */
21
21
 
22
22
  import { createStateStore } from 'multiplatform.one/zustand';
23
- // @ts-ignore
24
- import { config } from 'app/config';
23
+ import { MultiPlatform } from 'multiplatform.one';
24
+
25
+ export const persist = MultiPlatform.isIframe || (!MultiPlatform.isNext && !MultiPlatform.isServer);
25
26
 
26
27
  const { useStore } = createStateStore(
27
28
  'auth',
@@ -31,7 +32,7 @@ const { useStore } = createStateStore(
31
32
  token: '',
32
33
  },
33
34
  undefined,
34
- { persist: config.get('KEYCLOAK_PERSIST') === '1' },
35
+ { persist },
35
36
  );
36
37
 
37
38
  export function useAuthState() {
@@ -1,10 +1,10 @@
1
1
  /*
2
- * File: /src/util.ts
2
+ * File: /src/token.ts
3
3
  * Project: @multiplatform.one/keycloak
4
- * File Created: 22-06-2023 10:07:56
4
+ * File Created: 10-01-2024 16:19:33
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * BitSpur (c) Copyright 2021 - 2023
7
+ * BitSpur (c) Copyright 2021 - 2024
8
8
  *
9
9
  * Licensed under the Apache License, Version 2.0 (the "License");
10
10
  * you may not use this file except in compliance with the License.
@@ -19,7 +19,12 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- export function validToken(token: string | boolean, refreshToken?: string | boolean) {
22
+ import type { KeycloakTokenParsed } from 'keycloak-js';
23
+ import { jwtDecode } from 'jwt-decode';
24
+
25
+ export function validToken(token?: string | boolean, refreshToken?: string | boolean) {
26
+ if (typeof token === 'undefined') return;
27
+ if (!token) return false;
23
28
  if (typeof token !== 'string') return token;
24
29
  if (refreshToken) {
25
30
  if (refreshToken === true || isTokenValid(refreshToken)) return token;
@@ -29,11 +34,20 @@ export function validToken(token: string | boolean, refreshToken?: string | bool
29
34
  }
30
35
 
31
36
  export function isTokenValid(token: string) {
32
- try {
33
- const { exp } = JSON.parse(Buffer.from(token.split('.')?.[1] || '', 'base64').toString() || '{}');
34
- return Math.floor(Date.now() / 1000) <= exp;
35
- } catch (err) {
36
- if (err instanceof SyntaxError) return false;
37
- throw err;
38
- }
37
+ const { exp } = jwtDecode(token) as TokenParsed;
38
+ if (!exp) return false;
39
+ return Math.floor(Date.now() / 1000) <= exp;
40
+ }
41
+
42
+ export interface TokenParsed extends KeycloakTokenParsed {
43
+ jti?: string;
44
+ sid?: string;
45
+ typ?: 'Bearer' | string;
46
+ }
47
+
48
+ export interface AccessTokenParsed extends TokenParsed {
49
+ email?: string;
50
+ email_verified?: boolean;
51
+ preferred_username?: string;
52
+ scope?: string;
39
53
  }
package/src/types.ts CHANGED
@@ -34,4 +34,7 @@ declare global {
34
34
  }
35
35
  }
36
36
 
37
- export default null;
37
+ export interface KeycloakMock {
38
+ email?: string;
39
+ username: string;
40
+ }
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- var _chunkA7UBOIALjs = require("./chunk-A7UBOIAL.js");
6
- // src/hooks/useAuthConfig.ts
7
- var _react = require("react");
8
- function useAuthConfig() {
9
- return _react.useContext.call(void 0, _chunkA7UBOIALjs.AuthConfigContext);
10
- }
11
- exports.useAuthConfig = useAuthConfig;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- }); // src/authConfig.ts
5
- var _react = require("react");
6
- var defaultAuthConfig = {
7
- ensureFreshness: true,
8
- persist: false,
9
- ssr: false
10
- };
11
- var AuthConfigContext = _react.createContext.call(void 0, defaultAuthConfig);
12
- exports.defaultAuthConfig = defaultAuthConfig;
13
- exports.AuthConfigContext = AuthConfigContext;
@@ -1,78 +0,0 @@
1
- "use strict";
2
- function _define_property(obj, key, value) {
3
- if (key in obj) {
4
- Object.defineProperty(obj, key, {
5
- value: value,
6
- enumerable: true,
7
- configurable: true,
8
- writable: true
9
- });
10
- } else {
11
- obj[key] = value;
12
- }
13
- return obj;
14
- }
15
- function _object_spread(target) {
16
- for(var i = 1; i < arguments.length; i++){
17
- var source = arguments[i] != null ? arguments[i] : {};
18
- var ownKeys = Object.keys(source);
19
- if (typeof Object.getOwnPropertySymbols === "function") {
20
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
21
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
22
- }));
23
- }
24
- ownKeys.forEach(function(key) {
25
- _define_property(target, key, source[key]);
26
- });
27
- }
28
- return target;
29
- }
30
- Object.defineProperty(exports, "__esModule", {
31
- value: true
32
- });
33
- function _interopRequireDefault(obj) {
34
- return obj && obj.__esModule ? obj : {
35
- default: obj
36
- };
37
- }
38
- var _chunkKLLABHICjs = require("./chunk-KLLABHIC.js");
39
- var _chunkMZ6E62HKjs = require("./chunk-MZ6E62HK.js");
40
- var _chunkUL6L5ONIjs = require("./chunk-UL6L5ONI.js");
41
- var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
42
- var _chunkYGNNHTFEjs = require("./chunk-YGNNHTFE.js");
43
- var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
44
- // src/Authenticated.tsx
45
- var _react = require("react");
46
- var _react2 = _interopRequireDefault(_react);
47
- function Authenticated(param) {
48
- var children = param.children, disabled = param.disabled, loginRoute = param.loginRoute, loggedOutComponent = param.loggedOutComponent;
49
- var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
50
- var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
51
- var login = _chunkMZ6E62HKjs.useLogin.call(void 0, loginRoute);
52
- var tokensFromQuery = _chunkKLLABHICjs.useTokensFromQuery.call(void 0);
53
- var tokensFromState = _chunkYGNNHTFEjs.useTokensFromState.call(void 0);
54
- var authenticated = _chunkUL6L5ONIjs.useKeycloak.call(void 0).authenticated;
55
- _react.useEffect.call(void 0, function() {
56
- if (authenticated !== false) return;
57
- if (authConfig.persist) {
58
- authState.setIdToken("");
59
- authState.setRefreshToken("");
60
- authState.setToken("");
61
- }
62
- if (typeof window !== "undefined" && !tokensFromQuery && !tokensFromState && window.self === window.top) login();
63
- }, [
64
- authenticated
65
- ]);
66
- if (disabled || authenticated) return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
67
- var LoggedOutComponent = loggedOutComponent || function() {
68
- return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, authConfig.debug ? "not authenticated" : null);
69
- };
70
- return /* @__PURE__ */ _react2.default.createElement(LoggedOutComponent, null);
71
- }
72
- function withAuthenticated(Component) {
73
- return function(props) {
74
- return /* @__PURE__ */ _react2.default.createElement(Authenticated, null, /* @__PURE__ */ _react2.default.createElement(Component, _object_spread({}, props)));
75
- };
76
- }
77
- exports.Authenticated = Authenticated;
78
- exports.withAuthenticated = withAuthenticated;
@@ -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;
@@ -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
- };