@leancodepl/kratos 10.0.2 → 10.1.0

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 CHANGED
@@ -3,6 +3,43 @@
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.0](https://github.com/leancodepl/js_corelibrary/compare/v10.0.2...v10.1.0) (2026-02-16)
7
+
8
+ ### Bug Fixes
9
+
10
+ - Add OIDC providers config to example app and fix type issues
11
+ ([6c7f13b](https://github.com/leancodepl/js_corelibrary/commit/6c7f13b63498314ccdd742b2656767d3f4dd62b3))
12
+ - Address code review feedback
13
+ ([7830178](https://github.com/leancodepl/js_corelibrary/commit/7830178cba6147cd533bc6cbd7cd25e3c2d26fb1))
14
+ - Properly type OidcProviderUiNode attributes to avoid 'any'
15
+ ([27acdce](https://github.com/leancodepl/js_corelibrary/commit/27acdce9a874dfbe8e30566fc19f9b51aa6314d9))
16
+ - Remove unused imports and variables from OIDC provider implementation
17
+ ([2590a39](https://github.com/leancodepl/js_corelibrary/commit/2590a392e63181d0a6ea1ce4dc10ddf9b392c0d7))
18
+ - Resolve build failures in kratos package
19
+ ([c356f93](https://github.com/leancodepl/js_corelibrary/commit/c356f9366fbf623d32829e58d53afd58e374ca7d))
20
+ - Resolve linter errors and warnings
21
+ ([a900e5c](https://github.com/leancodepl/js_corelibrary/commit/a900e5c80664d4914114b0d2ca9f45fdb2c86854))
22
+ - Update documentation to show correct provider capitalization
23
+ ([980b62b](https://github.com/leancodepl/js_corelibrary/commit/980b62b707ac63f61c864d37ddd580b7225f94d6))
24
+
25
+ ### Features
26
+
27
+ - Add support for custom OIDC providers
28
+ ([a1ae459](https://github.com/leancodepl/js_corelibrary/commit/a1ae459ebb1a2d14bd9def97af7ec4dfec2e15da))
29
+ - Add type-safe OIDC provider support
30
+ ([b52ab23](https://github.com/leancodepl/js_corelibrary/commit/b52ab233096eeb91fae6850e7c30e5b0cb0a5b15))
31
+ - Make OidcFormProps generic with OidcProvidersConfig type
32
+ ([7957ff8](https://github.com/leancodepl/js_corelibrary/commit/7957ff84fb634b859a8a5f6bc114d2dc2ba3ec1d))
33
+ - remove label from oidc provider type amd spread oidc components
34
+ ([aa25a5f](https://github.com/leancodepl/js_corelibrary/commit/aa25a5f7ff0bb6b1cd2e36d23b3c61dd3621d77e))
35
+ - unify oidcProviderComponents implementations
36
+ ([74f7ad3](https://github.com/leancodepl/js_corelibrary/commit/74f7ad38211ff88826ffb21b9c73580854e27f3a))
37
+
38
+ # Change Log
39
+
40
+ All notable changes to this project will be documented in this file. See
41
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
42
+
6
43
  ## [10.0.2](https://github.com/leancodepl/js_corelibrary/compare/v10.0.1...v10.0.2) (2026-02-13)
7
44
 
8
45
  **Note:** Version bump only for package @leancodepl/kratos
package/README.md CHANGED
@@ -12,7 +12,7 @@ yarn add @leancodepl/kratos
12
12
 
13
13
  ## API
14
14
 
15
- ### `mkKratos(queryClient, basePath, traits, SessionManager)`
15
+ ### `mkKratos(queryClient, basePath, traits, SessionManager, oidcProviders)`
16
16
 
17
17
  Creates a Kratos client factory with authentication flows, session management, and React providers.
18
18
 
@@ -23,6 +23,8 @@ Creates a Kratos client factory with authentication flows, session management, a
23
23
  - `traits?: TTraitsConfig` - Optional traits configuration object for user schema validation
24
24
  - `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 provider
27
+ should have an `id` (matching Kratos provider ID)
26
28
 
27
29
  **Returns:** Object with the following structure:
28
30
 
@@ -201,6 +203,98 @@ const {
201
203
  })
202
204
  ```
203
205
 
206
+ ### Custom OIDC Providers
207
+
208
+ You can configure custom OIDC providers (like Microsoft, GitHub, etc.) in addition to the default providers (Apple, Google, Facebook):
209
+
210
+ ```typescript
211
+ // kratosService.ts
212
+
213
+ import { mkKratos } from "@leancodepl/kratos"
214
+ import { environment } from "./environments"
215
+ import { queryClient } from "./queryService"
216
+ import { traitsConfig } from "./traits"
217
+
218
+ const {
219
+ session: { sessionManager },
220
+ providers: { KratosProviders },
221
+ flows: { LoginFlow, RegistrationFlow, SettingsFlow },
222
+ } = mkKratos({
223
+ queryClient,
224
+ basePath: environment.authUrl,
225
+ traits: traitsConfig,
226
+ oidcProviders: [
227
+ { id: "microsoft" },
228
+ { id: "github" },
229
+ { id: "reddit" },
230
+ ],
231
+ })
232
+ ```
233
+
234
+ The OIDC providers are automatically made available in the flow forms as capitalized component properties. For example, a provider with `id: "microsoft"` will be available as `oidcProviders.Microsoft`.
235
+
236
+ With TypeScript, the library generates type-safe provider types from your configuration, ensuring you can only access providers you've configured:
237
+
238
+ ```tsx
239
+ // kratosService.ts
240
+
241
+ const oidcProvidersConfig = [
242
+ { id: "microsoft" },
243
+ { id: "github" },
244
+ { id: "reddit" },
245
+ ] as const
246
+
247
+ const {
248
+ session: { sessionManager },
249
+ providers: { KratosProviders },
250
+ flows: { LoginFlow, RegistrationFlow, SettingsFlow },
251
+ } = mkKratos({
252
+ queryClient,
253
+ basePath: environment.authUrl,
254
+ traits: traitsConfig,
255
+ oidcProviders: oidcProvidersConfig,
256
+ })
257
+
258
+ export type OidcProvidersConfig = typeof oidcProvidersConfig
259
+ ```
260
+
261
+ ```tsx
262
+ // loginPage.tsx
263
+
264
+ import { loginFlow } from "@leancodepl/kratos"
265
+ import type { OidcProvidersConfig } from "./kratosService"
266
+
267
+ // Note: Provider IDs are capitalized (first letter only) in the component names.
268
+ // For example, "github" becomes "Github", "microsoft" becomes "Microsoft".
269
+ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps<OidcProvidersConfig>) {
270
+ const { oidcProviders: { Microsoft, Github, Reddit }, isSubmitting, isValidating } = props
271
+
272
+ return (
273
+ <div>
274
+ {Microsoft && (
275
+ <Microsoft>
276
+ <button disabled={isSubmitting || isValidating}>Sign in with Microsoft</button>
277
+ </Microsoft>
278
+ )}
279
+
280
+ {Github && (
281
+ <Github>
282
+ <button disabled={isSubmitting || isValidating}>Sign in with GitHub</button>
283
+ </Github>
284
+ )}
285
+
286
+ {Reddit && (
287
+ <Reddit>
288
+ <button disabled={isSubmitting || isValidating}>Sign in with Reddit</button>
289
+ </Reddit>
290
+ )}
291
+ </div>
292
+ )
293
+ }
294
+ ```
295
+
296
+ The same pattern applies to registration and settings flows. Only providers configured in your Kratos instance will be available in the `oidcProviders` object, and TypeScript will provide autocomplete and type checking for the available providers.
297
+
204
298
  ### Session Management
205
299
 
206
300
  ```tsx
@@ -435,6 +529,7 @@ export const Input = ({ errors, ...props }: InputProps) => (
435
529
  import { loginFlow } from "@leancodepl/kratos"
436
530
  import { LoginFlow, getErrorMessage } from "./kratosService"
437
531
  import type { AuthTraitsConfig } from "./traits"
532
+ import type { OidcProvidersConfig } from "./kratosService"
438
533
 
439
534
  function LoginPage() {
440
535
  return (
@@ -445,11 +540,11 @@ function LoginPage() {
445
540
  )
446
541
  }
447
542
 
448
- function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps) {
449
- const { errors, isSubmitting, isValidating } = props
543
+ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps<OidcProvidersConfig>) {
544
+ const { errors, isSubmitting, isValidating, oidcProviders: { Google, Apple, Facebook } } = props
450
545
 
451
546
  if (props.isRefresh) {
452
- const { passwordFields, Google, Passkey, Apple, Facebook, identifier } = props
547
+ const { passwordFields, Passkey, identifier } = props
453
548
 
454
549
  return (
455
550
  <div>
@@ -508,10 +603,7 @@ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps) {
508
603
 
509
604
  const {
510
605
  passwordFields: { Identifier, Password, Submit },
511
- Google,
512
606
  Passkey,
513
- Apple,
514
- Facebook,
515
607
  } = props
516
608
 
517
609
  return (
@@ -528,17 +620,23 @@ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps) {
528
620
  <button>Login</button>
529
621
  </Submit>
530
622
 
531
- <Google>
532
- <button>Sign in with Google</button>
533
- </Google>
623
+ {Google && (
624
+ <Google>
625
+ <button>Sign in with Google</button>
626
+ </Google>
627
+ )}
534
628
 
535
- <Apple>
536
- <button>Sign in with Apple</button>
537
- </Apple>
629
+ {Apple && (
630
+ <Apple>
631
+ <button>Sign in with Apple</button>
632
+ </Apple>
633
+ )}
538
634
 
539
- <Facebook>
540
- <button>Sign in with Facebook</button>
541
- </Facebook>
635
+ {Facebook && (
636
+ <Facebook>
637
+ <button>Sign in with Facebook</button>
638
+ </Facebook>
639
+ )}
542
640
 
543
641
  <Passkey>
544
642
  <button>Sign in with Passkey</button>
@@ -561,7 +659,7 @@ function ChooseMethodForm(props: loginFlow.ChooseMethodFormProps) {
561
659
  ```tsx
562
660
  import { registrationFlow } from "@leancodepl/kratos"
563
661
  import { RegistrationFlow, getErrorMessage } from "./kratosService"
564
- import type { AuthTraitsConfig } from "./traits"
662
+ import type { AuthTraitsConfig, OidcProvidersConfig } from "./kratosService"
565
663
 
566
664
  function RegisterPage() {
567
665
  return (
@@ -575,36 +673,30 @@ function RegisterPage() {
575
673
 
576
674
  function TraitsForm({
577
675
  errors,
578
- Email,
579
- RegulationsAccepted,
580
- GivenName,
581
- Google,
582
- Apple,
583
- Facebook,
676
+ oidcProviders: { Google, Apple, Facebook },
677
+ traitFields: { Email, GivenName, RegulationsAccepted, Submit },
584
678
  isSubmitting,
585
679
  isValidating,
586
- }: registrationFlow.TraitsFormProps<AuthTraitsConfig>) {
680
+ }: registrationFlow.TraitsFormProps<AuthTraitsConfig, OidcProvidersConfig>) {
587
681
  return (
588
682
  <div>
589
- {Email && (
590
- <Email>
591
- <input placeholder="Email" />
592
- </Email>
593
- )}
594
- {GivenName && (
595
- <GivenName>
596
- <input placeholder="First name" />
597
- </GivenName>
598
- )}
599
- {RegulationsAccepted && (
600
- <RegulationsAccepted>
601
- <input placeholder="Regulations accepted" type="checkbox">
602
- I accept the regulations
603
- </input>
604
- </RegulationsAccepted>
605
- )}
683
+ <Email>
684
+ <input placeholder="Email" />
685
+ </Email>
606
686
 
607
- <button type="submit">Register</button>
687
+ <GivenName>
688
+ <input placeholder="First name" />
689
+ </GivenName>
690
+
691
+ <RegulationsAccepted>
692
+ <input placeholder="Regulations accepted" type="checkbox">
693
+ I accept the regulations
694
+ </input>
695
+ </RegulationsAccepted>
696
+
697
+ <Submit>
698
+ <button>Register</button>
699
+ </Submit>
608
700
 
609
701
  {Google && (
610
702
  <Google>