@multiplatform.one/keycloak 0.2.10 → 0.2.12
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 +24 -9
- package/dist/esm/provider/keycloakProvider.mjs.map +2 -2
- package/dist/jsx/provider/keycloakProvider.mjs +28 -7
- package/dist/jsx/provider/keycloakProvider.mjs.map +2 -2
- package/dist/lib/provider/keycloakProvider.d.ts +4 -1
- package/dist/lib/provider/keycloakProvider.js +31 -6
- package/dist/lib/provider/keycloakProvider.js.map +2 -2
- package/dist/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/provider/keycloakProvider.tsx +29 -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.12",
|
|
4
4
|
"description": "keycloak client for multiplatform.one ecosystem",
|
|
5
5
|
"main": "dist/lib",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@typescript-eslint/parser": "^5.59.5",
|
|
73
73
|
"babel-plugin-fully-specified": "^1.3.0",
|
|
74
74
|
"cspell": "^6.31.1",
|
|
75
|
-
"esbuild": "^0.17.
|
|
75
|
+
"esbuild": "^0.17.19",
|
|
76
76
|
"esbuild-plugin-babel": "^0.2.3",
|
|
77
77
|
"eslint": "^8.40.0",
|
|
78
78
|
"eslint-config-alloy": "^5.0.0",
|
|
@@ -115,10 +115,10 @@
|
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
117
|
"@bitspur/keycloak-js": "21.1.0-3",
|
|
118
|
-
"@bitspur/react-keycloak-ssr": "4.0.
|
|
119
|
-
"@bitspur/react-keycloak-web": "4.0.
|
|
118
|
+
"@bitspur/react-keycloak-ssr": "4.0.2",
|
|
119
|
+
"@bitspur/react-keycloak-web": "4.0.2",
|
|
120
120
|
"core-js-pure": "^3.30.2",
|
|
121
|
-
"expo-auth-session": "^4.0
|
|
121
|
+
"expo-auth-session": "^4.1.0",
|
|
122
122
|
"solito": "^3.2.6"
|
|
123
123
|
},
|
|
124
124
|
"resolutions": {
|
|
@@ -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,16 @@ export function KeycloakProvider({
|
|
|
169
174
|
};
|
|
170
175
|
}, []);
|
|
171
176
|
|
|
177
|
+
const handleEvent = useCallback((eventType: AuthClientEvent, error?: AuthClientError) => {
|
|
178
|
+
if (error) {
|
|
179
|
+
if (typeof error === 'string') throw new Error(error);
|
|
180
|
+
const err: Error & { errorDescription?: string } = new Error(error.error);
|
|
181
|
+
err.errorDescription = error.error_description;
|
|
182
|
+
throw err;
|
|
183
|
+
}
|
|
184
|
+
if (onEvent) onEvent(eventType, error);
|
|
185
|
+
}, []);
|
|
186
|
+
|
|
172
187
|
const keycloak = useMemo(
|
|
173
188
|
() =>
|
|
174
189
|
typeof window !== 'undefined' &&
|
|
@@ -203,14 +218,16 @@ export function KeycloakProvider({
|
|
|
203
218
|
return (
|
|
204
219
|
// @ts-ignore
|
|
205
220
|
<SSRKeycloakProvider
|
|
221
|
+
LoadingComponent={<LoadingComponent />}
|
|
206
222
|
initOptions={initOptions}
|
|
223
|
+
onEvent={handleEvent}
|
|
224
|
+
onTokens={onTokens}
|
|
225
|
+
persistor={SSRCookies(cookies)}
|
|
207
226
|
keycloakConfig={{
|
|
208
|
-
url: keycloakConfig.baseUrl,
|
|
209
|
-
realm: keycloakConfig.realm,
|
|
210
227
|
clientId: keycloakConfig.clientId,
|
|
228
|
+
realm: keycloakConfig.realm,
|
|
229
|
+
url: keycloakConfig.baseUrl,
|
|
211
230
|
}}
|
|
212
|
-
persistor={SSRCookies(cookies)}
|
|
213
|
-
LoadingComponent={<LoadingComponent />}
|
|
214
231
|
>
|
|
215
232
|
<AfterAuth>{children}</AfterAuth>
|
|
216
233
|
</SSRKeycloakProvider>
|
|
@@ -218,7 +235,13 @@ export function KeycloakProvider({
|
|
|
218
235
|
}
|
|
219
236
|
if (!keycloak) return <>{children}</>;
|
|
220
237
|
return (
|
|
221
|
-
<ReactKeycloakProvider
|
|
238
|
+
<ReactKeycloakProvider
|
|
239
|
+
LoadingComponent={<LoadingComponent />}
|
|
240
|
+
authClient={keycloak}
|
|
241
|
+
initOptions={initOptions}
|
|
242
|
+
onEvent={handleEvent}
|
|
243
|
+
onTokens={onTokens}
|
|
244
|
+
>
|
|
222
245
|
<AfterAuth>{children}</AfterAuth>
|
|
223
246
|
</ReactKeycloakProvider>
|
|
224
247
|
);
|