@multiplatform.one/keycloak 7.34.3 → 7.35.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/dist/cjs/index.cjs +120 -70
- package/dist/cjs/index.native.cjs +283 -148
- package/dist/esm/index.js +78 -28
- package/dist/esm/index.native.js +270 -135
- package/package.json +9 -9
- package/src/betterAuth/expoAuthFlow.deadline.spec.ts +230 -0
- package/src/betterAuth/expoAuthFlow.native.ts +67 -27
- package/src/keycloak/base.ts +3 -2
- package/src/keycloak/context.ts +2 -2
- package/src/keycloak/index.ts +26 -13
- package/src/keycloak/login.error.spec.tsx +85 -0
- package/src/provider/KeycloakProvider.loading.spec.tsx +37 -0
- package/src/provider/KeycloakProvider.tsx +16 -9
- package/src/provider/authProvider/index.native.tsx +170 -108
- package/src/provider/authProvider/nonblocking.native.spec.tsx +303 -0
- package/src/session/authError.ts +30 -0
- package/src/session/index.native.ts +6 -1
- package/src/session/index.ts +11 -4
- package/types/betterAuth/expoAuthFlow.native.d.ts +3 -1
- package/types/betterAuth/expoAuthFlow.native.d.ts.map +1 -1
- package/types/keycloak/base.d.ts +1 -1
- package/types/keycloak/base.d.ts.map +1 -1
- package/types/keycloak/context.d.ts +2 -2
- package/types/keycloak/context.d.ts.map +1 -1
- package/types/keycloak/index.d.ts +1 -1
- package/types/keycloak/index.d.ts.map +1 -1
- package/types/keycloak/index.native.d.ts +1 -1
- package/types/keycloak/index.native.d.ts.map +1 -1
- package/types/keycloak/index.webext.d.ts +1 -1
- package/types/keycloak/index.webext.d.ts.map +1 -1
- package/types/provider/KeycloakProvider.d.ts +3 -2
- package/types/provider/KeycloakProvider.d.ts.map +1 -1
- package/types/provider/authProvider/index.native.d.ts +1 -1
- package/types/provider/authProvider/index.native.d.ts.map +1 -1
- package/types/session/authError.d.ts +7 -0
- package/types/session/authError.d.ts.map +1 -0
- package/types/session/index.d.ts +2 -0
- package/types/session/index.d.ts.map +1 -1
- package/types/session/index.native.d.ts +1 -0
- package/types/session/index.native.d.ts.map +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -452,26 +452,55 @@ function watchKeycloakBearerTokenRevalidate() {
|
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
454
|
|
|
455
|
+
// src/session/authError.ts
|
|
456
|
+
import { useSyncExternalStore } from "react";
|
|
457
|
+
var error;
|
|
458
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
459
|
+
var AuthTimeoutError = class extends Error {
|
|
460
|
+
constructor(timeoutMs = 1e4) {
|
|
461
|
+
super(`Authentication request timed out after ${timeoutMs}ms`);
|
|
462
|
+
this.name = "AuthTimeoutError";
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
function setAuthError(next) {
|
|
466
|
+
if (error === next) return;
|
|
467
|
+
error = next;
|
|
468
|
+
for (const listener of listeners) listener();
|
|
469
|
+
}
|
|
470
|
+
function getAuthError() {
|
|
471
|
+
return error;
|
|
472
|
+
}
|
|
473
|
+
function subscribe(listener) {
|
|
474
|
+
listeners.add(listener);
|
|
475
|
+
return () => listeners.delete(listener);
|
|
476
|
+
}
|
|
477
|
+
function useAuthError() {
|
|
478
|
+
return useSyncExternalStore(subscribe, getAuthError, getAuthError);
|
|
479
|
+
}
|
|
480
|
+
|
|
455
481
|
// src/session/index.ts
|
|
456
482
|
var useSession = (_options) => {
|
|
457
|
-
return { session: null, status: "unauthenticated" };
|
|
483
|
+
return { session: null, status: "unauthenticated", error: useAuthError() };
|
|
458
484
|
};
|
|
459
485
|
if (isBrowser) {
|
|
460
486
|
useSession = (_options) => {
|
|
461
487
|
const client = getAuthClient();
|
|
462
|
-
const { data, isPending, error:
|
|
488
|
+
const { data, isPending, error: sessionError } = client.useSession();
|
|
489
|
+
const authError = useAuthError();
|
|
490
|
+
const error2 = sessionError ?? authError;
|
|
463
491
|
if (isPending) {
|
|
464
|
-
return { session: null, status: "loading" };
|
|
492
|
+
return { session: null, status: "loading", error: error2 };
|
|
465
493
|
}
|
|
466
494
|
if (!data?.user) {
|
|
467
|
-
return { session: null, status: "unauthenticated" };
|
|
495
|
+
return { session: null, status: "unauthenticated", error: error2 };
|
|
468
496
|
}
|
|
469
497
|
return {
|
|
470
498
|
session: {
|
|
471
499
|
user: data.user,
|
|
472
500
|
expires: data.session?.expiresAt?.toString()
|
|
473
501
|
},
|
|
474
|
-
status: "authenticated"
|
|
502
|
+
status: "authenticated",
|
|
503
|
+
error: error2
|
|
475
504
|
};
|
|
476
505
|
};
|
|
477
506
|
}
|
|
@@ -591,8 +620,9 @@ var BaseKeycloak = class {
|
|
|
591
620
|
this._clear();
|
|
592
621
|
if (this._keycloakClient) {
|
|
593
622
|
await this._keycloakClient.login(options);
|
|
594
|
-
} else {
|
|
595
|
-
await this._login
|
|
623
|
+
} else if (this._login) {
|
|
624
|
+
await this._login(options);
|
|
625
|
+
return;
|
|
596
626
|
}
|
|
597
627
|
this._sync();
|
|
598
628
|
}
|
|
@@ -630,19 +660,29 @@ var Keycloak = class extends BaseKeycloak {
|
|
|
630
660
|
}
|
|
631
661
|
}
|
|
632
662
|
async login(options = {}) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
})
|
|
642
|
-
|
|
643
|
-
|
|
663
|
+
setAuthError();
|
|
664
|
+
try {
|
|
665
|
+
this._clear();
|
|
666
|
+
if (this._keycloakClient) {
|
|
667
|
+
await this._keycloakClient.login(options);
|
|
668
|
+
this._sync();
|
|
669
|
+
} else if (this._login) {
|
|
670
|
+
await this._login(options);
|
|
671
|
+
} else if (isBrowser && !isServer2) {
|
|
672
|
+
const client = getAuthClient();
|
|
673
|
+
const result = await client.signIn.social({
|
|
674
|
+
provider: "keycloak",
|
|
675
|
+
callbackURL: options.redirectUri || (isWeb2 ? window.location.href : "")
|
|
676
|
+
});
|
|
677
|
+
if (result?.error) {
|
|
678
|
+
throw result.error instanceof Error ? result.error : new Error(result.error.message || "Sign-in failed");
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
} catch (cause) {
|
|
682
|
+
const error2 = cause instanceof Error ? cause : new Error(String(cause));
|
|
683
|
+
setAuthError(error2);
|
|
684
|
+
throw error2;
|
|
644
685
|
}
|
|
645
|
-
this._sync();
|
|
646
686
|
}
|
|
647
687
|
async logout(options = {}) {
|
|
648
688
|
if (this._keycloakClient) {
|
|
@@ -678,9 +718,9 @@ function useKeycloak() {
|
|
|
678
718
|
const keycloak = useContext3(KeycloakContext);
|
|
679
719
|
const keycloakConfig = useContext3(KeycloakConfigContext);
|
|
680
720
|
const { disabled } = useAuthConfig();
|
|
721
|
+
const { session, status } = useSession();
|
|
681
722
|
if (disabled) return null;
|
|
682
723
|
if (keycloak) return keycloak;
|
|
683
|
-
const { session, status } = useSession();
|
|
684
724
|
if (isStorybook) {
|
|
685
725
|
return new Keycloak(keycloakConfig, {
|
|
686
726
|
email: "storybook@example.com",
|
|
@@ -1231,6 +1271,7 @@ function KeycloakProvider({
|
|
|
1231
1271
|
clientId,
|
|
1232
1272
|
expoScheme,
|
|
1233
1273
|
loginRedirectUri,
|
|
1274
|
+
loadingComponent,
|
|
1234
1275
|
debug,
|
|
1235
1276
|
disabled,
|
|
1236
1277
|
iframeSso,
|
|
@@ -1241,18 +1282,23 @@ function KeycloakProvider({
|
|
|
1241
1282
|
() => ({ debug, disabled, iframeSso, loginRedirectUri }),
|
|
1242
1283
|
[debug, disabled, iframeSso, loginRedirectUri]
|
|
1243
1284
|
);
|
|
1285
|
+
const keycloakConfig = useMemo2(
|
|
1286
|
+
() => ({
|
|
1287
|
+
clientId: clientId || "app",
|
|
1288
|
+
publicClientId,
|
|
1289
|
+
realm: realm || "main",
|
|
1290
|
+
url: baseUrl ?? "",
|
|
1291
|
+
betterAuthBaseUrl,
|
|
1292
|
+
expoScheme
|
|
1293
|
+
}),
|
|
1294
|
+
[clientId, publicClientId, realm, baseUrl, betterAuthBaseUrl, expoScheme]
|
|
1295
|
+
);
|
|
1244
1296
|
return /* @__PURE__ */ jsx5(AuthConfigContext.Provider, { value: authConfig, children: /* @__PURE__ */ jsx5(
|
|
1245
1297
|
AuthProvider,
|
|
1246
1298
|
{
|
|
1247
1299
|
disabled,
|
|
1248
|
-
keycloakConfig
|
|
1249
|
-
|
|
1250
|
-
publicClientId,
|
|
1251
|
-
realm: realm || "main",
|
|
1252
|
-
url: baseUrl ?? "",
|
|
1253
|
-
betterAuthBaseUrl,
|
|
1254
|
-
expoScheme
|
|
1255
|
-
},
|
|
1300
|
+
keycloakConfig,
|
|
1301
|
+
loadingComponent,
|
|
1256
1302
|
children
|
|
1257
1303
|
}
|
|
1258
1304
|
) });
|
|
@@ -1261,6 +1307,7 @@ export {
|
|
|
1261
1307
|
AfterAuth,
|
|
1262
1308
|
AuthConfigContext,
|
|
1263
1309
|
AuthProvider,
|
|
1310
|
+
AuthTimeoutError,
|
|
1264
1311
|
Authenticated,
|
|
1265
1312
|
BaseKeycloak,
|
|
1266
1313
|
Keycloak,
|
|
@@ -1268,12 +1315,15 @@ export {
|
|
|
1268
1315
|
KeycloakProvider,
|
|
1269
1316
|
defaultAuthConfig,
|
|
1270
1317
|
getAllWalletAddresses,
|
|
1318
|
+
getAuthError,
|
|
1271
1319
|
getKeycloakBearerToken,
|
|
1272
1320
|
getWalletAddresses,
|
|
1273
1321
|
getWalletsFromToken,
|
|
1274
1322
|
hasWallets,
|
|
1275
1323
|
isTokenExpired,
|
|
1324
|
+
setAuthError,
|
|
1276
1325
|
useAuthConfig,
|
|
1326
|
+
useAuthError,
|
|
1277
1327
|
useKeycloak,
|
|
1278
1328
|
useSession,
|
|
1279
1329
|
useTokensFromQuery,
|