@multiplatform.one/keycloak 0.1.10 → 0.2.0

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 (204) hide show
  1. package/dist/esm/Authenticated.mjs +25 -0
  2. package/dist/esm/Authenticated.mjs.map +7 -0
  3. package/dist/esm/authConfig.mjs +10 -0
  4. package/dist/esm/authConfig.mjs.map +7 -0
  5. package/dist/esm/hooks/index.mjs +4 -0
  6. package/dist/esm/hooks/index.mjs.map +7 -0
  7. package/dist/esm/hooks/useAuthConfig.mjs +9 -0
  8. package/dist/esm/hooks/useAuthConfig.mjs.map +7 -0
  9. package/dist/esm/hooks/useCurrentRouteName/index.mjs +17 -0
  10. package/dist/esm/hooks/useCurrentRouteName/index.mjs.map +7 -0
  11. package/dist/esm/hooks/useCurrentRouteName/index.native.mjs +12 -0
  12. package/dist/esm/hooks/useCurrentRouteName/index.native.mjs.map +7 -0
  13. package/dist/esm/hooks/useKeycloak/index.mjs +2 -0
  14. package/dist/esm/hooks/useKeycloak/index.mjs.map +7 -0
  15. package/dist/esm/hooks/useKeycloak/useKeycloak.mjs +81 -0
  16. package/dist/esm/hooks/useKeycloak/useKeycloak.mjs.map +7 -0
  17. package/dist/esm/hooks/useKeycloak/useKeycloak.native.mjs +108 -0
  18. package/dist/esm/hooks/useKeycloak/useKeycloak.native.mjs.map +7 -0
  19. package/dist/esm/hooks/useLogin.mjs +35 -0
  20. package/dist/esm/hooks/useLogin.mjs.map +7 -0
  21. package/dist/esm/index.mjs +5 -0
  22. package/dist/esm/index.mjs.map +7 -0
  23. package/dist/esm/provider/afterAuth.mjs +29 -0
  24. package/dist/esm/provider/afterAuth.mjs.map +7 -0
  25. package/dist/esm/provider/index.mjs +73 -0
  26. package/dist/esm/provider/index.mjs.map +7 -0
  27. package/dist/esm/provider/keycloakProvider.mjs +275 -0
  28. package/dist/esm/provider/keycloakProvider.mjs.map +7 -0
  29. package/dist/esm/provider/keycloakProvider.native.mjs +69 -0
  30. package/dist/esm/provider/keycloakProvider.native.mjs.map +7 -0
  31. package/dist/esm/state/index.mjs +14 -0
  32. package/dist/esm/state/index.mjs.map +7 -0
  33. package/dist/esm/types.mjs +5 -0
  34. package/dist/esm/types.mjs.map +7 -0
  35. package/dist/jsx/Authenticated.mjs +20 -0
  36. package/dist/jsx/Authenticated.mjs.map +7 -0
  37. package/dist/jsx/authConfig.mjs +10 -0
  38. package/dist/jsx/authConfig.mjs.map +7 -0
  39. package/dist/jsx/hooks/index.mjs +4 -0
  40. package/dist/jsx/hooks/index.mjs.map +7 -0
  41. package/dist/jsx/hooks/useAuthConfig.mjs +9 -0
  42. package/dist/jsx/hooks/useAuthConfig.mjs.map +7 -0
  43. package/dist/jsx/hooks/useCurrentRouteName/index.mjs +17 -0
  44. package/dist/jsx/hooks/useCurrentRouteName/index.mjs.map +7 -0
  45. package/dist/jsx/hooks/useCurrentRouteName/index.native.mjs +12 -0
  46. package/dist/jsx/hooks/useCurrentRouteName/index.native.mjs.map +7 -0
  47. package/dist/jsx/hooks/useKeycloak/index.mjs +2 -0
  48. package/dist/jsx/hooks/useKeycloak/index.mjs.map +7 -0
  49. package/dist/jsx/hooks/useKeycloak/useKeycloak.mjs +25 -0
  50. package/dist/jsx/hooks/useKeycloak/useKeycloak.mjs.map +7 -0
  51. package/dist/jsx/hooks/useKeycloak/useKeycloak.native.mjs +58 -0
  52. package/dist/jsx/hooks/useKeycloak/useKeycloak.native.mjs.map +7 -0
  53. package/dist/jsx/hooks/useLogin.mjs +33 -0
  54. package/dist/jsx/hooks/useLogin.mjs.map +7 -0
  55. package/dist/jsx/index.mjs +5 -0
  56. package/dist/jsx/index.mjs.map +7 -0
  57. package/dist/jsx/provider/afterAuth.mjs +28 -0
  58. package/dist/jsx/provider/afterAuth.mjs.map +7 -0
  59. package/dist/jsx/provider/index.mjs +20 -0
  60. package/dist/jsx/provider/index.mjs.map +7 -0
  61. package/dist/jsx/provider/keycloakProvider.mjs +158 -0
  62. package/dist/jsx/provider/keycloakProvider.mjs.map +7 -0
  63. package/dist/jsx/provider/keycloakProvider.native.mjs +14 -0
  64. package/dist/jsx/provider/keycloakProvider.native.mjs.map +7 -0
  65. package/dist/jsx/state/index.mjs +17 -0
  66. package/dist/jsx/state/index.mjs.map +7 -0
  67. package/dist/jsx/types.mjs +5 -0
  68. package/dist/jsx/types.mjs.map +7 -0
  69. package/{lib → dist/lib}/Authenticated.d.ts +1 -1
  70. package/dist/lib/Authenticated.js +60 -0
  71. package/dist/lib/Authenticated.js.map +7 -0
  72. package/dist/lib/authConfig.js +35 -0
  73. package/dist/lib/authConfig.js.map +7 -0
  74. package/{lib → dist/lib}/hooks/index.d.ts +3 -3
  75. package/dist/lib/hooks/index.js +21 -0
  76. package/dist/lib/hooks/index.js.map +7 -0
  77. package/dist/lib/hooks/useAuthConfig.js +33 -0
  78. package/dist/lib/hooks/useAuthConfig.js.map +7 -0
  79. package/{lib/hooks/useCurrentRouteName.d.ts → dist/lib/hooks/useCurrentRouteName/index.d.ts} +5 -5
  80. package/dist/lib/hooks/useCurrentRouteName/index.js +41 -0
  81. package/dist/lib/hooks/useCurrentRouteName/index.js.map +7 -0
  82. package/{esm/types.js → dist/lib/hooks/useCurrentRouteName/index.native.d.ts} +5 -7
  83. package/dist/lib/hooks/useCurrentRouteName/index.native.js +36 -0
  84. package/dist/lib/hooks/useCurrentRouteName/index.native.js.map +7 -0
  85. package/{lib → dist/lib}/hooks/useKeycloak/index.d.ts +2 -2
  86. package/dist/lib/hooks/useKeycloak/index.js +19 -0
  87. package/dist/lib/hooks/useKeycloak/index.js.map +7 -0
  88. package/{lib → dist/lib}/hooks/useKeycloak/useKeycloak.d.ts +2 -2
  89. package/dist/lib/hooks/useKeycloak/useKeycloak.js +63 -0
  90. package/dist/lib/hooks/useKeycloak/useKeycloak.js.map +7 -0
  91. package/{lib → dist/lib}/hooks/useKeycloak/useKeycloak.native.d.ts +4 -4
  92. package/dist/lib/hooks/useKeycloak/useKeycloak.native.js +93 -0
  93. package/dist/lib/hooks/useKeycloak/useKeycloak.native.js.map +7 -0
  94. package/{lib → dist/lib}/hooks/useLogin.d.ts +1 -1
  95. package/dist/lib/hooks/useLogin.js +57 -0
  96. package/dist/lib/hooks/useLogin.js.map +7 -0
  97. package/{lib → dist/lib}/index.d.ts +4 -4
  98. package/dist/lib/index.js +22 -0
  99. package/dist/lib/index.js.map +7 -0
  100. package/{lib → dist/lib}/provider/afterAuth.d.ts +1 -1
  101. package/dist/lib/provider/afterAuth.js +53 -0
  102. package/dist/lib/provider/afterAuth.js.map +7 -0
  103. package/{lib → dist/lib}/provider/index.d.ts +4 -4
  104. package/dist/lib/provider/index.js +61 -0
  105. package/dist/lib/provider/index.js.map +7 -0
  106. package/{lib → dist/lib}/provider/keycloakProvider.d.ts +2 -2
  107. package/dist/lib/provider/keycloakProvider.js +212 -0
  108. package/dist/lib/provider/keycloakProvider.js.map +7 -0
  109. package/{lib → dist/lib}/provider/keycloakProvider.native.d.ts +2 -2
  110. package/dist/lib/provider/keycloakProvider.native.js +55 -0
  111. package/dist/lib/provider/keycloakProvider.native.js.map +7 -0
  112. package/{esm/state/index.js → dist/lib/state/index.d.ts} +8 -13
  113. package/dist/lib/state/index.js +41 -0
  114. package/dist/lib/state/index.js.map +7 -0
  115. package/dist/lib/tsconfig.build.tsbuildinfo +1 -0
  116. package/dist/lib/types.js +27 -0
  117. package/dist/lib/types.js.map +7 -0
  118. package/package.json +42 -61
  119. package/src/@types/coreJsPure.d.ts +2 -2
  120. package/src/@types/expoKeycloakAuth.d.ts +1 -1
  121. package/src/Authenticated.tsx +5 -8
  122. package/src/authConfig.ts +1 -1
  123. package/src/hooks/index.ts +3 -3
  124. package/src/hooks/useAuthConfig.ts +2 -2
  125. package/{esm/hooks/useCurrentRouteName.js → src/hooks/useCurrentRouteName/index.native.ts} +8 -13
  126. package/src/hooks/{useCurrentRouteName.ts → useCurrentRouteName/index.ts} +8 -8
  127. package/src/hooks/useKeycloak/index.ts +2 -6
  128. package/src/hooks/useKeycloak/useKeycloak.native.ts +18 -32
  129. package/src/hooks/useKeycloak/useKeycloak.ts +7 -7
  130. package/src/hooks/useLogin.ts +7 -7
  131. package/src/index.ts +4 -4
  132. package/src/provider/afterAuth.tsx +10 -11
  133. package/src/provider/index.tsx +9 -12
  134. package/src/provider/keycloakProvider.native.tsx +8 -10
  135. package/src/provider/keycloakProvider.tsx +44 -61
  136. package/src/state/index.ts +13 -10
  137. package/esm/Authenticated.js +0 -42
  138. package/esm/Authenticated.js.map +0 -1
  139. package/esm/authConfig.js +0 -30
  140. package/esm/authConfig.js.map +0 -1
  141. package/esm/hooks/index.js +0 -28
  142. package/esm/hooks/index.js.map +0 -1
  143. package/esm/hooks/useAuthConfig.js +0 -30
  144. package/esm/hooks/useAuthConfig.js.map +0 -1
  145. package/esm/hooks/useCurrentRouteName.js.map +0 -1
  146. package/esm/hooks/useKeycloak/index.js +0 -27
  147. package/esm/hooks/useKeycloak/index.js.map +0 -1
  148. package/esm/hooks/useKeycloak/useKeycloak.js +0 -55
  149. package/esm/hooks/useKeycloak/useKeycloak.js.map +0 -1
  150. package/esm/hooks/useKeycloak/useKeycloak.native.js +0 -91
  151. package/esm/hooks/useKeycloak/useKeycloak.native.js.map +0 -1
  152. package/esm/hooks/useLogin.js +0 -50
  153. package/esm/hooks/useLogin.js.map +0 -1
  154. package/esm/index.js +0 -29
  155. package/esm/index.js.map +0 -1
  156. package/esm/package.json +0 -1
  157. package/esm/provider/afterAuth.js +0 -58
  158. package/esm/provider/afterAuth.js.map +0 -1
  159. package/esm/provider/index.js +0 -43
  160. package/esm/provider/index.js.map +0 -1
  161. package/esm/provider/keycloakProvider.js +0 -175
  162. package/esm/provider/keycloakProvider.js.map +0 -1
  163. package/esm/provider/keycloakProvider.native.js +0 -41
  164. package/esm/provider/keycloakProvider.native.js.map +0 -1
  165. package/esm/state/index.js.map +0 -1
  166. package/esm/types.js.map +0 -1
  167. package/lib/Authenticated.js +0 -64
  168. package/lib/Authenticated.js.map +0 -1
  169. package/lib/authConfig.js +0 -51
  170. package/lib/authConfig.js.map +0 -1
  171. package/lib/hooks/index.js +0 -50
  172. package/lib/hooks/index.js.map +0 -1
  173. package/lib/hooks/useAuthConfig.js +0 -48
  174. package/lib/hooks/useAuthConfig.js.map +0 -1
  175. package/lib/hooks/useCurrentRouteName.js +0 -54
  176. package/lib/hooks/useCurrentRouteName.js.map +0 -1
  177. package/lib/hooks/useKeycloak/index.js +0 -30
  178. package/lib/hooks/useKeycloak/index.js.map +0 -1
  179. package/lib/hooks/useKeycloak/useKeycloak.js +0 -71
  180. package/lib/hooks/useKeycloak/useKeycloak.js.map +0 -1
  181. package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -112
  182. package/lib/hooks/useKeycloak/useKeycloak.native.js.map +0 -1
  183. package/lib/hooks/useLogin.js +0 -65
  184. package/lib/hooks/useLogin.js.map +0 -1
  185. package/lib/index.js +0 -60
  186. package/lib/index.js.map +0 -1
  187. package/lib/package.json +0 -1
  188. package/lib/provider/afterAuth.js +0 -78
  189. package/lib/provider/afterAuth.js.map +0 -1
  190. package/lib/provider/index.js +0 -77
  191. package/lib/provider/index.js.map +0 -1
  192. package/lib/provider/keycloakProvider.js +0 -193
  193. package/lib/provider/keycloakProvider.js.map +0 -1
  194. package/lib/provider/keycloakProvider.native.js +0 -61
  195. package/lib/provider/keycloakProvider.native.js.map +0 -1
  196. package/lib/state/index.d.ts +0 -34
  197. package/lib/state/index.js +0 -55
  198. package/lib/state/index.js.map +0 -1
  199. package/lib/tsconfig.build.tsbuildinfo +0 -1
  200. package/lib/types.js +0 -46
  201. package/lib/types.js.map +0 -1
  202. /package/{lib → dist/lib}/authConfig.d.ts +0 -0
  203. /package/{lib → dist/lib}/hooks/useAuthConfig.d.ts +0 -0
  204. /package/{lib → dist/lib}/types.d.ts +0 -0
