@stackframe/react 2.8.36 → 2.8.40
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 +40 -0
- package/dist/components/user-button.js +2 -2
- package/dist/components/user-button.js.map +1 -1
- package/dist/esm/components/user-button.js +2 -2
- package/dist/esm/components/user-button.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/integrations/convex.js +18 -0
- package/dist/esm/integrations/convex.js.map +1 -0
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +59 -6
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +140 -3
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +7 -7
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +112 -4
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/lib/stack-app/index.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/esm/providers/stack-provider-client.js.map +1 -1
- package/dist/index.d.mts +200 -43
- package/dist/index.d.ts +200 -43
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/convex.js +43 -0
- package/dist/integrations/convex.js.map +1 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +58 -5
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +140 -3
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +7 -7
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +111 -3
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/lib/stack-app/email/index.js.map +1 -1
- package/dist/lib/stack-app/index.js.map +1 -1
- package/dist/lib/stack-app/project-configs/index.js.map +1 -1
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/dist/providers/stack-provider-client.js.map +1 -1
- package/package.json +5 -4
|
@@ -123,6 +123,11 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
123
123
|
return results;
|
|
124
124
|
}
|
|
125
125
|
);
|
|
126
|
+
this._currentUserOAuthProvidersCache = createCacheBySession(
|
|
127
|
+
async (session) => {
|
|
128
|
+
return await this._interface.listOAuthProviders({ user_id: "me" }, session);
|
|
129
|
+
}
|
|
130
|
+
);
|
|
126
131
|
this._userItemCache = createCacheBySession(
|
|
127
132
|
async (session, [userId, itemId]) => {
|
|
128
133
|
return await this._interface.getItem({ userId, itemId }, session);
|
|
@@ -138,6 +143,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
138
143
|
return await this._interface.getItem({ customCustomerId, itemId }, session);
|
|
139
144
|
}
|
|
140
145
|
);
|
|
146
|
+
this._convexPartialUserCache = createCache(
|
|
147
|
+
async ([ctx]) => await this._getPartialUserFromConvex(ctx)
|
|
148
|
+
);
|
|
141
149
|
this._anonymousSignUpInProgress = null;
|
|
142
150
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
143
151
|
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
@@ -425,7 +433,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
425
433
|
}
|
|
426
434
|
async _getSession(overrideTokenStoreInit) {
|
|
427
435
|
const tokenStore = this._getOrCreateTokenStore(await this._createCookieHelper(), overrideTokenStoreInit);
|
|
428
|
-
|
|
436
|
+
const session = this._getSessionFromTokenStore(tokenStore);
|
|
437
|
+
return session;
|
|
429
438
|
}
|
|
430
439
|
_useSession(overrideTokenStoreInit) {
|
|
431
440
|
const tokenStore = this._useTokenStore(overrideTokenStoreInit);
|
|
@@ -646,6 +655,41 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
646
655
|
}
|
|
647
656
|
};
|
|
648
657
|
}
|
|
658
|
+
_clientOAuthProviderFromCrud(crud, session) {
|
|
659
|
+
const app = this;
|
|
660
|
+
return {
|
|
661
|
+
id: crud.id,
|
|
662
|
+
type: crud.type,
|
|
663
|
+
userId: crud.user_id,
|
|
664
|
+
email: crud.email,
|
|
665
|
+
allowSignIn: crud.allow_sign_in,
|
|
666
|
+
allowConnectedAccounts: crud.allow_connected_accounts,
|
|
667
|
+
async update(data) {
|
|
668
|
+
try {
|
|
669
|
+
await app._interface.updateOAuthProvider(
|
|
670
|
+
crud.user_id,
|
|
671
|
+
crud.id,
|
|
672
|
+
{
|
|
673
|
+
allow_sign_in: data.allowSignIn,
|
|
674
|
+
allow_connected_accounts: data.allowConnectedAccounts
|
|
675
|
+
},
|
|
676
|
+
session
|
|
677
|
+
);
|
|
678
|
+
await app._currentUserOAuthProvidersCache.refresh([session]);
|
|
679
|
+
return Result.ok(void 0);
|
|
680
|
+
} catch (error) {
|
|
681
|
+
if (KnownErrors.OAuthProviderAccountIdAlreadyUsedForSignIn.isInstance(error)) {
|
|
682
|
+
return Result.error(error);
|
|
683
|
+
}
|
|
684
|
+
throw error;
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
async delete() {
|
|
688
|
+
await app._interface.deleteOAuthProvider(crud.user_id, crud.id, session);
|
|
689
|
+
await app._currentUserOAuthProvidersCache.refresh([session]);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
}
|
|
649
693
|
_clientItemFromCrud(crud) {
|
|
650
694
|
const app = this;
|
|
651
695
|
return {
|
|
@@ -937,6 +981,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
937
981
|
);
|
|
938
982
|
await app._userApiKeysCache.refresh([session]);
|
|
939
983
|
return app._clientApiKeyFromCrud(session, result);
|
|
984
|
+
},
|
|
985
|
+
useOAuthProviders() {
|
|
986
|
+
const results = useAsyncCache(app._currentUserOAuthProvidersCache, [session], "user.useOAuthProviders()");
|
|
987
|
+
return results.map((crud2) => app._clientOAuthProviderFromCrud(crud2, session));
|
|
988
|
+
},
|
|
989
|
+
async listOAuthProviders() {
|
|
990
|
+
const results = Result.orThrow(await app._currentUserOAuthProvidersCache.getOrWait([session], "write-only"));
|
|
991
|
+
return results.map((crud2) => app._clientOAuthProviderFromCrud(crud2, session));
|
|
992
|
+
},
|
|
993
|
+
useOAuthProvider(id) {
|
|
994
|
+
const providers = this.useOAuthProviders();
|
|
995
|
+
return useMemo(() => providers.find((p) => p.id === id) ?? null, [providers, id]);
|
|
996
|
+
},
|
|
997
|
+
async getOAuthProvider(id) {
|
|
998
|
+
const providers = await this.listOAuthProviders();
|
|
999
|
+
return providers.find((p) => p.id === id) ?? null;
|
|
940
1000
|
}
|
|
941
1001
|
};
|
|
942
1002
|
}
|
|
@@ -1260,12 +1320,89 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1260
1320
|
return crud && this._currentUserFromCrud(crud, session);
|
|
1261
1321
|
}, [crud, session, options?.or]);
|
|
1262
1322
|
}
|
|
1323
|
+
_getTokenPartialUserFromSession(session, options) {
|
|
1324
|
+
const accessToken = session.getAccessTokenIfNotExpiredYet(0);
|
|
1325
|
+
if (!accessToken) {
|
|
1326
|
+
return null;
|
|
1327
|
+
}
|
|
1328
|
+
const isAnonymous = accessToken.payload.is_anonymous;
|
|
1329
|
+
if (isAnonymous && options.or !== "anonymous") {
|
|
1330
|
+
return null;
|
|
1331
|
+
}
|
|
1332
|
+
return {
|
|
1333
|
+
id: accessToken.payload.sub,
|
|
1334
|
+
primaryEmail: accessToken.payload.email,
|
|
1335
|
+
displayName: accessToken.payload.name,
|
|
1336
|
+
primaryEmailVerified: accessToken.payload.email_verified,
|
|
1337
|
+
isAnonymous
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
async _getPartialUserFromConvex(ctx) {
|
|
1341
|
+
const auth = await ctx.auth.getUserIdentity();
|
|
1342
|
+
if (!auth) {
|
|
1343
|
+
return null;
|
|
1344
|
+
}
|
|
1345
|
+
return {
|
|
1346
|
+
id: auth.subject,
|
|
1347
|
+
displayName: auth.name ?? null,
|
|
1348
|
+
primaryEmail: auth.email ?? null,
|
|
1349
|
+
primaryEmailVerified: auth.email_verified,
|
|
1350
|
+
isAnonymous: auth.is_anonymous
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
async getPartialUser(options) {
|
|
1354
|
+
switch (options.from) {
|
|
1355
|
+
case "token": {
|
|
1356
|
+
this._ensurePersistentTokenStore(options.tokenStore ?? this._tokenStoreInit);
|
|
1357
|
+
const session = await this._getSession(options.tokenStore);
|
|
1358
|
+
return this._getTokenPartialUserFromSession(session, options);
|
|
1359
|
+
}
|
|
1360
|
+
case "convex": {
|
|
1361
|
+
return await this._getPartialUserFromConvex(options.ctx);
|
|
1362
|
+
}
|
|
1363
|
+
default: {
|
|
1364
|
+
throw new Error(`Invalid 'from' option: ${options.from}`);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
usePartialUser(options) {
|
|
1369
|
+
switch (options.from) {
|
|
1370
|
+
case "token": {
|
|
1371
|
+
this._ensurePersistentTokenStore(options.tokenStore ?? this._tokenStoreInit);
|
|
1372
|
+
const session = this._useSession(options.tokenStore);
|
|
1373
|
+
return this._getTokenPartialUserFromSession(session, options);
|
|
1374
|
+
}
|
|
1375
|
+
case "convex": {
|
|
1376
|
+
const result = useAsyncCache(this._convexPartialUserCache, [options.ctx], "usePartialUser(convex)");
|
|
1377
|
+
return result;
|
|
1378
|
+
}
|
|
1379
|
+
default: {
|
|
1380
|
+
throw new Error(`Invalid 'from' option: ${options.from}`);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
getConvexClientAuth(options) {
|
|
1385
|
+
return async (args) => {
|
|
1386
|
+
const session = await this._getSession(options.tokenStore);
|
|
1387
|
+
if (!args.forceRefreshToken) {
|
|
1388
|
+
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1389
|
+
return tokens2?.accessToken.token ?? null;
|
|
1390
|
+
}
|
|
1391
|
+
const tokens = await session.fetchNewTokens();
|
|
1392
|
+
return tokens?.accessToken.token ?? null;
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
async getConvexHttpClientAuth(options) {
|
|
1396
|
+
const session = await this._getSession(options.tokenStore);
|
|
1397
|
+
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1398
|
+
return tokens?.accessToken.token ?? throwErr("No access token available");
|
|
1399
|
+
}
|
|
1263
1400
|
async _updateClientUser(update, session) {
|
|
1264
1401
|
const res = await this._interface.updateClientUser(userUpdateOptionsToCrud(update), session);
|
|
1265
1402
|
await this._refreshUser(session);
|
|
1266
1403
|
return res;
|
|
1267
1404
|
}
|
|
1268
|
-
async signInWithOAuth(provider) {
|
|
1405
|
+
async signInWithOAuth(provider, options) {
|
|
1269
1406
|
if (typeof window === "undefined") {
|
|
1270
1407
|
throw new Error("signInWithOAuth can currently only be called in a browser environment");
|
|
1271
1408
|
}
|
|
@@ -1275,7 +1412,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1275
1412
|
this._interface,
|
|
1276
1413
|
{
|
|
1277
1414
|
provider,
|
|
1278
|
-
redirectUrl: this.urls.oauthCallback,
|
|
1415
|
+
redirectUrl: options?.returnTo ?? this.urls.oauthCallback,
|
|
1279
1416
|
errorRedirectUrl: this.urls.error,
|
|
1280
1417
|
providerScope: this._oauthScopesOnSignIn[provider]?.join(" ")
|
|
1281
1418
|
},
|