@korajs/auth 1.0.0-beta.10 → 1.0.0-beta.11
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/index.cjs +14 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1207,13 +1207,26 @@ function readDeviceIdFromClaims(claims) {
|
|
|
1207
1207
|
return typeof dev === "string" && dev.length > 0 ? dev : void 0;
|
|
1208
1208
|
}
|
|
1209
1209
|
function createKoraAuthSync(options) {
|
|
1210
|
-
const { authClient, schema, scopeFromClaims } = options;
|
|
1210
|
+
const { authClient, schema, scopeFromClaims, anonymous = "suspend" } = options;
|
|
1211
1211
|
const binding = {
|
|
1212
1212
|
auth: async () => {
|
|
1213
1213
|
const token = await authClient.getAccessToken();
|
|
1214
1214
|
return { token: token ?? "" };
|
|
1215
1215
|
}
|
|
1216
1216
|
};
|
|
1217
|
+
binding.resolveSyncState = async () => {
|
|
1218
|
+
if (authClient.state === "loading") return { state: "loading" };
|
|
1219
|
+
const token = await authClient.getAccessToken();
|
|
1220
|
+
if (!token) {
|
|
1221
|
+
return anonymous === "allow" ? { state: "anonymous", mayConnectAnonymously: true } : { state: "signed-out", mayConnectAnonymously: false };
|
|
1222
|
+
}
|
|
1223
|
+
const claims = decodeJwtPayload2(token);
|
|
1224
|
+
const userId = typeof claims?.sub === "string" ? claims.sub : "";
|
|
1225
|
+
if (!userId) {
|
|
1226
|
+
return anonymous === "allow" ? { state: "anonymous", mayConnectAnonymously: true } : { state: "signed-out", mayConnectAnonymously: false };
|
|
1227
|
+
}
|
|
1228
|
+
return { state: "authenticated", userId, token };
|
|
1229
|
+
};
|
|
1217
1230
|
if (schema) {
|
|
1218
1231
|
binding.resolveScopeMap = async () => {
|
|
1219
1232
|
const token = await authClient.getAccessToken();
|