@leancodepl/kratos 10.1.2 → 10.1.3
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/CHANGELOG.md +18 -0
- package/README.md +79 -39
- package/dist/index.js +84 -83
- package/dist/index.umd.cjs +1 -1
- package/dist/lib/factories/mkKratos.d.ts +3 -3
- package/dist/lib/factories/mkKratos.d.ts.map +1 -1
- package/dist/lib/flows/formTypes.d.ts +6 -0
- package/dist/lib/flows/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/index.d.ts +6 -0
- package/dist/lib/flows/index.d.ts.map +1 -1
- package/dist/lib/flows/login/formTypes.d.ts +10 -0
- package/dist/lib/flows/login/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/login/loginFlow.d.ts.map +1 -1
- package/dist/lib/flows/recovery/formTypes.d.ts +9 -0
- package/dist/lib/flows/recovery/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/registration/formTypes.d.ts +9 -0
- package/dist/lib/flows/registration/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/settings/formTypes.d.ts +12 -0
- package/dist/lib/flows/settings/formTypes.d.ts.map +1 -0
- package/dist/lib/flows/verification/formTypes.d.ts +7 -0
- package/dist/lib/flows/verification/formTypes.d.ts.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.1.3](https://github.com/leancodepl/js_corelibrary/compare/v10.1.2...v10.1.3) (2026-04-01)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add more specific types for helpers
|
|
11
|
+
([83e8bd4](https://github.com/leancodepl/js_corelibrary/commit/83e8bd4978e7f0d90fd04f7d470a48302c1330ba))
|
|
12
|
+
- export form type helpers
|
|
13
|
+
([443de15](https://github.com/leancodepl/js_corelibrary/commit/443de1554d2e66e49bfa6379c8b045cdd8d9d124))
|
|
14
|
+
- extract default traits and oidc providers objects
|
|
15
|
+
([1a1ecb1](https://github.com/leancodepl/js_corelibrary/commit/1a1ecb1e6c09cdf65b2566718527d5a7a5b38c2b))
|
|
16
|
+
- unify error handler types
|
|
17
|
+
([d5bd8d6](https://github.com/leancodepl/js_corelibrary/commit/d5bd8d664eaa0046a61ddbbd4e8e85b4a1e7c3bb))
|
|
18
|
+
|
|
19
|
+
# Change Log
|
|
20
|
+
|
|
21
|
+
All notable changes to this project will be documented in this file. See
|
|
22
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
23
|
+
|
|
6
24
|
## [10.1.2](https://github.com/leancodepl/js_corelibrary/compare/v10.1.1...v10.1.2) (2026-02-26)
|
|
7
25
|
|
|
8
26
|
**Note:** Version bump only for package @leancodepl/kratos
|
package/README.md
CHANGED
|
@@ -12,19 +12,19 @@ yarn add @leancodepl/kratos
|
|
|
12
12
|
|
|
13
13
|
## API
|
|
14
14
|
|
|
15
|
-
### `mkKratos(
|
|
15
|
+
### `mkKratos(config)`
|
|
16
16
|
|
|
17
17
|
Creates a Kratos client factory with authentication flows, session management, and React providers.
|
|
18
18
|
|
|
19
19
|
**Parameters:**
|
|
20
20
|
|
|
21
|
-
- `queryClient: QueryClient` - React Query client instance for managing server state
|
|
22
|
-
- `basePath: string` - Base URL for the Kratos API server
|
|
23
|
-
- `traits?: TTraitsConfig` - Optional traits configuration object for user schema validation
|
|
24
|
-
- `SessionManager?: new (props: BaseSessionManagerContructorProps) => TSessionManager` - Optional session manager
|
|
21
|
+
- `config.queryClient: QueryClient` - React Query client instance for managing server state
|
|
22
|
+
- `config.basePath: string` - Base URL for the Kratos API server
|
|
23
|
+
- `config.traits?: TTraitsConfig` - Optional traits configuration object for user schema validation
|
|
24
|
+
- `config.SessionManager?: new (props: BaseSessionManagerContructorProps) => TSessionManager` - Optional session manager
|
|
25
25
|
constructor, defaults to BaseSessionManager
|
|
26
|
-
- `oidcProviders?: readonly OidcProviderConfig[]` - Optional array of custom OIDC provider configurations. Each
|
|
27
|
-
should have an `id` (matching Kratos provider ID)
|
|
26
|
+
- `config.oidcProviders?: readonly OidcProviderConfig[]` - Optional array of custom OIDC provider configurations. Each
|
|
27
|
+
provider should have an `id` (matching Kratos provider ID). Define as `as const` for type-safe flow form props.
|
|
28
28
|
|
|
29
29
|
**Returns:** Object with the following structure:
|
|
30
30
|
|
|
@@ -66,6 +66,36 @@ Manages Ory Kratos session and identity state with React Query integration.
|
|
|
66
66
|
- `queryClient: QueryClient` - React Query `QueryClient` instance for caching and fetching session data
|
|
67
67
|
- `api: FrontendApi` - Ory Kratos `FrontendApi` instance for session and identity requests
|
|
68
68
|
|
|
69
|
+
### Form and error handler type utilities
|
|
70
|
+
|
|
71
|
+
Type utilities for extracting form component props and error handler types from flow components. Pass the flow component
|
|
72
|
+
type (e.g. `typeof LoginFlow`) as the generic parameter.
|
|
73
|
+
|
|
74
|
+
**Form props types:**
|
|
75
|
+
|
|
76
|
+
- `GetLoginChooseMethodFormProps<T>` - Props for `chooseMethodForm` in LoginFlow
|
|
77
|
+
- `GetLoginSecondFactorFormProps<T>` - Props for `secondFactorForm` in LoginFlow
|
|
78
|
+
- `GetLoginSecondFactorEmailFormProps<T>` - Props for `secondFactorEmailForm` in LoginFlow
|
|
79
|
+
- `GetLoginEmailVerificationFormProps<T>` - Props for `emailVerificationForm` in LoginFlow
|
|
80
|
+
- `GetRegistrationTraitsFormProps<T>` - Props for `traitsForm` in RegistrationFlow
|
|
81
|
+
- `GetRegistrationChooseMethodFormProps<T>` - Props for `chooseMethodForm` in RegistrationFlow
|
|
82
|
+
- `GetRegistrationEmailVerificationFormProps<T>` - Props for `emailVerificationForm` in RegistrationFlow
|
|
83
|
+
- `GetVerificationEmailVerificationFormProps<T>` - Props for `emailVerificationForm` in VerificationFlow
|
|
84
|
+
- `GetSettingsFormProps<T>` - Props for `settingsForm` in SettingsFlow
|
|
85
|
+
- `GetSettingsTraitsFormProps<T>` - Props for `traitsForm` in SettingsFlow
|
|
86
|
+
- `GetSettingsOidcFormProps<T>` - Props for `oidcForm` in SettingsFlow
|
|
87
|
+
- `GetSettingsNewPasswordFormProps<T>` - Props for `newPasswordForm` in SettingsFlow
|
|
88
|
+
- `GetSettingsPasskeysFormProps<T>` - Props for `passkeysForm` in SettingsFlow
|
|
89
|
+
- `GetSettingsTotpFormProps<T>` - Props for `totpForm` in SettingsFlow
|
|
90
|
+
- `GetRecoveryEmailFormProps<T>` - Props for `emailForm` in RecoveryFlow
|
|
91
|
+
- `GetRecoveryCodeFormProps<T>` - Props for `codeForm` in RecoveryFlow
|
|
92
|
+
- `GetRecoveryNewPasswordFormProps<T>` - Props for `newPasswordForm` in RecoveryFlow
|
|
93
|
+
|
|
94
|
+
**Error handler type:**
|
|
95
|
+
|
|
96
|
+
- `GetFlowErrorHandler<T>` - Type for `onError` in any flow (LoginFlow, RegistrationFlow, VerificationFlow,
|
|
97
|
+
RecoveryFlow, SettingsFlow)
|
|
98
|
+
|
|
69
99
|
## Usage Examples
|
|
70
100
|
|
|
71
101
|
### Basic Setup
|
|
@@ -205,7 +235,8 @@ const {
|
|
|
205
235
|
|
|
206
236
|
### Custom OIDC Providers
|
|
207
237
|
|
|
208
|
-
You can configure custom OIDC providers (like Microsoft, GitHub, etc.) in addition to the default providers (Apple,
|
|
238
|
+
You can configure custom OIDC providers (like Microsoft, GitHub, etc.) in addition to the default providers (Apple,
|
|
239
|
+
Google, Facebook):
|
|
209
240
|
|
|
210
241
|
```typescript
|
|
211
242
|
// kratosService.ts
|
|
@@ -223,26 +254,20 @@ const {
|
|
|
223
254
|
queryClient,
|
|
224
255
|
basePath: environment.authUrl,
|
|
225
256
|
traits: traitsConfig,
|
|
226
|
-
oidcProviders: [
|
|
227
|
-
{ id: "microsoft" },
|
|
228
|
-
{ id: "github" },
|
|
229
|
-
{ id: "reddit" },
|
|
230
|
-
],
|
|
257
|
+
oidcProviders: [{ id: "microsoft" }, { id: "github" }, { id: "reddit" }],
|
|
231
258
|
})
|
|
232
259
|
```
|
|
233
260
|
|
|
234
|
-
The OIDC providers are automatically made available in the flow forms as capitalized component properties. For example,
|
|
261
|
+
The OIDC providers are automatically made available in the flow forms as capitalized component properties. For example,
|
|
262
|
+
a provider with `id: "microsoft"` will be available as `oidcProviders.Microsoft`.
|
|
235
263
|
|
|
236
|
-
With TypeScript, the library generates type-safe provider types from your configuration, ensuring you can only access
|
|
264
|
+
With TypeScript, the library generates type-safe provider types from your configuration, ensuring you can only access
|
|
265
|
+
providers you've configured:
|
|
237
266
|
|
|
238
267
|
```tsx
|
|
239
268
|
// kratosService.ts
|
|
240
269
|
|
|
241
|
-
const oidcProvidersConfig = [
|
|
242
|
-
{ id: "microsoft" },
|
|
243
|
-
{ id: "github" },
|
|
244
|
-
{ id: "reddit" },
|
|
245
|
-
] as const
|
|
270
|
+
const oidcProvidersConfig = [{ id: "microsoft" }, { id: "github" }, { id: "reddit" }] as const
|
|
246
271
|
|
|
247
272
|
const {
|
|
248
273
|
session: { sessionManager },
|
|
@@ -261,13 +286,17 @@ export type OidcProvidersConfig = typeof oidcProvidersConfig
|
|
|
261
286
|
```tsx
|
|
262
287
|
// loginPage.tsx
|
|
263
288
|
|
|
264
|
-
import {
|
|
265
|
-
import
|
|
289
|
+
import type { GetLoginChooseMethodFormProps } from "@leancodepl/kratos"
|
|
290
|
+
import { LoginFlow } from "./kratosService"
|
|
266
291
|
|
|
267
292
|
// Note: Provider IDs are capitalized (first letter only) in the component names.
|
|
268
293
|
// For example, "github" becomes "Github", "microsoft" becomes "Microsoft".
|
|
269
|
-
function ChooseMethodForm(props:
|
|
270
|
-
const {
|
|
294
|
+
function ChooseMethodForm(props: GetLoginChooseMethodFormProps<typeof LoginFlow>) {
|
|
295
|
+
const {
|
|
296
|
+
oidcProviders: { Microsoft, Github, Reddit },
|
|
297
|
+
isSubmitting,
|
|
298
|
+
isValidating,
|
|
299
|
+
} = props
|
|
271
300
|
|
|
272
301
|
return (
|
|
273
302
|
<div>
|
|
@@ -293,7 +322,9 @@ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps<OidcProvidersCo
|
|
|
293
322
|
}
|
|
294
323
|
```
|
|
295
324
|
|
|
296
|
-
The same pattern applies to registration and settings flows. Only providers configured in your Kratos instance will be
|
|
325
|
+
The same pattern applies to registration and settings flows. Only providers configured in your Kratos instance will be
|
|
326
|
+
available in the `oidcProviders` object, and TypeScript will provide autocomplete and type checking for the available
|
|
327
|
+
providers.
|
|
297
328
|
|
|
298
329
|
### Session Management
|
|
299
330
|
|
|
@@ -377,7 +408,8 @@ function RegisterPage() {
|
|
|
377
408
|
### Settings Flow
|
|
378
409
|
|
|
379
410
|
```tsx
|
|
380
|
-
import { SettingsFlow
|
|
411
|
+
import { SettingsFlow } from "./kratosService"
|
|
412
|
+
import type { GetSettingsFormProps } from "@leancodepl/kratos"
|
|
381
413
|
|
|
382
414
|
function SettingsPage() {
|
|
383
415
|
const { isLoggedIn, isLoading } = sessionManager.useIsLoggedIn()
|
|
@@ -403,7 +435,12 @@ function SettingsPage() {
|
|
|
403
435
|
)
|
|
404
436
|
}
|
|
405
437
|
|
|
406
|
-
function SettingsForm({
|
|
438
|
+
function SettingsForm({
|
|
439
|
+
isLoading,
|
|
440
|
+
traitsForm,
|
|
441
|
+
newPasswordForm,
|
|
442
|
+
passkeysForm,
|
|
443
|
+
}: GetSettingsFormProps<typeof SettingsFlow>) {
|
|
407
444
|
if (isLoading) {
|
|
408
445
|
return <div>...loading</div>
|
|
409
446
|
}
|
|
@@ -495,9 +532,10 @@ and buttons. When wrapping your custom components with these slots, relevant pro
|
|
|
495
532
|
are automatically applied. If you use a custom component as a child, you receive props from one of the following types:
|
|
496
533
|
`CommonInputFieldProps`, `CommonCheckboxFieldProps`, or `CommonButtonProps`.
|
|
497
534
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
535
|
+
To type form components and error handlers, use the `Get*FormProps` and `GetFlowErrorHandler` type utilities with your
|
|
536
|
+
flow component. For example, `GetLoginChooseMethodFormProps<typeof LoginFlow>` or
|
|
537
|
+
`GetFlowErrorHandler<typeof RegistrationFlow>`. Types are inferred from the flow, so no need to pass traits or OIDC
|
|
538
|
+
config separately.
|
|
501
539
|
|
|
502
540
|
Some forms are typed as discriminated unions with multiple variants.
|
|
503
541
|
|
|
@@ -526,10 +564,8 @@ export const Input = ({ errors, ...props }: InputProps) => (
|
|
|
526
564
|
#### ChooseMethodForm in login flow
|
|
527
565
|
|
|
528
566
|
```tsx
|
|
529
|
-
import {
|
|
567
|
+
import type { GetLoginChooseMethodFormProps } from "@leancodepl/kratos"
|
|
530
568
|
import { LoginFlow, getErrorMessage } from "./kratosService"
|
|
531
|
-
import type { AuthTraitsConfig } from "./traits"
|
|
532
|
-
import type { OidcProvidersConfig } from "./kratosService"
|
|
533
569
|
|
|
534
570
|
function LoginPage() {
|
|
535
571
|
return (
|
|
@@ -540,8 +576,13 @@ function LoginPage() {
|
|
|
540
576
|
)
|
|
541
577
|
}
|
|
542
578
|
|
|
543
|
-
function ChooseMethodForm(props:
|
|
544
|
-
const {
|
|
579
|
+
function ChooseMethodForm(props: GetLoginChooseMethodFormProps<typeof LoginFlow>) {
|
|
580
|
+
const {
|
|
581
|
+
errors,
|
|
582
|
+
isSubmitting,
|
|
583
|
+
isValidating,
|
|
584
|
+
oidcProviders: { Google, Apple, Facebook },
|
|
585
|
+
} = props
|
|
545
586
|
|
|
546
587
|
if (props.isRefresh) {
|
|
547
588
|
const { passwordFields, Passkey, identifier } = props
|
|
@@ -657,9 +698,8 @@ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps<OidcProvidersCo
|
|
|
657
698
|
#### TraitsForm in registration flow
|
|
658
699
|
|
|
659
700
|
```tsx
|
|
660
|
-
import {
|
|
701
|
+
import type { GetFlowErrorHandler, GetRegistrationTraitsFormProps } from "@leancodepl/kratos"
|
|
661
702
|
import { RegistrationFlow, getErrorMessage } from "./kratosService"
|
|
662
|
-
import type { AuthTraitsConfig, OidcProvidersConfig } from "./kratosService"
|
|
663
703
|
|
|
664
704
|
function RegisterPage() {
|
|
665
705
|
return (
|
|
@@ -677,7 +717,7 @@ function TraitsForm({
|
|
|
677
717
|
traitFields: { Email, GivenName, RegulationsAccepted, Submit },
|
|
678
718
|
isSubmitting,
|
|
679
719
|
isValidating,
|
|
680
|
-
}:
|
|
720
|
+
}: GetRegistrationTraitsFormProps<typeof RegistrationFlow>) {
|
|
681
721
|
return (
|
|
682
722
|
<div>
|
|
683
723
|
<Email>
|
|
@@ -727,7 +767,7 @@ function TraitsForm({
|
|
|
727
767
|
)
|
|
728
768
|
}
|
|
729
769
|
|
|
730
|
-
const handleError:
|
|
770
|
+
const handleError: GetFlowErrorHandler<typeof RegistrationFlow> = ({ target, errors }) => {
|
|
731
771
|
if (target === "root") {
|
|
732
772
|
console.error("Form errors:", errors.map(getErrorMessage))
|
|
733
773
|
} else {
|