@leancodepl/kratos 8.4.0 → 8.5.1
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/README.md +368 -4
- package/index.cjs.js +335 -16
- package/index.esm.js +335 -16
- package/package.json +36 -3
- package/src/lib/cards/userAuthCard.d.ts +42 -0
- package/src/lib/cards/userSettingsCard.d.ts +26 -0
- package/src/lib/createKratosClient.d.ts +17 -0
- package/src/lib/flows/useLoginFlow.d.ts +29 -0
- package/src/lib/flows/useLogoutFlow.d.ts +25 -0
- package/src/lib/flows/useReauthenticationFlow.d.ts +23 -0
- package/src/lib/flows/useRecoveryFlow.d.ts +27 -0
- package/src/lib/flows/useRegistrationFlow.d.ts +27 -0
- package/src/lib/flows/useSettingsFlow.d.ts +27 -0
- package/src/lib/flows/useVerificationFlow.d.ts +27 -0
- package/src/lib/kratosContext.d.ts +18 -0
- package/src/lib/kratosContextProvider.d.ts +24 -0
- package/src/lib/sessionManager/baseSessionManager.d.ts +22 -0
- package/index.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
package/index.esm.js
CHANGED
|
@@ -5,7 +5,23 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
5
5
|
import { ReplaySubject, map, shareReplay, Subject, switchMap, from, catchError, of } from 'rxjs';
|
|
6
6
|
import yn from 'yn';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Creates Ory Kratos FrontendApi client with axios and credentials configuration.
|
|
10
|
+
*
|
|
11
|
+
* Initializes a Kratos client for browser-based applications with automatic
|
|
12
|
+
* cookie handling and CORS support for authentication flows.
|
|
13
|
+
*
|
|
14
|
+
* @param configuration - Kratos client configuration parameters
|
|
15
|
+
* @returns Configured FrontendApi instance for Kratos operations
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createKratosClient } from '@leancodepl/kratos';
|
|
19
|
+
*
|
|
20
|
+
* const kratosClient = createKratosClient({
|
|
21
|
+
* basePath: 'https://auth.example.com'
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/ function createKratosClient(configuration) {
|
|
9
25
|
return new FrontendApi(new Configuration(configuration), undefined, axios.create({
|
|
10
26
|
withCredentials: true
|
|
11
27
|
}));
|
|
@@ -149,7 +165,24 @@ var kratosContext = /*#__PURE__*/ createContext({
|
|
|
149
165
|
},
|
|
150
166
|
excludeScripts: false
|
|
151
167
|
});
|
|
152
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Access Kratos context data with components and error handling.
|
|
170
|
+
*
|
|
171
|
+
* Retrieves the current Kratos context including UI components, error handlers,
|
|
172
|
+
* and configuration. Throws error if components are not initialized.
|
|
173
|
+
*
|
|
174
|
+
* @returns Kratos context data with initialized components
|
|
175
|
+
* @throws Error when Kratos context components are not initialized
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* import { useKratosContext } from '@leancodepl/kratos';
|
|
179
|
+
*
|
|
180
|
+
* function LoginComponent() {
|
|
181
|
+
* const { components, useHandleFlowError } = useKratosContext();
|
|
182
|
+
* // Use components and error handling...
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/ function useKratosContext() {
|
|
153
186
|
var context = useContext(kratosContext);
|
|
154
187
|
if (context.components === undefined) {
|
|
155
188
|
throw new Error("Kratos context components were not initialized");
|
|
@@ -836,7 +869,30 @@ function _object_spread$g(target) {
|
|
|
836
869
|
}
|
|
837
870
|
return target;
|
|
838
871
|
}
|
|
839
|
-
|
|
872
|
+
/**
|
|
873
|
+
* Provides Kratos context to child components with customizable configuration.
|
|
874
|
+
*
|
|
875
|
+
* Sets up the React context for Kratos integration, allowing customization of
|
|
876
|
+
* UI components, error handling, and script loading behavior.
|
|
877
|
+
*
|
|
878
|
+
* @param components - Partial override of default Kratos UI components
|
|
879
|
+
* @param useHandleFlowError - Custom error handler for authentication flows
|
|
880
|
+
* @param excludeScripts - Whether to exclude script node execution
|
|
881
|
+
* @param children - Child React components
|
|
882
|
+
* @returns JSX element providing Kratos context
|
|
883
|
+
* @example
|
|
884
|
+
* ```typescript
|
|
885
|
+
* import { KratosContextProvider } from '@leancodepl/kratos';
|
|
886
|
+
*
|
|
887
|
+
* function App() {
|
|
888
|
+
* return (
|
|
889
|
+
* <KratosContextProvider>
|
|
890
|
+
* <LoginPage />
|
|
891
|
+
* </KratosContextProvider>
|
|
892
|
+
* );
|
|
893
|
+
* }
|
|
894
|
+
* ```
|
|
895
|
+
*/ function KratosContextProvider(param) {
|
|
840
896
|
var _param_components = param.components, components = _param_components === void 0 ? {} : _param_components, useHandleFlowError = param.useHandleFlowError, excludeScripts = param.excludeScripts, children = param.children;
|
|
841
897
|
var _useContext = useContext(kratosContext), baseComponents = _useContext.components, baseUseHandleFlowError = _useContext.useHandleFlowError, baseExcludeScripts = _useContext.excludeScripts;
|
|
842
898
|
var value = useMemo(function() {
|
|
@@ -914,7 +970,28 @@ function _define_property$g(obj, key, value) {
|
|
|
914
970
|
}
|
|
915
971
|
return obj;
|
|
916
972
|
}
|
|
917
|
-
|
|
973
|
+
/**
|
|
974
|
+
* Manages Kratos session state with RxJS observables for authentication status.
|
|
975
|
+
*
|
|
976
|
+
* Provides reactive session management with automatic status checking, user identity
|
|
977
|
+
* tracking, and AAL (Authenticator Assurance Level) handling for multi-factor authentication.
|
|
978
|
+
*
|
|
979
|
+
* @param authUrl - Base URL for Kratos authentication endpoints
|
|
980
|
+
* @param loginRoute - Application route for login page
|
|
981
|
+
* @example
|
|
982
|
+
* ```typescript
|
|
983
|
+
* import { BaseSessionManager } from '@leancodepl/kratos';
|
|
984
|
+
*
|
|
985
|
+
* const sessionManager = new BaseSessionManager(
|
|
986
|
+
* 'https://auth.example.com',
|
|
987
|
+
* '/login'
|
|
988
|
+
* );
|
|
989
|
+
*
|
|
990
|
+
* sessionManager.isLoggedIn.subscribe(loggedIn => {
|
|
991
|
+
* console.log('User logged in:', loggedIn);
|
|
992
|
+
* });
|
|
993
|
+
* ```
|
|
994
|
+
*/ var BaseSessionManager = /*#__PURE__*/ function() {
|
|
918
995
|
function BaseSessionManager(authUrl, loginRoute) {
|
|
919
996
|
var _this = this;
|
|
920
997
|
_class_call_check(this, BaseSessionManager);
|
|
@@ -1383,7 +1460,29 @@ function _unsupported_iterable_to_array$6(o, minLen) {
|
|
|
1383
1460
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1384
1461
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$6(o, minLen);
|
|
1385
1462
|
}
|
|
1386
|
-
|
|
1463
|
+
/**
|
|
1464
|
+
* Manages Kratos reauthentication flow for elevated security operations.
|
|
1465
|
+
*
|
|
1466
|
+
* Handles reauthentication flow creation and submission for operations requiring
|
|
1467
|
+
* fresh authentication, such as changing passwords or accessing sensitive data.
|
|
1468
|
+
*
|
|
1469
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
1470
|
+
* @param onReauthenticated - Callback executed with session after successful reauthentication
|
|
1471
|
+
* @returns Object with current flow and submit function
|
|
1472
|
+
* @example
|
|
1473
|
+
* ```typescript
|
|
1474
|
+
* import { useReauthenticationFlow } from '@leancodepl/kratos';
|
|
1475
|
+
*
|
|
1476
|
+
* function ReauthForm() {
|
|
1477
|
+
* const { flow, submit } = useReauthenticationFlow({
|
|
1478
|
+
* kratosClient,
|
|
1479
|
+
* onReauthenticated: (session) => navigate('/secure-area')
|
|
1480
|
+
* });
|
|
1481
|
+
*
|
|
1482
|
+
* return <form onSubmit={submit}>...</form>;
|
|
1483
|
+
* }
|
|
1484
|
+
* ```
|
|
1485
|
+
*/ function useReauthenticationFlow(param) {
|
|
1387
1486
|
var kratosClient = param.kratosClient, onReauthenticated = param.onReauthenticated;
|
|
1388
1487
|
var useHandleFlowError = useKratosContext().useHandleFlowError;
|
|
1389
1488
|
var _useState = _sliced_to_array$5(useState(), 2), flow = _useState[0], setFlow = _useState[1];
|
|
@@ -1579,7 +1678,33 @@ function _unsupported_iterable_to_array$5(o, minLen) {
|
|
|
1579
1678
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1580
1679
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$5(o, minLen);
|
|
1581
1680
|
}
|
|
1582
|
-
|
|
1681
|
+
/**
|
|
1682
|
+
* Manages Kratos account recovery flow state and form submission.
|
|
1683
|
+
*
|
|
1684
|
+
* Handles recovery flow creation, retrieval, and submission with automatic error handling,
|
|
1685
|
+
* URL parameter management, and continue-with callbacks for post-recovery actions.
|
|
1686
|
+
*
|
|
1687
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
1688
|
+
* @param onSessionAlreadyAvailable - Callback when session already exists
|
|
1689
|
+
* @param onContinueWith - Optional callback for post-recovery actions
|
|
1690
|
+
* @param searchParams - URL search parameters for flow state
|
|
1691
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
1692
|
+
* @returns Object with current flow, submit function, and recovery status
|
|
1693
|
+
* @example
|
|
1694
|
+
* ```typescript
|
|
1695
|
+
* import { useRecoveryFlow } from '@leancodepl/kratos';
|
|
1696
|
+
*
|
|
1697
|
+
* function RecoveryForm() {
|
|
1698
|
+
* const { flow, submit, isRecovering } = useRecoveryFlow({
|
|
1699
|
+
* kratosClient,
|
|
1700
|
+
* onSessionAlreadyAvailable: () => navigate('/dashboard'),
|
|
1701
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
1702
|
+
* });
|
|
1703
|
+
*
|
|
1704
|
+
* return <form onSubmit={submit}>...</form>;
|
|
1705
|
+
* }
|
|
1706
|
+
* ```
|
|
1707
|
+
*/ function useRecoveryFlow(param) {
|
|
1583
1708
|
var kratosClient = param.kratosClient, onSessionAlreadyAvailable = param.onSessionAlreadyAvailable, onContinueWith = param.onContinueWith, _param_searchParams = param.searchParams, searchParams = _param_searchParams === void 0 ? {} : _param_searchParams, updateSearchParams = param.updateSearchParams;
|
|
1584
1709
|
var useHandleFlowError = useKratosContext().useHandleFlowError;
|
|
1585
1710
|
var _useState = _sliced_to_array$4(useState(), 2), flow = _useState[0], setFlow = _useState[1];
|
|
@@ -1803,7 +1928,33 @@ function _unsupported_iterable_to_array$4(o, minLen) {
|
|
|
1803
1928
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1804
1929
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$4(o, minLen);
|
|
1805
1930
|
}
|
|
1806
|
-
|
|
1931
|
+
/**
|
|
1932
|
+
* Manages Kratos user settings flow state and form submission.
|
|
1933
|
+
*
|
|
1934
|
+
* Handles settings flow creation, retrieval, and submission for profile updates,
|
|
1935
|
+
* password changes, and security settings management.
|
|
1936
|
+
*
|
|
1937
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
1938
|
+
* @param params - Optional Axios request parameters
|
|
1939
|
+
* @param onContinueWith - Optional callback for post-settings actions
|
|
1940
|
+
* @param searchParams - URL search parameters for flow state
|
|
1941
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
1942
|
+
* @returns Object with current flow and submit function
|
|
1943
|
+
* @example
|
|
1944
|
+
* ```typescript
|
|
1945
|
+
* import { useSettingsFlow } from '@leancodepl/kratos';
|
|
1946
|
+
*
|
|
1947
|
+
* function UserSettingsForm() {
|
|
1948
|
+
* const { flow, submit } = useSettingsFlow({
|
|
1949
|
+
* kratosClient,
|
|
1950
|
+
* onContinueWith: (actions) => console.log('Settings updated'),
|
|
1951
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
1952
|
+
* });
|
|
1953
|
+
*
|
|
1954
|
+
* return <form onSubmit={submit}>...</form>;
|
|
1955
|
+
* }
|
|
1956
|
+
* ```
|
|
1957
|
+
*/ function useSettingsFlow(param) {
|
|
1807
1958
|
var kratosClient = param.kratosClient, params = param.params, onContinueWith = param.onContinueWith, _param_searchParams = param.searchParams, searchParams = _param_searchParams === void 0 ? {} : _param_searchParams, updateSearchParams = param.updateSearchParams;
|
|
1808
1959
|
var useHandleFlowError = useKratosContext().useHandleFlowError;
|
|
1809
1960
|
var _useState = _sliced_to_array$3(useState(), 2), flow = _useState[0], setFlow = _useState[1];
|
|
@@ -2030,7 +2181,35 @@ function _unsupported_iterable_to_array$3(o, minLen) {
|
|
|
2030
2181
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
2031
2182
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$3(o, minLen);
|
|
2032
2183
|
}
|
|
2033
|
-
|
|
2184
|
+
/**
|
|
2185
|
+
* Manages Kratos login flow state and form submission.
|
|
2186
|
+
*
|
|
2187
|
+
* Handles login flow creation, retrieval, and submission with automatic error handling,
|
|
2188
|
+
* URL parameter management, and session callbacks. Supports multi-factor authentication
|
|
2189
|
+
* and refresh flows.
|
|
2190
|
+
*
|
|
2191
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
2192
|
+
* @param returnTo - URL to redirect after successful login
|
|
2193
|
+
* @param onLoggedIn - Callback executed when user successfully logs in
|
|
2194
|
+
* @param onSessionAlreadyAvailable - Callback when session already exists
|
|
2195
|
+
* @param searchParams - URL search parameters for flow state
|
|
2196
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
2197
|
+
* @returns Object with current flow and submit function
|
|
2198
|
+
* @example
|
|
2199
|
+
* ```typescript
|
|
2200
|
+
* import { useLoginFlow } from '@leancodepl/kratos';
|
|
2201
|
+
*
|
|
2202
|
+
* function LoginForm() {
|
|
2203
|
+
* const { flow, submit } = useLoginFlow({
|
|
2204
|
+
* kratosClient,
|
|
2205
|
+
* onLoggedIn: (session) => navigate('/dashboard'),
|
|
2206
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
2207
|
+
* });
|
|
2208
|
+
*
|
|
2209
|
+
* return <form onSubmit={submit}>...</form>;
|
|
2210
|
+
* }
|
|
2211
|
+
* ```
|
|
2212
|
+
*/ function useLoginFlow(param) {
|
|
2034
2213
|
var kratosClient = param.kratosClient, returnTo = param.returnTo, onLoggedIn = param.onLoggedIn, onSessionAlreadyAvailable = param.onSessionAlreadyAvailable, _param_searchParams = param.searchParams, searchParams = _param_searchParams === void 0 ? {} : _param_searchParams, updateSearchParams = param.updateSearchParams;
|
|
2035
2214
|
var useHandleFlowError = useKratosContext().useHandleFlowError;
|
|
2036
2215
|
var _useState = _sliced_to_array$2(useState(), 2), flow = _useState[0], setFlow = _useState[1];
|
|
@@ -2264,7 +2443,33 @@ function _unsupported_iterable_to_array$2(o, minLen) {
|
|
|
2264
2443
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
2265
2444
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
|
|
2266
2445
|
}
|
|
2267
|
-
|
|
2446
|
+
/**
|
|
2447
|
+
* Manages Kratos registration flow state and form submission.
|
|
2448
|
+
*
|
|
2449
|
+
* Handles registration flow creation, retrieval, and submission with automatic error handling,
|
|
2450
|
+
* URL parameter management, and continue-with callbacks for post-registration actions.
|
|
2451
|
+
*
|
|
2452
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
2453
|
+
* @param onSessionAlreadyAvailable - Callback when session already exists
|
|
2454
|
+
* @param onContinueWith - Optional callback for post-registration actions
|
|
2455
|
+
* @param searchParams - URL search parameters for flow state
|
|
2456
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
2457
|
+
* @returns Object with current flow, submit function, and registration status
|
|
2458
|
+
* @example
|
|
2459
|
+
* ```typescript
|
|
2460
|
+
* import { useRegisterFlow } from '@leancodepl/kratos';
|
|
2461
|
+
*
|
|
2462
|
+
* function RegisterForm() {
|
|
2463
|
+
* const { flow, submit, isRegistered } = useRegisterFlow({
|
|
2464
|
+
* kratosClient,
|
|
2465
|
+
* onSessionAlreadyAvailable: () => navigate('/dashboard'),
|
|
2466
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
2467
|
+
* });
|
|
2468
|
+
*
|
|
2469
|
+
* return <form onSubmit={submit}>...</form>;
|
|
2470
|
+
* }
|
|
2471
|
+
* ```
|
|
2472
|
+
*/ function useRegisterFlow(param) {
|
|
2268
2473
|
var kratosClient = param.kratosClient, onSessionAlreadyAvailable = param.onSessionAlreadyAvailable, onContinueWith = param.onContinueWith, _param_searchParams = param.searchParams, searchParams = _param_searchParams === void 0 ? {} : _param_searchParams, updateSearchParams = param.updateSearchParams;
|
|
2269
2474
|
var useHandleFlowError = useKratosContext().useHandleFlowError;
|
|
2270
2475
|
var _useState = _sliced_to_array$1(useState(), 2), flow = _useState[0], setFlow = _useState[1];
|
|
@@ -2442,7 +2647,33 @@ function _unsupported_iterable_to_array$1(o, minLen) {
|
|
|
2442
2647
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
2443
2648
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
2444
2649
|
}
|
|
2445
|
-
|
|
2650
|
+
/**
|
|
2651
|
+
* Manages Kratos email/phone verification flow state and form submission.
|
|
2652
|
+
*
|
|
2653
|
+
* Handles verification flow creation, retrieval, and submission with automatic error handling,
|
|
2654
|
+
* URL parameter management, and verification status tracking.
|
|
2655
|
+
*
|
|
2656
|
+
* @param initialFlowId - Optional initial flow ID to start with
|
|
2657
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
2658
|
+
* @param onVerified - Callback executed when verification is successful
|
|
2659
|
+
* @param searchParams - URL search parameters for flow state
|
|
2660
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
2661
|
+
* @returns Object with current flow, submit function, and reset function
|
|
2662
|
+
* @example
|
|
2663
|
+
* ```typescript
|
|
2664
|
+
* import { useVerificationFlow } from '@leancodepl/kratos';
|
|
2665
|
+
*
|
|
2666
|
+
* function VerifyEmailForm() {
|
|
2667
|
+
* const { flow, submit, reset } = useVerificationFlow({
|
|
2668
|
+
* kratosClient,
|
|
2669
|
+
* onVerified: () => navigate('/dashboard'),
|
|
2670
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
2671
|
+
* });
|
|
2672
|
+
*
|
|
2673
|
+
* return <form onSubmit={submit}>...</form>;
|
|
2674
|
+
* }
|
|
2675
|
+
* ```
|
|
2676
|
+
*/ function useVerificationFlow(param) {
|
|
2446
2677
|
var initialFlowId = param.initialFlowId, kratosClient = param.kratosClient, onVerified = param.onVerified, _param_searchParams = param.searchParams, searchParams = _param_searchParams === void 0 ? {} : _param_searchParams, updateSearchParams = param.updateSearchParams;
|
|
2447
2678
|
var useHandleFlowError = useKratosContext().useHandleFlowError;
|
|
2448
2679
|
var _useState = _sliced_to_array(useState(), 2), flow = _useState[0], setFlow = _useState[1];
|
|
@@ -2656,7 +2887,31 @@ function _ts_generator(thisArg, body) {
|
|
|
2656
2887
|
};
|
|
2657
2888
|
}
|
|
2658
2889
|
}
|
|
2659
|
-
|
|
2890
|
+
/**
|
|
2891
|
+
* Manages Kratos user logout flow with callback support.
|
|
2892
|
+
*
|
|
2893
|
+
* Provides a logout function that creates and executes logout flow,
|
|
2894
|
+
* handling token invalidation and redirect logic.
|
|
2895
|
+
*
|
|
2896
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
2897
|
+
* @param returnTo - Optional URL to redirect after logout
|
|
2898
|
+
* @param onLoggedOut - Optional callback executed after successful logout
|
|
2899
|
+
* @returns Object with logout function
|
|
2900
|
+
* @example
|
|
2901
|
+
* ```typescript
|
|
2902
|
+
* import { useLogoutFlow } from '@leancodepl/kratos';
|
|
2903
|
+
*
|
|
2904
|
+
* function LogoutButton() {
|
|
2905
|
+
* const { logout } = useLogoutFlow({
|
|
2906
|
+
* kratosClient,
|
|
2907
|
+
* returnTo: '/login',
|
|
2908
|
+
* onLoggedOut: () => console.log('User logged out')
|
|
2909
|
+
* });
|
|
2910
|
+
*
|
|
2911
|
+
* return <button onClick={logout}>Logout</button>;
|
|
2912
|
+
* }
|
|
2913
|
+
* ```
|
|
2914
|
+
*/ function useLogoutFlow(param) {
|
|
2660
2915
|
var kratosClient = param.kratosClient, returnTo = param.returnTo, onLoggedOut = param.onLoggedOut;
|
|
2661
2916
|
var logout = useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
2662
2917
|
var flow;
|
|
@@ -3896,10 +4151,48 @@ function mkCard(flowType) {
|
|
|
3896
4151
|
}, props));
|
|
3897
4152
|
};
|
|
3898
4153
|
}
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
4154
|
+
/**
|
|
4155
|
+
* Pre-built login card component for Kratos login flows.
|
|
4156
|
+
*
|
|
4157
|
+
* Renders a complete login form with support for password, passkey, OIDC,
|
|
4158
|
+
* multi-factor authentication, and identifier-first flows.
|
|
4159
|
+
*
|
|
4160
|
+
* @param flow - Kratos login flow object
|
|
4161
|
+
* @param onSubmit - Form submission handler
|
|
4162
|
+
* @param className - Optional CSS class name
|
|
4163
|
+
* @returns JSX element with login form
|
|
4164
|
+
*/ var LoginCard = mkCard("login");
|
|
4165
|
+
/**
|
|
4166
|
+
* Pre-built verification card component for Kratos verification flows.
|
|
4167
|
+
*
|
|
4168
|
+
* Renders a complete verification form for email/phone verification processes.
|
|
4169
|
+
*
|
|
4170
|
+
* @param flow - Kratos verification flow object
|
|
4171
|
+
* @param onSubmit - Form submission handler
|
|
4172
|
+
* @param className - Optional CSS class name
|
|
4173
|
+
* @returns JSX element with verification form
|
|
4174
|
+
*/ var VerificationCard = mkCard("verification");
|
|
4175
|
+
/**
|
|
4176
|
+
* Pre-built registration card component for Kratos registration flows.
|
|
4177
|
+
*
|
|
4178
|
+
* Renders a complete registration form with support for profile fields,
|
|
4179
|
+
* password, passkey, and OIDC registration methods.
|
|
4180
|
+
*
|
|
4181
|
+
* @param flow - Kratos registration flow object
|
|
4182
|
+
* @param onSubmit - Form submission handler
|
|
4183
|
+
* @param className - Optional CSS class name
|
|
4184
|
+
* @returns JSX element with registration form
|
|
4185
|
+
*/ var RegistrationCard = mkCard("registration");
|
|
4186
|
+
/**
|
|
4187
|
+
* Pre-built recovery card component for Kratos account recovery flows.
|
|
4188
|
+
*
|
|
4189
|
+
* Renders a complete recovery form for password reset and account recovery processes.
|
|
4190
|
+
*
|
|
4191
|
+
* @param flow - Kratos recovery flow object
|
|
4192
|
+
* @param onSubmit - Form submission handler
|
|
4193
|
+
* @param className - Optional CSS class name
|
|
4194
|
+
* @returns JSX element with recovery form
|
|
4195
|
+
*/ var RecoveryCard = mkCard("recovery");
|
|
3903
4196
|
// the user might need to logout on the second factor page.
|
|
3904
4197
|
function isLoggedIn(flow) {
|
|
3905
4198
|
if ("requested_aal" in flow && flow.requested_aal === AuthenticatorAssuranceLevel.Aal2) {
|
|
@@ -4277,7 +4570,32 @@ function TotpSettingsSection(param) {
|
|
|
4277
4570
|
});
|
|
4278
4571
|
}
|
|
4279
4572
|
|
|
4280
|
-
|
|
4573
|
+
/**
|
|
4574
|
+
* Pre-built settings card component for Kratos settings flows.
|
|
4575
|
+
*
|
|
4576
|
+
* Renders different settings sections based on flow type: profile, password,
|
|
4577
|
+
* passkey, TOTP, lookup secrets, or OIDC settings management.
|
|
4578
|
+
*
|
|
4579
|
+
* @param flow - Kratos settings flow object
|
|
4580
|
+
* @param flowType - Type of settings flow to render
|
|
4581
|
+
* @param onSubmit - Form submission handler
|
|
4582
|
+
* @param className - Optional CSS class name
|
|
4583
|
+
* @returns JSX element with settings form or null if flow type unavailable
|
|
4584
|
+
* @example
|
|
4585
|
+
* ```typescript
|
|
4586
|
+
* import { UserSettingsCard } from '@leancodepl/kratos';
|
|
4587
|
+
*
|
|
4588
|
+
* function ProfileSettings() {
|
|
4589
|
+
* return (
|
|
4590
|
+
* <UserSettingsCard
|
|
4591
|
+
* flow={settingsFlow}
|
|
4592
|
+
* flowType="profile"
|
|
4593
|
+
* onSubmit={handleSubmit}
|
|
4594
|
+
* />
|
|
4595
|
+
* );
|
|
4596
|
+
* }
|
|
4597
|
+
* ```
|
|
4598
|
+
*/ function UserSettingsCard(param) {
|
|
4281
4599
|
var flow = param.flow, flowType = param.flowType, onSubmit = param.onSubmit, className = param.className;
|
|
4282
4600
|
var _useKratosContext = useKratosContext(), _useKratosContext_components = _useKratosContext.components, ProfileSettingsSectionWrapper = _useKratosContext_components.ProfileSettingsSectionWrapper, PasswordSettingsSectionWrapper = _useKratosContext_components.PasswordSettingsSectionWrapper, WebAuthnSettingsSectionWrapper = _useKratosContext_components.WebAuthnSettingsSectionWrapper, LookupSecretSettingsSectionWrapper = _useKratosContext_components.LookupSecretSettingsSectionWrapper, OidcSettingsSectionWrapper = _useKratosContext_components.OidcSettingsSectionWrapper, TotpSettingsSectionWrapper = _useKratosContext_components.TotpSettingsSectionWrapper, UiMessages = _useKratosContext_components.UiMessages, excludeScripts = _useKratosContext.excludeScripts;
|
|
4283
4601
|
useScriptNodes({
|
|
@@ -4316,6 +4634,7 @@ function UserSettingsCard(param) {
|
|
|
4316
4634
|
TotpSettingsSectionWrapper: TotpSettingsSectionWrapper
|
|
4317
4635
|
});
|
|
4318
4636
|
}
|
|
4637
|
+
return null;
|
|
4319
4638
|
}();
|
|
4320
4639
|
if (!$flow) return null;
|
|
4321
4640
|
return /*#__PURE__*/ jsxs(UserAuthForm, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/kratos",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18.0.0"
|
|
11
|
+
},
|
|
5
12
|
"dependencies": {
|
|
6
13
|
"@ory/client": ">=1.14.3",
|
|
7
14
|
"axios": ">=1.6.0",
|
|
@@ -13,16 +20,42 @@
|
|
|
13
20
|
"react": "*",
|
|
14
21
|
"react-dom": "*"
|
|
15
22
|
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/leancodepl/js_corelibrary.git",
|
|
26
|
+
"directory": "packages/kratos"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/leancodepl/js_corelibrary",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/leancodepl/js_corelibrary/issues"
|
|
31
|
+
},
|
|
32
|
+
"description": "React components and hooks for Ory Kratos authentication",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"ory",
|
|
35
|
+
"kratos",
|
|
36
|
+
"authentication",
|
|
37
|
+
"react",
|
|
38
|
+
"auth",
|
|
39
|
+
"identity",
|
|
40
|
+
"typescript",
|
|
41
|
+
"javascript",
|
|
42
|
+
"leancode"
|
|
43
|
+
],
|
|
44
|
+
"author": {
|
|
45
|
+
"name": "LeanCode",
|
|
46
|
+
"url": "https://leancode.co"
|
|
47
|
+
},
|
|
48
|
+
"sideEffects": false,
|
|
16
49
|
"exports": {
|
|
17
50
|
"./package.json": "./package.json",
|
|
18
51
|
".": {
|
|
19
52
|
"module": "./index.esm.js",
|
|
20
|
-
"types": "./index.
|
|
53
|
+
"types": "./index.d.ts",
|
|
21
54
|
"import": "./index.cjs.mjs",
|
|
22
55
|
"default": "./index.cjs.js"
|
|
23
56
|
}
|
|
24
57
|
},
|
|
25
58
|
"module": "./index.esm.js",
|
|
26
59
|
"main": "./index.cjs.js",
|
|
27
|
-
"types": "./index.
|
|
60
|
+
"types": "./index.d.ts"
|
|
28
61
|
}
|
|
@@ -5,15 +5,57 @@ type UserAuthCardProps<TBody> = UserAuthFormAdditionalProps<TBody> & {
|
|
|
5
5
|
flow: LoginFlow | RecoveryFlow | RegistrationFlow | VerificationFlow;
|
|
6
6
|
flowType: "login" | "recovery" | "registration" | "verification";
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Pre-built login card component for Kratos login flows.
|
|
10
|
+
*
|
|
11
|
+
* Renders a complete login form with support for password, passkey, OIDC,
|
|
12
|
+
* multi-factor authentication, and identifier-first flows.
|
|
13
|
+
*
|
|
14
|
+
* @param flow - Kratos login flow object
|
|
15
|
+
* @param onSubmit - Form submission handler
|
|
16
|
+
* @param className - Optional CSS class name
|
|
17
|
+
* @returns JSX element with login form
|
|
18
|
+
*/
|
|
8
19
|
export declare const LoginCard: ({ ...props }: Omit<UserAuthCardProps<UpdateLoginFlowBody>, "flow" | "flowType"> & {
|
|
9
20
|
flow: LoginFlow;
|
|
10
21
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* Pre-built verification card component for Kratos verification flows.
|
|
24
|
+
*
|
|
25
|
+
* Renders a complete verification form for email/phone verification processes.
|
|
26
|
+
*
|
|
27
|
+
* @param flow - Kratos verification flow object
|
|
28
|
+
* @param onSubmit - Form submission handler
|
|
29
|
+
* @param className - Optional CSS class name
|
|
30
|
+
* @returns JSX element with verification form
|
|
31
|
+
*/
|
|
11
32
|
export declare const VerificationCard: ({ ...props }: Omit<UserAuthCardProps<UpdateVerificationFlowBody>, "flow" | "flowType"> & {
|
|
12
33
|
flow: VerificationFlow;
|
|
13
34
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
/**
|
|
36
|
+
* Pre-built registration card component for Kratos registration flows.
|
|
37
|
+
*
|
|
38
|
+
* Renders a complete registration form with support for profile fields,
|
|
39
|
+
* password, passkey, and OIDC registration methods.
|
|
40
|
+
*
|
|
41
|
+
* @param flow - Kratos registration flow object
|
|
42
|
+
* @param onSubmit - Form submission handler
|
|
43
|
+
* @param className - Optional CSS class name
|
|
44
|
+
* @returns JSX element with registration form
|
|
45
|
+
*/
|
|
14
46
|
export declare const RegistrationCard: ({ ...props }: Omit<UserAuthCardProps<UpdateRegistrationFlowBody>, "flow" | "flowType"> & {
|
|
15
47
|
flow: RegistrationFlow;
|
|
16
48
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
49
|
+
/**
|
|
50
|
+
* Pre-built recovery card component for Kratos account recovery flows.
|
|
51
|
+
*
|
|
52
|
+
* Renders a complete recovery form for password reset and account recovery processes.
|
|
53
|
+
*
|
|
54
|
+
* @param flow - Kratos recovery flow object
|
|
55
|
+
* @param onSubmit - Form submission handler
|
|
56
|
+
* @param className - Optional CSS class name
|
|
57
|
+
* @returns JSX element with recovery form
|
|
58
|
+
*/
|
|
17
59
|
export declare const RecoveryCard: ({ ...props }: Omit<UserAuthCardProps<UpdateRecoveryFlowBody>, "flow" | "flowType"> & {
|
|
18
60
|
flow: RecoveryFlow;
|
|
19
61
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,4 +7,30 @@ export type UserSettingsCardProps = UserAuthFormAdditionalProps<UpdateSettingsFl
|
|
|
7
7
|
flowType: UserSettingsFlowType;
|
|
8
8
|
className?: string;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Pre-built settings card component for Kratos settings flows.
|
|
12
|
+
*
|
|
13
|
+
* Renders different settings sections based on flow type: profile, password,
|
|
14
|
+
* passkey, TOTP, lookup secrets, or OIDC settings management.
|
|
15
|
+
*
|
|
16
|
+
* @param flow - Kratos settings flow object
|
|
17
|
+
* @param flowType - Type of settings flow to render
|
|
18
|
+
* @param onSubmit - Form submission handler
|
|
19
|
+
* @param className - Optional CSS class name
|
|
20
|
+
* @returns JSX element with settings form or null if flow type unavailable
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { UserSettingsCard } from '@leancodepl/kratos';
|
|
24
|
+
*
|
|
25
|
+
* function ProfileSettings() {
|
|
26
|
+
* return (
|
|
27
|
+
* <UserSettingsCard
|
|
28
|
+
* flow={settingsFlow}
|
|
29
|
+
* flowType="profile"
|
|
30
|
+
* onSubmit={handleSubmit}
|
|
31
|
+
* />
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
10
36
|
export declare function UserSettingsCard({ flow, flowType, onSubmit, className }: UserSettingsCardProps): JSX.Element | null;
|
|
@@ -1,2 +1,19 @@
|
|
|
1
1
|
import { ConfigurationParameters, FrontendApi } from "@ory/client";
|
|
2
|
+
/**
|
|
3
|
+
* Creates Ory Kratos FrontendApi client with axios and credentials configuration.
|
|
4
|
+
*
|
|
5
|
+
* Initializes a Kratos client for browser-based applications with automatic
|
|
6
|
+
* cookie handling and CORS support for authentication flows.
|
|
7
|
+
*
|
|
8
|
+
* @param configuration - Kratos client configuration parameters
|
|
9
|
+
* @returns Configured FrontendApi instance for Kratos operations
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createKratosClient } from '@leancodepl/kratos';
|
|
13
|
+
*
|
|
14
|
+
* const kratosClient = createKratosClient({
|
|
15
|
+
* basePath: 'https://auth.example.com'
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
2
19
|
export declare function createKratosClient(configuration: ConfigurationParameters): FrontendApi;
|
|
@@ -6,6 +6,35 @@ export type LoginSearchParams = {
|
|
|
6
6
|
[refreshParameterName]?: string;
|
|
7
7
|
[aalParameterName]?: string;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Manages Kratos login flow state and form submission.
|
|
11
|
+
*
|
|
12
|
+
* Handles login flow creation, retrieval, and submission with automatic error handling,
|
|
13
|
+
* URL parameter management, and session callbacks. Supports multi-factor authentication
|
|
14
|
+
* and refresh flows.
|
|
15
|
+
*
|
|
16
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
17
|
+
* @param returnTo - URL to redirect after successful login
|
|
18
|
+
* @param onLoggedIn - Callback executed when user successfully logs in
|
|
19
|
+
* @param onSessionAlreadyAvailable - Callback when session already exists
|
|
20
|
+
* @param searchParams - URL search parameters for flow state
|
|
21
|
+
* @param updateSearchParams - Function to update URL search parameters
|
|
22
|
+
* @returns Object with current flow and submit function
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { useLoginFlow } from '@leancodepl/kratos';
|
|
26
|
+
*
|
|
27
|
+
* function LoginForm() {
|
|
28
|
+
* const { flow, submit } = useLoginFlow({
|
|
29
|
+
* kratosClient,
|
|
30
|
+
* onLoggedIn: (session) => navigate('/dashboard'),
|
|
31
|
+
* updateSearchParams: (params) => setSearchParams(params)
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* return <form onSubmit={submit}>...</form>;
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
9
38
|
export declare function useLoginFlow({ kratosClient, returnTo, onLoggedIn, onSessionAlreadyAvailable, searchParams, updateSearchParams, }: {
|
|
10
39
|
kratosClient: FrontendApi;
|
|
11
40
|
returnTo?: string;
|
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
import { FrontendApi } from "@ory/client";
|
|
2
|
+
/**
|
|
3
|
+
* Manages Kratos user logout flow with callback support.
|
|
4
|
+
*
|
|
5
|
+
* Provides a logout function that creates and executes logout flow,
|
|
6
|
+
* handling token invalidation and redirect logic.
|
|
7
|
+
*
|
|
8
|
+
* @param kratosClient - Configured Kratos FrontendApi client
|
|
9
|
+
* @param returnTo - Optional URL to redirect after logout
|
|
10
|
+
* @param onLoggedOut - Optional callback executed after successful logout
|
|
11
|
+
* @returns Object with logout function
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { useLogoutFlow } from '@leancodepl/kratos';
|
|
15
|
+
*
|
|
16
|
+
* function LogoutButton() {
|
|
17
|
+
* const { logout } = useLogoutFlow({
|
|
18
|
+
* kratosClient,
|
|
19
|
+
* returnTo: '/login',
|
|
20
|
+
* onLoggedOut: () => console.log('User logged out')
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* return <button onClick={logout}>Logout</button>;
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
2
27
|
export declare function useLogoutFlow({ kratosClient, returnTo, onLoggedOut, }: {
|
|
3
28
|
kratosClient: FrontendApi;
|
|
4
29
|
returnTo?: string;
|