@multiplatform.one/keycloak 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/provider/keycloakProvider.mjs +22 -9
- package/dist/esm/provider/keycloakProvider.mjs.map +2 -2
- package/dist/jsx/provider/keycloakProvider.mjs +26 -7
- package/dist/jsx/provider/keycloakProvider.mjs.map +2 -2
- package/dist/lib/Authenticated.d.ts +2 -2
- package/dist/lib/provider/keycloakProvider.d.ts +4 -1
- package/dist/lib/provider/keycloakProvider.js +29 -6
- package/dist/lib/provider/keycloakProvider.js.map +2 -2
- package/dist/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +15 -14
- package/src/provider/keycloakProvider.tsx +28 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/keycloak",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "keycloak client for multiplatform.one ecosystem",
|
|
5
5
|
"main": "dist/lib",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -56,25 +56,25 @@
|
|
|
56
56
|
"react-native": "~0.68.5"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@babel/preset-env": "^7.21.
|
|
59
|
+
"@babel/preset-env": "^7.21.5",
|
|
60
60
|
"@babel/preset-flow": "^7.21.4",
|
|
61
61
|
"@babel/preset-react": "^7.18.6",
|
|
62
|
-
"@babel/preset-typescript": "^7.21.
|
|
62
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
63
63
|
"@react-native-async-storage/async-storage": "^1.18.1",
|
|
64
64
|
"@react-navigation/native": "^6.1.6",
|
|
65
65
|
"@types/eslint": "^8.37.0",
|
|
66
66
|
"@types/jest": "^29.5.1",
|
|
67
67
|
"@types/lodash.camelcase": "^4.3.7",
|
|
68
68
|
"@types/lodash.startcase": "^4.4.7",
|
|
69
|
-
"@types/react": "18.2.
|
|
70
|
-
"@types/react-native": "0.
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^5.59.
|
|
72
|
-
"@typescript-eslint/parser": "^5.59.
|
|
69
|
+
"@types/react": "18.2.6",
|
|
70
|
+
"@types/react-native": "0.72.0",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
|
72
|
+
"@typescript-eslint/parser": "^5.59.5",
|
|
73
73
|
"babel-plugin-fully-specified": "^1.3.0",
|
|
74
74
|
"cspell": "^6.31.1",
|
|
75
75
|
"esbuild": "^0.17.18",
|
|
76
76
|
"esbuild-plugin-babel": "^0.2.3",
|
|
77
|
-
"eslint": "^8.
|
|
77
|
+
"eslint": "^8.40.0",
|
|
78
78
|
"eslint-config-alloy": "^5.0.0",
|
|
79
79
|
"eslint-plugin-react": "^7.32.2",
|
|
80
80
|
"eslint-plugin-spellcheck": "^0.0.20",
|
|
@@ -82,11 +82,11 @@
|
|
|
82
82
|
"jest": "^29.5.0",
|
|
83
83
|
"jest-sonar-reporter": "^2.0.0",
|
|
84
84
|
"lockfile-lint": "^4.10.1",
|
|
85
|
-
"multiplatform.one": "^0.5.
|
|
86
|
-
"next": "^13.
|
|
85
|
+
"multiplatform.one": "^0.5.30",
|
|
86
|
+
"next": "^13.4.2",
|
|
87
87
|
"prettier": "^2.8.8",
|
|
88
88
|
"react": "^18.2.0",
|
|
89
|
-
"react-native": "~0.71.
|
|
89
|
+
"react-native": "~0.71.8",
|
|
90
90
|
"ts-node": "^10.9.1",
|
|
91
91
|
"typescript": "^5.0.4"
|
|
92
92
|
},
|
|
@@ -117,12 +117,13 @@
|
|
|
117
117
|
"@bitspur/keycloak-js": "21.1.0-3",
|
|
118
118
|
"@bitspur/react-keycloak-ssr": "4.0.1",
|
|
119
119
|
"@bitspur/react-keycloak-web": "4.0.1",
|
|
120
|
-
"core-js-pure": "^3.30.
|
|
120
|
+
"core-js-pure": "^3.30.2",
|
|
121
121
|
"expo-auth-session": "^4.0.3",
|
|
122
|
-
"solito": "^3.2.
|
|
122
|
+
"solito": "^3.2.6"
|
|
123
123
|
},
|
|
124
124
|
"resolutions": {
|
|
125
|
-
"expo-keycloak-auth@1.0.14": "patch:expo-keycloak-auth@npm%3A1.0.14#./.yarn/patches/expo-keycloak-auth-npm-1.0.14-78201597ce.patch"
|
|
125
|
+
"expo-keycloak-auth@1.0.14": "patch:expo-keycloak-auth@npm%3A1.0.14#./.yarn/patches/expo-keycloak-auth-npm-1.0.14-78201597ce.patch",
|
|
126
|
+
"@types/react": "^18.2.6"
|
|
126
127
|
},
|
|
127
128
|
"prettier": "eslint-config-alloy/.prettierrc.js"
|
|
128
129
|
}
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import Keycloak from '@bitspur/keycloak-js';
|
|
26
|
-
import React, { useMemo, useEffect, useState } from 'react';
|
|
26
|
+
import React, { useMemo, useEffect, useState, useCallback } from 'react';
|
|
27
|
+
import type { AuthClientEvent, AuthClientError, AuthClientTokens } from '@bitspur/react-keycloak-core';
|
|
27
28
|
import type { KeycloakInitOptions } from '@bitspur/keycloak-js';
|
|
28
29
|
import type { ReactNode, ComponentType } from 'react';
|
|
29
30
|
import { AfterAuth } from './afterAuth';
|
|
@@ -42,6 +43,8 @@ export interface KeycloakProviderProps {
|
|
|
42
43
|
keycloakConfig: KeycloakConfig;
|
|
43
44
|
keycloakInitOptions?: KeycloakInitOptions;
|
|
44
45
|
loadingComponent?: ComponentType;
|
|
46
|
+
onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;
|
|
47
|
+
onTokens?: (tokens: AuthClientTokens) => void;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
const logger = console;
|
|
@@ -53,6 +56,8 @@ export function KeycloakProvider({
|
|
|
53
56
|
keycloakConfig,
|
|
54
57
|
keycloakInitOptions,
|
|
55
58
|
loadingComponent,
|
|
59
|
+
onEvent,
|
|
60
|
+
onTokens,
|
|
56
61
|
}: KeycloakProviderProps) {
|
|
57
62
|
const authState = useAuthState();
|
|
58
63
|
const LoadingComponent = loadingComponent || (() => <>{debug ? 'authenticating' : null}</>);
|
|
@@ -169,6 +174,15 @@ export function KeycloakProvider({
|
|
|
169
174
|
};
|
|
170
175
|
}, []);
|
|
171
176
|
|
|
177
|
+
const handleEvent = useCallback((eventType: AuthClientEvent, error?: AuthClientError) => {
|
|
178
|
+
if (error) {
|
|
179
|
+
const err: Error & { errorDescription?: string } = new Error(error.error);
|
|
180
|
+
err.errorDescription = error.error_description;
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
if (onEvent) onEvent(eventType, error);
|
|
184
|
+
}, []);
|
|
185
|
+
|
|
172
186
|
const keycloak = useMemo(
|
|
173
187
|
() =>
|
|
174
188
|
typeof window !== 'undefined' &&
|
|
@@ -203,14 +217,16 @@ export function KeycloakProvider({
|
|
|
203
217
|
return (
|
|
204
218
|
// @ts-ignore
|
|
205
219
|
<SSRKeycloakProvider
|
|
220
|
+
LoadingComponent={<LoadingComponent />}
|
|
206
221
|
initOptions={initOptions}
|
|
222
|
+
onEvent={handleEvent}
|
|
223
|
+
onTokens={onTokens}
|
|
224
|
+
persistor={SSRCookies(cookies)}
|
|
207
225
|
keycloakConfig={{
|
|
208
|
-
url: keycloakConfig.baseUrl,
|
|
209
|
-
realm: keycloakConfig.realm,
|
|
210
226
|
clientId: keycloakConfig.clientId,
|
|
227
|
+
realm: keycloakConfig.realm,
|
|
228
|
+
url: keycloakConfig.baseUrl,
|
|
211
229
|
}}
|
|
212
|
-
persistor={SSRCookies(cookies)}
|
|
213
|
-
LoadingComponent={<LoadingComponent />}
|
|
214
230
|
>
|
|
215
231
|
<AfterAuth>{children}</AfterAuth>
|
|
216
232
|
</SSRKeycloakProvider>
|
|
@@ -218,7 +234,13 @@ export function KeycloakProvider({
|
|
|
218
234
|
}
|
|
219
235
|
if (!keycloak) return <>{children}</>;
|
|
220
236
|
return (
|
|
221
|
-
<ReactKeycloakProvider
|
|
237
|
+
<ReactKeycloakProvider
|
|
238
|
+
LoadingComponent={<LoadingComponent />}
|
|
239
|
+
authClient={keycloak}
|
|
240
|
+
initOptions={initOptions}
|
|
241
|
+
onEvent={handleEvent}
|
|
242
|
+
onTokens={onTokens}
|
|
243
|
+
>
|
|
222
244
|
<AfterAuth>{children}</AfterAuth>
|
|
223
245
|
</ReactKeycloakProvider>
|
|
224
246
|
);
|