@stackframe/stack 2.5.23 → 2.5.24
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 +10 -0
- package/dist/esm/lib/stack-app.js +45 -35
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/lib/stack-app.d.mts +1 -1
- package/dist/lib/stack-app.d.ts +1 -1
- package/dist/lib/stack-app.js +45 -35
- package/dist/lib/stack-app.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -24,7 +24,7 @@ import { constructRedirectUrl } from "../utils/url";
|
|
|
24
24
|
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
|
|
25
25
|
import { deleteCookie, getCookie, setOrDeleteCookie } from "./cookie";
|
|
26
26
|
var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
|
|
27
|
-
var clientVersion = "js @stackframe/stack@2.5.
|
|
27
|
+
var clientVersion = "js @stackframe/stack@2.5.24";
|
|
28
28
|
function getUrls(partial) {
|
|
29
29
|
const handler = partial.handler ?? "/handler";
|
|
30
30
|
const home = partial.home ?? "/";
|
|
@@ -1466,24 +1466,29 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1466
1466
|
return this._serverUserFromCrud(crud);
|
|
1467
1467
|
}
|
|
1468
1468
|
async getUser(options) {
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1469
|
+
if (typeof options === "string") {
|
|
1470
|
+
const allUsers = await this.listUsers();
|
|
1471
|
+
return allUsers.find((u) => u.id === options) ?? null;
|
|
1472
|
+
} else {
|
|
1473
|
+
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1474
|
+
const session = this._getSession(options?.tokenStore);
|
|
1475
|
+
const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
|
|
1476
|
+
if (crud === null) {
|
|
1477
|
+
switch (options?.or) {
|
|
1478
|
+
case "redirect": {
|
|
1479
|
+
await this.redirectToSignIn({ replace: true });
|
|
1480
|
+
break;
|
|
1481
|
+
}
|
|
1482
|
+
case "throw": {
|
|
1483
|
+
throw new Error("User is not signed in but getUser was called with { or: 'throw' }");
|
|
1484
|
+
}
|
|
1485
|
+
default: {
|
|
1486
|
+
return null;
|
|
1487
|
+
}
|
|
1483
1488
|
}
|
|
1484
1489
|
}
|
|
1490
|
+
return crud && this._currentUserFromCrud(crud, session);
|
|
1485
1491
|
}
|
|
1486
|
-
return crud && this._currentUserFromCrud(crud, session);
|
|
1487
1492
|
}
|
|
1488
1493
|
async getServerUser() {
|
|
1489
1494
|
console.warn("stackServerApp.getServerUser is deprecated; use stackServerApp.getUser instead");
|
|
@@ -1494,28 +1499,33 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1494
1499
|
return crud && this._serverUserFromCrud(crud);
|
|
1495
1500
|
}
|
|
1496
1501
|
useUser(options) {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1502
|
+
if (typeof options === "string") {
|
|
1503
|
+
const users = this.useUsers();
|
|
1504
|
+
return users.find((u) => u.id === options) ?? null;
|
|
1505
|
+
} else {
|
|
1506
|
+
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1507
|
+
const router = NextNavigation.useRouter();
|
|
1508
|
+
const session = this._getSession(options?.tokenStore);
|
|
1509
|
+
const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
|
|
1510
|
+
if (crud === null) {
|
|
1511
|
+
switch (options?.or) {
|
|
1512
|
+
case "redirect": {
|
|
1513
|
+
runAsynchronously(this.redirectToSignIn({ replace: true }));
|
|
1514
|
+
suspend();
|
|
1515
|
+
throw new StackAssertionError("suspend should never return");
|
|
1516
|
+
}
|
|
1517
|
+
case "throw": {
|
|
1518
|
+
throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
|
|
1519
|
+
}
|
|
1520
|
+
case void 0:
|
|
1521
|
+
case "return-null": {
|
|
1522
|
+
}
|
|
1513
1523
|
}
|
|
1514
1524
|
}
|
|
1525
|
+
return useMemo(() => {
|
|
1526
|
+
return crud && this._currentUserFromCrud(crud, session);
|
|
1527
|
+
}, [crud, session, options?.or]);
|
|
1515
1528
|
}
|
|
1516
|
-
return useMemo(() => {
|
|
1517
|
-
return crud && this._currentUserFromCrud(crud, session);
|
|
1518
|
-
}, [crud, session, options?.or]);
|
|
1519
1529
|
}
|
|
1520
1530
|
useUserById(userId) {
|
|
1521
1531
|
const crud = useAsyncCache(this._serverUserCache, [userId], "useUserById()");
|