package/src/authConfig.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import { createContext } from "react";
25
+ import { createContext } from 'react';
26
26
 
27
27
  export const defaultAuthConfig: AuthConfig = {
28
28
  ssr: true,
@@ -22,6 +22,6 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- export * from "./useCurrentRouteName";
26
- export * from "./useKeycloak";
27
- export * from "./useLogin";
25
+ export * from './useCurrentRouteName';
26
+ export * from './useKeycloak';
27
+ export * from './useLogin';
@@ -22,8 +22,8 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import { useContext } from "react";
26
- import { AuthConfigContext } from "../authConfig";
25
+ import { useContext } from 'react';
26
+ import { AuthConfigContext } from '../authConfig';
27
27
 
28
28
  export function useAuthConfig() {
29
29
  return useContext(AuthConfigContext);
@@ -1,13 +1,13 @@
1
1
  /**
2
- * File: /src/hooks/useCurrentRouteName.ts
3
- * Project: app
4
- * File Created: 08-11-2022 08:38:23
2
+ * File: /src/hooks/useCurrentRouteName/index.native.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 24-02-2023 06:30:36
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 28-01-2023 13:47:18
7
+ * Last Modified: 24-02-2023 06:31:25
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
- * Risser Labs LLC (c) Copyright 2021 - 2022
10
+ * Risser Labs LLC (c) Copyright 2022 - 2023
11
11
  *
12
12
  * Licensed under the Apache License, Version 2.0 (the "License");
13
13
  * you may not use this file except in compliance with the License.
@@ -22,16 +22,11 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import { MultiPlatform } from "multiplatform.one";
26
- import { useRoute } from "@react-navigation/native";
27
- import { useRouter } from "next/router";
25
+ import { MultiPlatform } from 'multiplatform.one';
26
+ import { useRoute } from '@react-navigation/native';
27
+
28
28
  export function useCurrentRouteName() {
29
29
  if (MultiPlatform.isStorybook) return null;
30
- if (MultiPlatform.isNext) {
31
- const router = useRouter();
32
- return router.route;
33
- }
34
30
  const route = useRoute();
35
31
  return route.name;
36
32
  }
37
- //# sourceMappingURL=useCurrentRouteName.js.map
@@ -1,13 +1,13 @@
1
1
  /**
2
- * File: /src/hooks/useCurrentRouteName.ts
3
- * Project: app
4
- * File Created: 08-11-2022 08:38:23
2
+ * File: /src/hooks/useCurrentRouteName/index.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 24-02-2023 06:30:32
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 28-01-2023 13:47:18
7
+ * Last Modified: 24-02-2023 06:30:54
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
- * Risser Labs LLC (c) Copyright 2021 - 2022
10
+ * Risser Labs LLC (c) Copyright 2022 - 2023
11
11
  *
12
12
  * Licensed under the Apache License, Version 2.0 (the "License");
13
13
  * you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import { MultiPlatform } from "multiplatform.one";
26
- import { useRoute } from "@react-navigation/native";
27
- import { useRouter } from "next/router";
25
+ import { MultiPlatform } from 'multiplatform.one';
26
+ import { useRoute } from '@react-navigation/native';
27
+ import { useRouter } from 'next/router';
28
28
 
29
29
  export function useCurrentRouteName() {
30
30
  if (MultiPlatform.isStorybook) return null;
@@ -22,12 +22,8 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import type {
26
- KeycloakResourceAccess,
27
- KeycloakRoles,
28
- KeycloakTokenParsed,
29
- } from "keycloak-js";
30
- export * from "./useKeycloak";
25
+ import type { KeycloakResourceAccess, KeycloakRoles, KeycloakTokenParsed } from 'keycloak-js';
26
+ export * from './useKeycloak';
31
27
 
32
28
  export interface IKeycloak {
33
29
  authenticated?: boolean;
@@ -4,7 +4,7 @@
4
4
  * File Created: 08-11-2022 14:10:25
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 28-01-2023 13:47:33
7
+ * Last Modified: 24-02-2023 06:29:25
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
10
  * Risser Labs LLC (c) Copyright 2021 - 2022
@@ -22,30 +22,18 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import atob from "core-js-pure/stable/atob";
26
- import escape from "core-js-pure/stable/escape";
27
- import { AuthRequestPromptOptions, AuthSessionResult } from "expo-auth-session";
28
- import { MultiPlatform } from "multiplatform.one";
29
- import {
30
- KeycloakResourceAccess,
31
- KeycloakRoles,
32
- KeycloakTokenParsed,
33
- } from "keycloak-js";
34
- import { useKeycloak as useExpoKeycloak } from "expo-keycloak-auth";
35
- import { IKeycloak } from "./index";
25
+ import atob from 'core-js-pure/stable/atob';
26
+ import escape from 'core-js-pure/stable/escape';
27
+ import type { AuthRequestPromptOptions, AuthSessionResult } from 'expo-auth-session';
28
+ import type { IKeycloak } from './index';
29
+ import type { KeycloakResourceAccess, KeycloakRoles, KeycloakTokenParsed } from 'keycloak-js';
30
+ import { MultiPlatform } from 'multiplatform.one';
31
+ import { useKeycloak as useExpoKeycloak } from 'expo-keycloak-auth';
36
32
 
37
33
  export function useKeycloak() {
38
34
  if (MultiPlatform.isStorybook) return { authenticated: true } as IKeycloak;
39
- const { ready, login, isLoggedIn, token, logout, refreshToken } =
40
- useExpoKeycloak();
41
- const keycloak = new ExpoKeycloak(
42
- ready,
43
- isLoggedIn,
44
- login,
45
- logout,
46
- token || undefined,
47
- refreshToken || undefined
48
- );
35
+ const { ready, login, isLoggedIn, token, logout, refreshToken } = useExpoKeycloak();
36
+ const keycloak = new ExpoKeycloak(ready, isLoggedIn, login, logout, token || undefined, refreshToken || undefined);
49
37
  return keycloak as IKeycloak;
50
38
  }
51
39
 
@@ -67,12 +55,10 @@ export class ExpoKeycloak implements IKeycloak {
67
55
  constructor(
68
56
  ready: boolean,
69
57
  isLoggedIn: boolean | undefined,
70
- login: (
71
- options?: AuthRequestPromptOptions
72
- ) => Promise<AuthSessionResult | undefined>,
58
+ login: (options?: AuthRequestPromptOptions) => Promise<AuthSessionResult | undefined>,
73
59
  public logout: () => unknown,
74
60
  public token?: string,
75
- public refreshToken?: string
61
+ public refreshToken?: string,
76
62
  ) {
77
63
  if (ready) this.authenticated = isLoggedIn;
78
64
  if (this.authenticated) {
@@ -91,20 +77,20 @@ export class ExpoKeycloak implements IKeycloak {
91
77
  }
92
78
 
93
79
  function decodeToken(str: string) {
94
- str = str.split(".")[1];
95
- str = str.replace(/-/g, "+");
96
- str = str.replace(/_/g, "/");
80
+ str = str.split('.')[1];
81
+ str = str.replace(/-/g, '+');
82
+ str = str.replace(/_/g, '/');
97
83
  switch (str.length % 4) {
98
84
  case 0:
99
85
  break;
100
86
  case 2:
101
- str += "==";
87
+ str += '==';
102
88
  break;
103
89
  case 3:
104
- str += "=";
90
+ str += '=';
105
91
  break;
106
92
  default:
107
- throw "Invalid token";
93
+ throw 'Invalid token';
108
94
  }
109
95
  str = decodeURIComponent(escape(atob(str)));
110
96
  str = JSON.parse(str);
@@ -4,7 +4,7 @@
4
4
  * File Created: 08-11-2022 06:04:59
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 28-01-2023 13:48:24
7
+ * Last Modified: 24-02-2023 06:22:07
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
10
  * Risser Labs LLC (c) Copyright 2021 - 2022
@@ -22,12 +22,12 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import Keycloak from "keycloak-js";
26
- import { MultiPlatform } from "multiplatform.one";
27
- import { useKeycloak as useReactKeycloak } from "@react-keycloak/web";
28
- import { useKeycloak as useSsrKeycloak } from "@react-keycloak/ssr";
29
- import { IKeycloak } from "./index";
30
- import { useAuthConfig } from "../useAuthConfig";
25
+ import type Keycloak from 'keycloak-js';
26
+ import type { IKeycloak } from './index';
27
+ import { MultiPlatform } from 'multiplatform.one';
28
+ import { useAuthConfig } from '../useAuthConfig';
29
+ import { useKeycloak as useReactKeycloak } from '@react-keycloak/web';
30
+ import { useKeycloak as useSsrKeycloak } from '@react-keycloak/ssr';
31
31
 
32
32
  export function useKeycloak() {
33
33
  const authConfig = useAuthConfig();
@@ -4,7 +4,7 @@
4
4
  * File Created: 08-11-2022 08:49:14
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 28-01-2023 13:47:42
7
+ * Last Modified: 24-02-2023 06:22:27
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
10
  * Risser Labs LLC (c) Copyright 2021 - 2022
@@ -22,11 +22,11 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import { useRouter } from "solito/router";
26
- import { MultiPlatform } from "multiplatform.one";
27
- import { useCurrentRouteName } from "./useCurrentRouteName";
28
- import { useKeycloak } from "./useKeycloak/useKeycloak";
29
- import { useAuthConfig } from "./useAuthConfig";
25
+ import { MultiPlatform } from 'multiplatform.one';
26
+ import { useAuthConfig } from './useAuthConfig';
27
+ import { useCurrentRouteName } from './useCurrentRouteName';
28
+ import { useKeycloak } from './useKeycloak/useKeycloak';
29
+ import { useRouter } from 'solito/router';
30
30
 
31
31
  export function useLogin(loginRoute?: string) {
32
32
  if (MultiPlatform.isStorybook) return () => null;
@@ -42,7 +42,7 @@ export function useLogin(loginRoute?: string) {
42
42
  }
43
43
  const url = new URL(`x://${loginRoute}`);
44
44
  const searchParams = new URLSearchParams(url.search);
45
- if (currentRouteName) searchParams.append("backTo", currentRouteName);
45
+ if (currentRouteName) searchParams.append('backTo', currentRouteName);
46
46
  let query = searchParams.toString();
47
47
  if (query.length) query = `?${query}`;
48
48
  router.push(`${url.pathname.substring(2)}${query}`);
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- export * from "./Authenticated";
26
- export * from "./authConfig";
27
- export * from "./hooks";
28
- export * from "./provider";
25
+ export * from './Authenticated';
26
+ export * from './authConfig';
27
+ export * from './hooks';
28
+ export * from './provider';
@@ -22,10 +22,11 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import React, { FC, ReactNode, useEffect } from "react";
26
- import { useKeycloak } from "../hooks";
27
- import { useAuthConfig } from "../hooks/useAuthConfig";
28
- import { useAuthState } from "../state";
25
+ import React, { useEffect } from 'react';
26
+ import type { FC, ReactNode } from 'react';
27
+ import { useAuthConfig } from '../hooks/useAuthConfig';
28
+ import { useAuthState } from '../state';
29
+ import { useKeycloak } from '../hooks';
29
30
 
30
31
  export interface AfterAuthProps {
31
32
  children: ReactNode;
@@ -36,21 +37,19 @@ const logger = console;
36
37
  export const AfterAuth: FC<AfterAuthProps> = ({ children }: AfterAuthProps) => {
37
38
  const authConfig = useAuthConfig();
38
39
  const { token, refreshToken, authenticated } = useKeycloak();
39
- const [, setAuth] = useAuthState();
40
+ const authState = useAuthState();
40
41
 
41
42
  useEffect(() => {
42
43
  if (!authenticated) return;
43
44
  if (token) {
44
- setAuth({
45
- token,
46
- ...(refreshToken ? { refreshToken } : {}),
47
- });
45
+ authState.setToken(token);
46
+ if (refreshToken) authState.setRefreshToken(refreshToken);
48
47
  }
49
48
  }, [token, refreshToken]);
50
49
 
51
50
  if (authConfig.debug) {
52
- logger.debug("authenticated", authenticated);
53
- logger.debug("token", token);
51
+ logger.debug('authenticated', authenticated);
52
+ logger.debug('token', token);
54
53
  }
55
54
  return <>{children}</>;
56
55
  };
@@ -22,21 +22,18 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import React, { FC, useMemo } from "react";
26
- import {
27
- AuthConfig,
28
- AuthConfigContext,
29
- defaultAuthConfig,
30
- } from "../authConfig";
31
- import { KeycloakProvider, KeycloakProviderProps } from "./keycloakProvider";
25
+ import React, { useMemo } from 'react';
26
+ import type { AuthConfig } from '../authConfig';
27
+ import type { FC } from 'react';
28
+ import type { KeycloakProviderProps } from './keycloakProvider';
29
+ import { AuthConfigContext, defaultAuthConfig } from '../authConfig';
30
+ import { KeycloakProvider } from './keycloakProvider';
32
31
 
33
32
  export interface AuthProviderProps extends KeycloakProviderProps {
34
33
  authConfig?: Partial<AuthConfig>;
35
34
  }
36
35
 
37
- export const AuthProvider: FC<AuthProviderProps> = (
38
- props: AuthProviderProps
39
- ) => {
36
+ export const AuthProvider: FC<AuthProviderProps> = (props: AuthProviderProps) => {
40
37
  const { authConfig, debug } = props;
41
38
  const authConfigValue = useMemo(
42
39
  () => ({
@@ -44,7 +41,7 @@ export const AuthProvider: FC<AuthProviderProps> = (
44
41
  ...authConfig,
45
42
  debug: !!debug,
46
43
  }),
47
- []
44
+ [],
48
45
  );
49
46
 
50
47
  return (
@@ -54,4 +51,4 @@ export const AuthProvider: FC<AuthProviderProps> = (
54
51
  );
55
52
  };
56
53
 
57
- export * from "./keycloakProvider";
54
+ export * from './keycloakProvider';
@@ -22,18 +22,16 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import React, { FC } from "react";
26
- import type { KeycloakProviderProps } from "./keycloakProvider";
27
- import { AfterAuth } from "./afterAuth";
28
- import { KeycloakConfig } from "keycloak-js";
29
- import { KeycloakProvider as ExpoKeycloakProvider } from "expo-keycloak-auth";
25
+ import React from 'react';
26
+ import type { FC } from 'react';
27
+ import type { KeycloakConfig } from 'keycloak-js';
28
+ import type { KeycloakProviderProps } from './keycloakProvider';
29
+ import { AfterAuth } from './afterAuth';
30
+ import { KeycloakProvider as ExpoKeycloakProvider } from 'expo-keycloak-auth';
30
31
 
31
- export const KeycloakProvider: FC<KeycloakProviderProps> = ({
32
- children,
33
- keycloakConfig,
34
- }: KeycloakProviderProps) => {
32
+ export const KeycloakProvider: FC<KeycloakProviderProps> = ({ children, keycloakConfig }: KeycloakProviderProps) => {
35
33
  const clonedKeycloakConfig = {
36
- ...(keycloakConfig as Omit<KeycloakConfig, "baseUrl">),
34
+ ...(keycloakConfig as Omit<KeycloakConfig, 'baseUrl'>),
37
35
  url: keycloakConfig.baseUrl,
38
36
  };
39
37
  // @ts-ignore
@@ -22,22 +22,17 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import Keycloak, { KeycloakInitOptions } from "keycloak-js";
26
- import { MultiPlatform } from "multiplatform.one";
27
- import { ReactKeycloakProvider } from "@react-keycloak/web";
28
- import { SSRKeycloakProvider, SSRCookies } from "@react-keycloak/ssr";
29
- import { useRouter } from "next/router";
30
- import React, {
31
- FC,
32
- ReactNode,
33
- useMemo,
34
- useEffect,
35
- useState,
36
- ComponentType,
37
- } from "react";
38
- import { useAuthConfig } from "../hooks/useAuthConfig";
39
- import { useAuthState } from "../state";
40
- import { AfterAuth } from "./afterAuth";
25
+ import Keycloak from 'keycloak-js';
26
+ import React, { useMemo, useEffect, useState } from 'react';
27
+ import type { FC, ReactNode, ComponentType } from 'react';
28
+ import type { KeycloakInitOptions } from 'keycloak-js';
29
+ import { AfterAuth } from './afterAuth';
30
+ import { MultiPlatform } from 'multiplatform.one';
31
+ import { ReactKeycloakProvider } from '@react-keycloak/web';
32
+ import { SSRKeycloakProvider, SSRCookies } from '@react-keycloak/ssr';
33
+ import { useAuthConfig } from '../hooks/useAuthConfig';
34
+ import { useAuthState } from '../state';
35
+ import { useRouter } from 'next/router';
41
36
 
42
37
  export interface KeycloakProviderProps {
43
38
  children: ReactNode;
@@ -59,59 +54,52 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
59
54
  keycloakInitOptions,
60
55
  loadingComponent,
61
56
  }: KeycloakProviderProps) => {
62
- const [auth] = useAuthState();
63
- const LoadingComponent =
64
- loadingComponent || (() => <>{debug ? "authenticating" : null}</>);
57
+ const authState = useAuthState();
58
+ const LoadingComponent = loadingComponent || (() => <>{debug ? 'authenticating' : null}</>);
65
59
  const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
66
60
  const authConfig = useAuthConfig();
67
61
  const [token, setToken] = useState<string | boolean>(
68
- ("token" in query && (query.token?.toString() || true)) ||
69
- auth.token ||
70
- false
62
+ ('token' in query && (query.token?.toString() || true)) || authState.token || false,
71
63
  );
72
64
  const [refreshToken, setRefreshToken] = useState<string | boolean>(
73
- ("refreshToken" in query && (query.refreshToken?.toString() || true)) ||
74
- auth.refreshToken ||
75
- false
65
+ ('refreshToken' in query && (query.refreshToken?.toString() || true)) || authState.refreshToken || false,
76
66
  );
77
67
 
78
68
  useEffect(() => {
79
69
  if (token !== true && refreshToken !== true) return;
80
- if (debug) logger.debug("post message", { type: "LOADED" });
70
+ if (debug) logger.debug('post message', { type: 'LOADED' });
81
71
  (authConfig.messageHandlerKeys || []).forEach((key: string) => {
82
- window?.webkit?.messageHandlers?.[key]?.postMessage(
83
- JSON.stringify({ type: "LOADED" })
84
- );
72
+ window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: 'LOADED' }));
85
73
  });
86
- window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: "LOADED" }));
87
- window?.parent?.postMessage(JSON.stringify({ type: "LOADED" }));
74
+ window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: 'LOADED' }));
75
+ window?.parent?.postMessage(JSON.stringify({ type: 'LOADED' }));
88
76
  }, []);
89
77
 
90
78
  useEffect(() => {
91
79
  if (token !== true) return;
92
80
  const messageCallback = (e: MessageEvent<any>) => {
93
81
  let data = e?.data;
94
- if (typeof data === "string") {
82
+ if (typeof data === 'string') {
95
83
  try {
96
84
  data = JSON.parse(data);
97
85
  } catch (err) {}
98
86
  }
99
- if (debug) logger.debug("received message", data);
87
+ if (debug) logger.debug('received message', data);
100
88
  const message: MessageSchema = data;
101
89
  if (!message.type) return;
102
- if (message.type.toUpperCase() === "TOKEN" && message.payload) {
103
- if (debug) logger.debug("setting token", message.payload);
90
+ if (message.type.toUpperCase() === 'TOKEN' && message.payload) {
91
+ if (debug) logger.debug('setting token', message.payload);
104
92
  setToken(message.payload);
105
93
  }
106
94
  };
107
95
  if (debug)
108
- logger.debug("listening for message", {
109
- type: "TOKEN",
110
- payload: "<some_token>",
96
+ logger.debug('listening for message', {
97
+ type: 'TOKEN',
98
+ payload: '<some_token>',
111
99
  });
112
- window.addEventListener("message", messageCallback);
100
+ window.addEventListener('message', messageCallback);
113
101
  return () => {
114
- window.removeEventListener("message", messageCallback);
102
+ window.removeEventListener('message', messageCallback);
115
103
  };
116
104
  }, []);
117
105
 
@@ -119,39 +107,39 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
119
107
  if (refreshToken !== true) return;
120
108
  const messageCallback = (e: MessageEvent<any>) => {
121
109
  let data = e?.data;
122
- if (typeof data === "string") {
110
+ if (typeof data === 'string') {
123
111
  try {
124
112
  data = JSON.parse(data);
125
113
  } catch (err) {}
126
114
  }
127
- if (debug) logger.debug("received message", data);
115
+ if (debug) logger.debug('received message', data);
128
116
  const message: MessageSchema = data;
129
117
  if (!message.type) return;
130
- if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
131
- if (debug) logger.debug("setting refresh token", message.payload);
118
+ if (message.type.toUpperCase() === 'REFRESH_TOKEN' && message.payload) {
119
+ if (debug) logger.debug('setting refresh token', message.payload);
132
120
  setRefreshToken(message.payload);
133
121
  }
134
122
  };
135
123
  if (debug)
136
- logger.debug("listening for message", {
137
- type: "REFRESH_TOKEN",
138
- payload: "<some_refresh_token>",
124
+ logger.debug('listening for message', {
125
+ type: 'REFRESH_TOKEN',
126
+ payload: '<some_refresh_token>',
139
127
  });
140
- window.addEventListener("message", messageCallback);
128
+ window.addEventListener('message', messageCallback);
141
129
  return () => {
142
- window.removeEventListener("message", messageCallback);
130
+ window.removeEventListener('message', messageCallback);
143
131
  };
144
132
  }, []);
145
133
 
146
134
  const keycloak = useMemo(
147
135
  () =>
148
- typeof window !== "undefined" &&
136
+ typeof window !== 'undefined' &&
149
137
  new Keycloak({
150
138
  url: keycloakConfig.baseUrl,
151
139
  realm: keycloakConfig.realm,
152
140
  clientId: keycloakConfig.clientId,
153
141
  }),
154
- []
142
+ [],
155
143
  );
156
144
 
157
145
  const initOptions = useMemo(() => {
@@ -159,10 +147,9 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
159
147
  ...defaultKeycloakInitOptions,
160
148
  ...keycloakInitOptions,
161
149
  };
162
- if (token && typeof token === "string") {
150
+ if (token && typeof token === 'string') {
163
151
  initOptions.token = token;
164
- if (refreshToken && typeof refreshToken === "string")
165
- initOptions.refreshToken = refreshToken;
152
+ if (refreshToken && typeof refreshToken === 'string') initOptions.refreshToken = refreshToken;
166
153
  initOptions.checkLoginIframe = false;
167
154
  initOptions.onLoad = undefined;
168
155
  }
@@ -189,11 +176,7 @@ export const KeycloakProvider: FC<KeycloakProviderProps> = ({
189
176
  }
190
177
  if (!keycloak) return <>{children}</>;
191
178
  return (
192
- <ReactKeycloakProvider
193
- initOptions={initOptions}
194
- authClient={keycloak}
195
- LoadingComponent={<LoadingComponent />}
196
- >
179
+ <ReactKeycloakProvider initOptions={initOptions} authClient={keycloak} LoadingComponent={<LoadingComponent />}>
197
180
  <AfterAuth>{children}</AfterAuth>
198
181
  </ReactKeycloakProvider>
199
182
  );
@@ -210,8 +193,8 @@ export const defaultKeycloakInitOptions: KeycloakInitOptions = {
210
193
  checkLoginIframe: true,
211
194
  checkLoginIframeInterval: 5,
212
195
  enableLogging: false,
213
- onLoad: "check-sso",
214
- pkceMethod: "S256",
196
+ onLoad: 'check-sso',
197
+ pkceMethod: 'S256',
215
198
  };
216
199
 
217
200
  export interface MessageSchema {
@@ -4,7 +4,7 @@
4
4
  * File Created: 22-11-2022 17:40:53
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * Last Modified: 01-02-2023 14:38:51
7
+ * Last Modified: 24-02-2023 06:26:51
8
8
  * Modified By: Clay Risser
9
9
  * -----
10
10
  * Risser Labs LLC (c) Copyright 2021 - 2022
@@ -22,15 +22,18 @@
22
22
  * limitations under the License.
23
23
  */
24
24
 
25
- import { atom, useRecoilState } from "recoil";
26
- import { persistAtom } from "multiplatform.one/recoil";
25
+ import { createStateStore } from 'multiplatform.one/zustand';
26
+
27
+ const { useStore } = createStateStore(
28
+ 'auth',
29
+ {
30
+ token: '',
31
+ refreshToken: '',
32
+ },
33
+ undefined,
34
+ { persist: true },
35
+ );
27
36
 
28
37
  export function useAuthState() {
29
- return useRecoilState(authState);
38
+ return useStore();
30
39
  }
31
-
32
- export const authState = atom<{ token?: string; refreshToken?: string }>({
33
- key: "auth",
34
- default: {},
35
- effects: [persistAtom],
36
- });