@react-keycloak-refork/core 6.0.0 → 8.0.2
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/LICENSE.md +24 -24
- package/README.md +149 -150
- package/lib/context.d.ts +23 -24
- package/lib/context.js +23 -23
- package/lib/index.d.ts +3 -3
- package/lib/index.js +4 -4
- package/lib/provider.d.ts +127 -132
- package/lib/provider.js +146 -145
- package/lib/provider.js.map +1 -1
- package/lib/types.d.ts +80 -80
- package/lib/types.js +1 -1
- package/lib-commonjs/context.d.ts +23 -24
- package/lib-commonjs/context.js +26 -27
- package/lib-commonjs/context.js.map +1 -1
- package/lib-commonjs/index.d.ts +3 -3
- package/lib-commonjs/index.js +20 -20
- package/lib-commonjs/provider.d.ts +127 -132
- package/lib-commonjs/provider.js +185 -175
- package/lib-commonjs/provider.js.map +1 -1
- package/lib-commonjs/types.d.ts +80 -80
- package/lib-commonjs/types.js +2 -2
- package/package.json +11 -7
package/lib/types.d.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
export interface AuthClientError {
|
|
2
|
-
error: string;
|
|
3
|
-
error_description: string;
|
|
4
|
-
}
|
|
5
|
-
export interface AuthClientInitOptions {
|
|
6
|
-
[paramName: string]: any;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* A client for the Auth server.
|
|
10
|
-
*/
|
|
11
|
-
export interface AuthClient {
|
|
12
|
-
/**
|
|
13
|
-
* The base64 encoded token that can be sent in the Authorization header in
|
|
14
|
-
* requests to services.
|
|
15
|
-
*/
|
|
16
|
-
token?: string;
|
|
17
|
-
/**
|
|
18
|
-
* The base64 encoded refresh token that can be used to retrieve a new token.
|
|
19
|
-
*/
|
|
20
|
-
refreshToken?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The base64 encoded ID token.
|
|
23
|
-
*/
|
|
24
|
-
idToken?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Called when the adapter is initialized.
|
|
27
|
-
*/
|
|
28
|
-
onReady?(authenticated?: boolean): void;
|
|
29
|
-
/**
|
|
30
|
-
* Called when a user is successfully authenticated.
|
|
31
|
-
*/
|
|
32
|
-
onAuthSuccess?(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Called if there was an error during authentication.
|
|
35
|
-
*/
|
|
36
|
-
onAuthError?(errorData: AuthClientError): void;
|
|
37
|
-
/**
|
|
38
|
-
* Called when the token is refreshed.
|
|
39
|
-
*/
|
|
40
|
-
onAuthRefreshSuccess?(): void;
|
|
41
|
-
/**
|
|
42
|
-
* Called if there was an error while trying to refresh the token.
|
|
43
|
-
*/
|
|
44
|
-
onAuthRefreshError?(): void;
|
|
45
|
-
/**
|
|
46
|
-
* Called if the user is logged out (will only be called if the session
|
|
47
|
-
* status iframe is enabled, or in Cordova mode).
|
|
48
|
-
*/
|
|
49
|
-
onAuthLogout?(): void;
|
|
50
|
-
/**
|
|
51
|
-
* Called when the access token is expired. If a refresh token is available
|
|
52
|
-
* the token can be refreshed with Auth#updateToken, or in cases where
|
|
53
|
-
* it's not (ie. with implicit flow) you can redirect to login screen to
|
|
54
|
-
* obtain a new access token.
|
|
55
|
-
*/
|
|
56
|
-
onTokenExpired?(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Called to initialize the adapter.
|
|
59
|
-
* @param initOptions Initialization options.
|
|
60
|
-
* @returns A promise to set functions to be invoked on success or error.
|
|
61
|
-
*/
|
|
62
|
-
init(initOptions: AuthClientInitOptions): Promise<boolean>;
|
|
63
|
-
/**
|
|
64
|
-
* If the token expires within `minValidity` seconds, the token is refreshed.
|
|
65
|
-
* If the session status iframe is enabled, the session status is also
|
|
66
|
-
* checked.
|
|
67
|
-
*
|
|
68
|
-
* @returns A promise to set functions that can be invoked if the token is
|
|
69
|
-
* still valid, or if the token is no longer valid.
|
|
70
|
-
*/
|
|
71
|
-
updateToken(minValidity: number): Promise<boolean>;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Set of tokens provided by AuthClient
|
|
75
|
-
*/
|
|
76
|
-
export type AuthClientTokens = Pick<AuthClient, 'idToken' | 'refreshToken' | 'token'>;
|
|
77
|
-
/**
|
|
78
|
-
* ReactAuth event types
|
|
79
|
-
*/
|
|
80
|
-
export type AuthClientEvent = 'onReady' | 'onInitError' | 'onAuthSuccess' | 'onAuthError' | 'onAuthRefreshSuccess' | 'onAuthRefreshError' | 'onAuthLogout' | 'onTokenExpired';
|
|
1
|
+
export interface AuthClientError {
|
|
2
|
+
error: string;
|
|
3
|
+
error_description: string;
|
|
4
|
+
}
|
|
5
|
+
export interface AuthClientInitOptions {
|
|
6
|
+
[paramName: string]: any;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A client for the Auth server.
|
|
10
|
+
*/
|
|
11
|
+
export interface AuthClient {
|
|
12
|
+
/**
|
|
13
|
+
* The base64 encoded token that can be sent in the Authorization header in
|
|
14
|
+
* requests to services.
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The base64 encoded refresh token that can be used to retrieve a new token.
|
|
19
|
+
*/
|
|
20
|
+
refreshToken?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The base64 encoded ID token.
|
|
23
|
+
*/
|
|
24
|
+
idToken?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Called when the adapter is initialized.
|
|
27
|
+
*/
|
|
28
|
+
onReady?(authenticated?: boolean): void;
|
|
29
|
+
/**
|
|
30
|
+
* Called when a user is successfully authenticated.
|
|
31
|
+
*/
|
|
32
|
+
onAuthSuccess?(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Called if there was an error during authentication.
|
|
35
|
+
*/
|
|
36
|
+
onAuthError?(errorData: AuthClientError): void;
|
|
37
|
+
/**
|
|
38
|
+
* Called when the token is refreshed.
|
|
39
|
+
*/
|
|
40
|
+
onAuthRefreshSuccess?(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Called if there was an error while trying to refresh the token.
|
|
43
|
+
*/
|
|
44
|
+
onAuthRefreshError?(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Called if the user is logged out (will only be called if the session
|
|
47
|
+
* status iframe is enabled, or in Cordova mode).
|
|
48
|
+
*/
|
|
49
|
+
onAuthLogout?(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Called when the access token is expired. If a refresh token is available
|
|
52
|
+
* the token can be refreshed with Auth#updateToken, or in cases where
|
|
53
|
+
* it's not (ie. with implicit flow) you can redirect to login screen to
|
|
54
|
+
* obtain a new access token.
|
|
55
|
+
*/
|
|
56
|
+
onTokenExpired?(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Called to initialize the adapter.
|
|
59
|
+
* @param initOptions Initialization options.
|
|
60
|
+
* @returns A promise to set functions to be invoked on success or error.
|
|
61
|
+
*/
|
|
62
|
+
init(initOptions: AuthClientInitOptions): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* If the token expires within `minValidity` seconds, the token is refreshed.
|
|
65
|
+
* If the session status iframe is enabled, the session status is also
|
|
66
|
+
* checked.
|
|
67
|
+
*
|
|
68
|
+
* @returns A promise to set functions that can be invoked if the token is
|
|
69
|
+
* still valid, or if the token is no longer valid.
|
|
70
|
+
*/
|
|
71
|
+
updateToken(minValidity: number): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set of tokens provided by AuthClient
|
|
75
|
+
*/
|
|
76
|
+
export type AuthClientTokens = Pick<AuthClient, 'idToken' | 'refreshToken' | 'token'>;
|
|
77
|
+
/**
|
|
78
|
+
* ReactAuth event types
|
|
79
|
+
*/
|
|
80
|
+
export type AuthClientEvent = 'onReady' | 'onInitError' | 'onAuthSuccess' | 'onAuthError' | 'onAuthRefreshSuccess' | 'onAuthRefreshError' | 'onAuthLogout' | 'onTokenExpired';
|
package/lib/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
export default createAuthContext;
|
|
1
|
+
import { AuthClient } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Auth Context props
|
|
4
|
+
*/
|
|
5
|
+
export type IAuthContextProps<T extends AuthClient> = {
|
|
6
|
+
/**
|
|
7
|
+
* The single AuthClient of your application.
|
|
8
|
+
*/
|
|
9
|
+
authClient?: T;
|
|
10
|
+
/**
|
|
11
|
+
* Boolean indicating whenever the AuthClient has been initialized by AuthProvider
|
|
12
|
+
*/
|
|
13
|
+
initialized: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Create a React context containing an AuthClient instance.
|
|
17
|
+
*
|
|
18
|
+
* @param {IAuthContextProps} initialContext initial context value.
|
|
19
|
+
*
|
|
20
|
+
* @returns {React.Context} the ReactKeycloak context.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createAuthContext<T extends AuthClient>(initialContext?: Partial<IAuthContextProps<T>>): React.Context<IAuthContextProps<T>>;
|
|
23
|
+
export default createAuthContext;
|
package/lib-commonjs/context.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.createAuthContext =
|
|
15
|
-
var react_1 = require("react");
|
|
16
|
-
/**
|
|
17
|
-
* Create a React context containing an AuthClient instance.
|
|
18
|
-
*
|
|
19
|
-
* @param {IAuthContextProps} initialContext initial context value.
|
|
20
|
-
*
|
|
21
|
-
* @returns {React.Context} the ReactKeycloak context.
|
|
22
|
-
*/
|
|
23
|
-
function createAuthContext(initialContext) {
|
|
24
|
-
return (0, react_1.createContext)(__assign({ initialized: false }, initialContext));
|
|
25
|
-
}
|
|
26
|
-
exports.
|
|
27
|
-
exports.default = createAuthContext;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createAuthContext = createAuthContext;
|
|
15
|
+
var react_1 = require("react");
|
|
16
|
+
/**
|
|
17
|
+
* Create a React context containing an AuthClient instance.
|
|
18
|
+
*
|
|
19
|
+
* @param {IAuthContextProps} initialContext initial context value.
|
|
20
|
+
*
|
|
21
|
+
* @returns {React.Context} the ReactKeycloak context.
|
|
22
|
+
*/
|
|
23
|
+
function createAuthContext(initialContext) {
|
|
24
|
+
return (0, react_1.createContext)(__assign({ initialized: false }, initialContext));
|
|
25
|
+
}
|
|
26
|
+
exports.default = createAuthContext;
|
|
28
27
|
//# sourceMappingURL=context.js.map
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
"@react-keycloak-refork\\core\\context.ts"
|
|
7
7
|
],
|
|
8
8
|
"names": [],
|
|
9
|
-
"mappings": "
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;AA0BA,8CAOC;AAjCD,+BAAqC;AAmBrC;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,cAA8C;IAE9C,OAAO,IAAA,qBAAa,aAClB,WAAW,EAAE,KAAK,IACf,cAAc,EACjB,CAAA;AACJ,CAAC;AAED,kBAAe,iBAAiB,CAAA"
|
|
10
10
|
}
|
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './context';
|
|
2
|
-
export * from './provider';
|
|
3
|
-
export * from './types';
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './provider';
|
|
3
|
+
export * from './types';
|
package/lib-commonjs/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* istanbul ignore file */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./context"), exports);
|
|
19
|
-
__exportStar(require("./provider"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./context"), exports);
|
|
19
|
+
__exportStar(require("./provider"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,132 +1,127 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { IAuthContextProps } from './context';
|
|
4
|
-
import { AuthClient, AuthClientError, AuthClientEvent, AuthClientInitOptions, AuthClientTokens } from './types';
|
|
5
|
-
/**
|
|
6
|
-
* Props that can be passed to AuthProvider
|
|
7
|
-
*/
|
|
8
|
-
export type AuthProviderProps<T extends AuthClient> = {
|
|
9
|
-
/**
|
|
10
|
-
* The single AuthClient instance to be used by your application.
|
|
11
|
-
*/
|
|
12
|
-
authClient: T;
|
|
13
|
-
/**
|
|
14
|
-
* The single AuthClient instance to be used by your application.
|
|
15
|
-
*/
|
|
16
|
-
children: React.JSXElementConstructor<{
|
|
17
|
-
children: React.ReactElement | ReactNode | Element;
|
|
18
|
-
}> | any;
|
|
19
|
-
/**
|
|
20
|
-
* A flag to enable automatic token refresh. Defaults to true.
|
|
21
|
-
* This is useful if you need to disable it (not recommended).
|
|
22
|
-
*
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
autoRefreshToken?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* The config to be used when initializing AuthClient instance.
|
|
28
|
-
*/
|
|
29
|
-
initOptions?: AuthClientInitOptions;
|
|
30
|
-
/**
|
|
31
|
-
* An optional loading check function to customize LoadingComponent display condition.
|
|
32
|
-
* Return `true` to display LoadingComponent, `false` to hide it.
|
|
33
|
-
*
|
|
34
|
-
* @param authClient the current AuthClient instance.
|
|
35
|
-
*
|
|
36
|
-
* @returns {boolean} Set to true to display LoadingComponent, false to hide it.
|
|
37
|
-
*/
|
|
38
|
-
isLoadingCheck?: (authClient: T) => boolean;
|
|
39
|
-
/**
|
|
40
|
-
* An optional component to display while AuthClient instance is being initialized.
|
|
41
|
-
*/
|
|
42
|
-
LoadingComponent?: JSX.Element;
|
|
43
|
-
/**
|
|
44
|
-
* An optional function to receive AuthClient events as they happen.
|
|
45
|
-
*/
|
|
46
|
-
onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;
|
|
47
|
-
/**
|
|
48
|
-
* An optional function to receive AuthClient tokens when changed.
|
|
49
|
-
*
|
|
50
|
-
* @param {AuthClientTokens} tokens The current AuthClient tokens set.
|
|
51
|
-
*/
|
|
52
|
-
onTokens?: (tokens: AuthClientTokens) => void;
|
|
53
|
-
};
|
|
54
|
-
type AuthProviderState = {
|
|
55
|
-
initialized: boolean;
|
|
56
|
-
isAuthenticated: boolean;
|
|
57
|
-
isLoading: boolean;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Create an AuthProvider component to wrap a React app with, it will take care of common AuthClient
|
|
61
|
-
* lifecycle handling (such as initialization and token refresh).
|
|
62
|
-
*
|
|
63
|
-
* @param AuthContext the Auth context to be used by the created AuthProvider
|
|
64
|
-
*
|
|
65
|
-
* @returns the AuthProvider component
|
|
66
|
-
*/
|
|
67
|
-
export declare function createAuthProvider<T extends AuthClient>(AuthContext: React.Context<IAuthContextProps<T>>): {
|
|
68
|
-
new (props: AuthProviderProps<T>): {
|
|
69
|
-
state: {
|
|
70
|
-
initialized: boolean;
|
|
71
|
-
isAuthenticated: boolean;
|
|
72
|
-
isLoading: boolean;
|
|
73
|
-
};
|
|
74
|
-
componentDidMount(): void;
|
|
75
|
-
componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
|
|
76
|
-
init(): void;
|
|
77
|
-
onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
|
|
78
|
-
updateState: (event: AuthClientEvent) => () => void;
|
|
79
|
-
refreshToken: (event: AuthClientEvent) => () => void;
|
|
80
|
-
render(): React.JSX.Element;
|
|
81
|
-
context: unknown;
|
|
82
|
-
setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
|
|
83
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
84
|
-
readonly props: Readonly<AuthProviderProps<T>>;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
|
|
129
|
-
};
|
|
130
|
-
contextType?: React.Context<any> | undefined;
|
|
131
|
-
};
|
|
132
|
-
export default createAuthProvider;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { IAuthContextProps } from './context';
|
|
4
|
+
import { AuthClient, AuthClientError, AuthClientEvent, AuthClientInitOptions, AuthClientTokens } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Props that can be passed to AuthProvider
|
|
7
|
+
*/
|
|
8
|
+
export type AuthProviderProps<T extends AuthClient> = {
|
|
9
|
+
/**
|
|
10
|
+
* The single AuthClient instance to be used by your application.
|
|
11
|
+
*/
|
|
12
|
+
authClient: T;
|
|
13
|
+
/**
|
|
14
|
+
* The single AuthClient instance to be used by your application.
|
|
15
|
+
*/
|
|
16
|
+
children: React.JSXElementConstructor<{
|
|
17
|
+
children: React.ReactElement | ReactNode | Element;
|
|
18
|
+
}> | any;
|
|
19
|
+
/**
|
|
20
|
+
* A flag to enable automatic token refresh. Defaults to true.
|
|
21
|
+
* This is useful if you need to disable it (not recommended).
|
|
22
|
+
*
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
autoRefreshToken?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The config to be used when initializing AuthClient instance.
|
|
28
|
+
*/
|
|
29
|
+
initOptions?: AuthClientInitOptions;
|
|
30
|
+
/**
|
|
31
|
+
* An optional loading check function to customize LoadingComponent display condition.
|
|
32
|
+
* Return `true` to display LoadingComponent, `false` to hide it.
|
|
33
|
+
*
|
|
34
|
+
* @param authClient the current AuthClient instance.
|
|
35
|
+
*
|
|
36
|
+
* @returns {boolean} Set to true to display LoadingComponent, false to hide it.
|
|
37
|
+
*/
|
|
38
|
+
isLoadingCheck?: (authClient: T) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* An optional component to display while AuthClient instance is being initialized.
|
|
41
|
+
*/
|
|
42
|
+
LoadingComponent?: React.JSX.Element;
|
|
43
|
+
/**
|
|
44
|
+
* An optional function to receive AuthClient events as they happen.
|
|
45
|
+
*/
|
|
46
|
+
onEvent?: (eventType: AuthClientEvent, error?: AuthClientError) => void;
|
|
47
|
+
/**
|
|
48
|
+
* An optional function to receive AuthClient tokens when changed.
|
|
49
|
+
*
|
|
50
|
+
* @param {AuthClientTokens} tokens The current AuthClient tokens set.
|
|
51
|
+
*/
|
|
52
|
+
onTokens?: (tokens: AuthClientTokens) => void;
|
|
53
|
+
};
|
|
54
|
+
type AuthProviderState = {
|
|
55
|
+
initialized: boolean;
|
|
56
|
+
isAuthenticated: boolean;
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Create an AuthProvider component to wrap a React app with, it will take care of common AuthClient
|
|
61
|
+
* lifecycle handling (such as initialization and token refresh).
|
|
62
|
+
*
|
|
63
|
+
* @param AuthContext the Auth context to be used by the created AuthProvider
|
|
64
|
+
*
|
|
65
|
+
* @returns the AuthProvider component
|
|
66
|
+
*/
|
|
67
|
+
export declare function createAuthProvider<T extends AuthClient>(AuthContext: React.Context<IAuthContextProps<T>>): {
|
|
68
|
+
new (props: AuthProviderProps<T>): {
|
|
69
|
+
state: {
|
|
70
|
+
initialized: boolean;
|
|
71
|
+
isAuthenticated: boolean;
|
|
72
|
+
isLoading: boolean;
|
|
73
|
+
};
|
|
74
|
+
componentDidMount(): void;
|
|
75
|
+
componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
|
|
76
|
+
init(): void;
|
|
77
|
+
onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
|
|
78
|
+
updateState: (event: AuthClientEvent) => () => void;
|
|
79
|
+
refreshToken: (event: AuthClientEvent) => () => void;
|
|
80
|
+
render(): React.JSX.Element;
|
|
81
|
+
context: unknown;
|
|
82
|
+
setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
|
|
83
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
84
|
+
readonly props: Readonly<AuthProviderProps<T>>;
|
|
85
|
+
shouldComponentUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): boolean;
|
|
86
|
+
componentWillUnmount?(): void;
|
|
87
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
88
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<AuthProviderProps<T>>, prevState: Readonly<AuthProviderState>): any;
|
|
89
|
+
componentWillMount?(): void;
|
|
90
|
+
UNSAFE_componentWillMount?(): void;
|
|
91
|
+
componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
|
|
92
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
|
|
93
|
+
componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
|
|
94
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
|
|
95
|
+
};
|
|
96
|
+
new (props: AuthProviderProps<T>, context: any): {
|
|
97
|
+
state: {
|
|
98
|
+
initialized: boolean;
|
|
99
|
+
isAuthenticated: boolean;
|
|
100
|
+
isLoading: boolean;
|
|
101
|
+
};
|
|
102
|
+
componentDidMount(): void;
|
|
103
|
+
componentDidUpdate({ authClient: prevAuthClient, initOptions: prevInitOptions, }: AuthProviderProps<T>): void;
|
|
104
|
+
init(): void;
|
|
105
|
+
onError: (event: AuthClientEvent) => (error?: AuthClientError) => void;
|
|
106
|
+
updateState: (event: AuthClientEvent) => () => void;
|
|
107
|
+
refreshToken: (event: AuthClientEvent) => () => void;
|
|
108
|
+
render(): React.JSX.Element;
|
|
109
|
+
context: unknown;
|
|
110
|
+
setState<K extends keyof AuthProviderState>(state: AuthProviderState | ((prevState: Readonly<AuthProviderState>, props: Readonly<AuthProviderProps<T>>) => AuthProviderState | Pick<AuthProviderState, K> | null) | Pick<AuthProviderState, K> | null, callback?: (() => void) | undefined): void;
|
|
111
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
112
|
+
readonly props: Readonly<AuthProviderProps<T>>;
|
|
113
|
+
shouldComponentUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): boolean;
|
|
114
|
+
componentWillUnmount?(): void;
|
|
115
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
116
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<AuthProviderProps<T>>, prevState: Readonly<AuthProviderState>): any;
|
|
117
|
+
componentWillMount?(): void;
|
|
118
|
+
UNSAFE_componentWillMount?(): void;
|
|
119
|
+
componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
|
|
120
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<AuthProviderProps<T>>, nextContext: any): void;
|
|
121
|
+
componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
|
|
122
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<AuthProviderProps<T>>, nextState: Readonly<AuthProviderState>, nextContext: any): void;
|
|
123
|
+
};
|
|
124
|
+
contextType?: React.Context<any> | undefined;
|
|
125
|
+
propTypes?: any;
|
|
126
|
+
};
|
|
127
|
+
export default createAuthProvider;
|