@multiplatform.one/keycloak 0.3.3 → 0.3.5
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/hooks/index.mjs +1 -0
- package/dist/esm/hooks/index.mjs.map +2 -2
- package/dist/esm/hooks/useIsPassedInToken/index.mjs +12 -0
- package/dist/esm/hooks/useIsPassedInToken/index.mjs.map +7 -0
- package/dist/esm/hooks/useIsPassedInToken/index.native.mjs +7 -0
- package/dist/esm/hooks/useIsPassedInToken/index.native.mjs.map +7 -0
- package/dist/esm/provider/index.mjs +3 -1
- package/dist/esm/provider/index.mjs.map +2 -2
- package/dist/esm/provider/keycloakProvider.mjs +12 -7
- package/dist/esm/provider/keycloakProvider.mjs.map +2 -2
- package/dist/jsx/hooks/index.mjs +1 -0
- package/dist/jsx/hooks/index.mjs.map +2 -2
- package/dist/jsx/hooks/useIsPassedInToken/index.mjs +10 -0
- package/dist/jsx/hooks/useIsPassedInToken/index.mjs.map +7 -0
- package/dist/jsx/hooks/useIsPassedInToken/index.native.mjs +5 -0
- package/dist/jsx/hooks/useIsPassedInToken/index.native.mjs.map +7 -0
- package/dist/jsx/provider/index.mjs +3 -1
- package/dist/jsx/provider/index.mjs.map +2 -2
- package/dist/jsx/provider/keycloakProvider.mjs +12 -7
- package/dist/jsx/provider/keycloakProvider.mjs.map +2 -2
- package/dist/lib/hooks/index.d.ts +2 -1
- package/dist/lib/hooks/index.js +2 -0
- package/dist/lib/hooks/index.js.map +2 -2
- package/dist/lib/hooks/useIsPassedInToken/index.d.ts +24 -0
- package/dist/lib/hooks/useIsPassedInToken/index.js +34 -0
- package/dist/lib/hooks/useIsPassedInToken/index.js.map +7 -0
- package/dist/lib/hooks/useIsPassedInToken/index.native.d.ts +24 -0
- package/dist/lib/hooks/useIsPassedInToken/index.native.js +29 -0
- package/dist/lib/hooks/useIsPassedInToken/index.native.js.map +7 -0
- package/dist/lib/provider/index.js +3 -1
- package/dist/lib/provider/index.js.map +2 -2
- package/dist/lib/provider/keycloakProvider.js +12 -7
- package/dist/lib/provider/keycloakProvider.js.map +2 -2
- package/dist/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useIsPassedInToken/index.native.ts +25 -0
- package/src/hooks/useIsPassedInToken/index.ts +31 -0
- package/src/provider/index.tsx +3 -1
- package/src/provider/keycloakProvider.tsx +13 -7
package/package.json
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* File Created: 08-11-2022 06:34:56
|
|
5
5
|
* Author: Clay Risser
|
|
6
6
|
* -----
|
|
7
|
-
* Last Modified:
|
|
7
|
+
* Last Modified: 15-05-2023 01:58:05
|
|
8
8
|
* Modified By: Clay Risser
|
|
9
9
|
* -----
|
|
10
10
|
* Risser Labs LLC (c) Copyright 2021 - 2022
|
|
@@ -23,5 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
export * from './useCurrentRouteName';
|
|
26
|
+
export * from './useIsPassedInToken';
|
|
26
27
|
export * from './useKeycloak';
|
|
27
28
|
export * from './useLogin';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/hooks/useIsPassedInToken/index.native.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 15-05-2023 01:54:48
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 15-05-2023 01:55:27
|
|
8
|
+
* Modified By: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Risser Labs LLC (c) Copyright 2022 - 2023
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const useIsPassedInToken = () => false;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/hooks/useIsPassedInToken/index.ts
|
|
3
|
+
* Project: @multiplatform.one/keycloak
|
|
4
|
+
* File Created: 15-05-2023 01:54:44
|
|
5
|
+
* Author: Clay Risser
|
|
6
|
+
* -----
|
|
7
|
+
* Last Modified: 15-05-2023 01:56:30
|
|
8
|
+
* Modified By: Clay Risser
|
|
9
|
+
* -----
|
|
10
|
+
* Risser Labs LLC (c) Copyright 2022 - 2023
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { MultiPlatform } from 'multiplatform.one';
|
|
26
|
+
import { useRouter } from 'next/router';
|
|
27
|
+
|
|
28
|
+
export function useIsPassedInToken() {
|
|
29
|
+
const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
|
|
30
|
+
return 'idToken' in query || 'token' in query || 'refreshToken' in query;
|
|
31
|
+
}
|
package/src/provider/index.tsx
CHANGED
|
@@ -29,6 +29,7 @@ import type { FC, ComponentType, ReactNode } from 'react';
|
|
|
29
29
|
import type { KeycloakConfig, KeycloakInitOptions } from '@bitspur/keycloak-js';
|
|
30
30
|
import { AuthConfigContext, defaultAuthConfig } from '../authConfig';
|
|
31
31
|
import { KeycloakProvider } from './keycloakProvider';
|
|
32
|
+
import { useIsPassedInToken } from '../hooks';
|
|
32
33
|
// @ts-ignore
|
|
33
34
|
import { config } from 'app/config';
|
|
34
35
|
|
|
@@ -67,6 +68,7 @@ export const AuthProvider: FC<AuthProviderProps> = ({
|
|
|
67
68
|
onTokens,
|
|
68
69
|
...keycloakInitOptions
|
|
69
70
|
}: AuthProviderProps) => {
|
|
71
|
+
const isPassedInToken = useIsPassedInToken();
|
|
70
72
|
const authConfig = useMemo(
|
|
71
73
|
() => ({
|
|
72
74
|
...defaultAuthConfig,
|
|
@@ -74,7 +76,7 @@ export const AuthProvider: FC<AuthProviderProps> = ({
|
|
|
74
76
|
ensureFreshness,
|
|
75
77
|
loginRoute,
|
|
76
78
|
messageHandlerKeys,
|
|
77
|
-
persist: ssr ? false : persist,
|
|
79
|
+
persist: ssr || isPassedInToken ? false : persist,
|
|
78
80
|
ssr,
|
|
79
81
|
}),
|
|
80
82
|
[debug, ensureFreshness, loginRoute, messageHandlerKeys, persist, ssr],
|
|
@@ -33,6 +33,7 @@ import { ReactKeycloakProvider } from '@bitspur/react-keycloak-web';
|
|
|
33
33
|
import { SSRKeycloakProvider, SSRCookies } from '@bitspur/react-keycloak-ssr';
|
|
34
34
|
import { useAuthConfig } from '../hooks/useAuthConfig';
|
|
35
35
|
import { useAuthState } from '../state';
|
|
36
|
+
import { useIsPassedInToken } from '../hooks';
|
|
36
37
|
import { useRouter } from 'next/router';
|
|
37
38
|
|
|
38
39
|
export interface KeycloakProviderProps {
|
|
@@ -80,7 +81,7 @@ export function KeycloakProvider({
|
|
|
80
81
|
refreshToken,
|
|
81
82
|
),
|
|
82
83
|
);
|
|
83
|
-
const
|
|
84
|
+
const isPassedInToken = useIsPassedInToken();
|
|
84
85
|
|
|
85
86
|
useEffect(() => {
|
|
86
87
|
if (token !== true && refreshToken !== true && idToken !== true) return;
|
|
@@ -101,7 +102,7 @@ export function KeycloakProvider({
|
|
|
101
102
|
data = JSON.parse(data);
|
|
102
103
|
} catch (err) {}
|
|
103
104
|
}
|
|
104
|
-
if (debug) logger.debug('received message', data);
|
|
105
|
+
if (debug) logger.debug('received message', JSON.stringify(data));
|
|
105
106
|
const message: MessageSchema = data;
|
|
106
107
|
if (!message.type) return;
|
|
107
108
|
if (message.type.toUpperCase() === 'REFRESH_TOKEN' && message.payload) {
|
|
@@ -130,7 +131,7 @@ export function KeycloakProvider({
|
|
|
130
131
|
data = JSON.parse(data);
|
|
131
132
|
} catch (err) {}
|
|
132
133
|
}
|
|
133
|
-
if (debug) logger.debug('received message', data);
|
|
134
|
+
if (debug) logger.debug('received message', JSON.stringify(data));
|
|
134
135
|
const message: MessageSchema = data;
|
|
135
136
|
if (!message.type) return;
|
|
136
137
|
if (message.type.toUpperCase() === 'TOKEN' && message.payload) {
|
|
@@ -159,7 +160,7 @@ export function KeycloakProvider({
|
|
|
159
160
|
data = JSON.parse(data);
|
|
160
161
|
} catch (err) {}
|
|
161
162
|
}
|
|
162
|
-
if (debug) logger.debug('received message', data);
|
|
163
|
+
if (debug) logger.debug('received message', JSON.stringify(data));
|
|
163
164
|
const message: MessageSchema = data;
|
|
164
165
|
if (!message.type) return;
|
|
165
166
|
if (message.type.toUpperCase() === 'ID_TOKEN' && message.payload) {
|
|
@@ -197,7 +198,7 @@ export function KeycloakProvider({
|
|
|
197
198
|
realm: keycloakConfig.realm,
|
|
198
199
|
clientId: keycloakConfig.clientId,
|
|
199
200
|
}),
|
|
200
|
-
[],
|
|
201
|
+
[keycloakInitOptions, token, refreshToken, idToken],
|
|
201
202
|
);
|
|
202
203
|
|
|
203
204
|
const initOptions = useMemo(() => {
|
|
@@ -210,7 +211,7 @@ export function KeycloakProvider({
|
|
|
210
211
|
initOptions.token = token;
|
|
211
212
|
if (idToken && typeof idToken === 'string') initOptions.idToken = idToken;
|
|
212
213
|
if (refreshToken && typeof refreshToken === 'string') initOptions.refreshToken = refreshToken;
|
|
213
|
-
if (
|
|
214
|
+
if (isPassedInToken) {
|
|
214
215
|
initOptions.checkLoginIframe = false;
|
|
215
216
|
initOptions.onLoad = undefined;
|
|
216
217
|
}
|
|
@@ -218,8 +219,12 @@ export function KeycloakProvider({
|
|
|
218
219
|
return initOptions;
|
|
219
220
|
}, [keycloakInitOptions, token, refreshToken, idToken]);
|
|
220
221
|
|
|
222
|
+
console.log('token', token);
|
|
223
|
+
console.log('idToken', idToken);
|
|
224
|
+
console.log('refreshToken', refreshToken);
|
|
225
|
+
|
|
221
226
|
if (token === true || idToken === true || refreshToken === true) return <LoadingComponent />;
|
|
222
|
-
if (cookies && ssr) {
|
|
227
|
+
if (!isPassedInToken && cookies && ssr) {
|
|
223
228
|
return (
|
|
224
229
|
// @ts-ignore
|
|
225
230
|
<SSRKeycloakProvider
|
|
@@ -240,6 +245,7 @@ export function KeycloakProvider({
|
|
|
240
245
|
</SSRKeycloakProvider>
|
|
241
246
|
);
|
|
242
247
|
}
|
|
248
|
+
console.log('keycloak', keycloak);
|
|
243
249
|
if (!keycloak) return <>{children}</>;
|
|
244
250
|
return (
|
|
245
251
|
<ReactKeycloakProvider
|