@block-auth.io/core 0.4.2 → 0.5.2
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 +217 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -6
- package/dist/index.d.ts +69 -6
- package/dist/index.js +217 -51
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -21,8 +21,70 @@ var __export = (target, all) => {
|
|
|
21
21
|
for (var name in all)
|
|
22
22
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
// src/utils/apiBridge.ts
|
|
26
|
+
var DEFAULT_API_URL = "https://api.block-auth.io";
|
|
27
|
+
function buildApiUrl(path, apiUrl) {
|
|
28
|
+
const base = (apiUrl || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
29
|
+
return `${base}${path}`;
|
|
30
|
+
}
|
|
31
|
+
async function bridgeSessionCookie(token, apiUrl) {
|
|
32
|
+
if (!token || typeof fetch === "undefined") return false;
|
|
33
|
+
try {
|
|
34
|
+
const response = await fetch(buildApiUrl("/auth/session", apiUrl), {
|
|
35
|
+
method: "POST",
|
|
36
|
+
credentials: "include",
|
|
37
|
+
headers: { "Content-Type": "application/json" },
|
|
38
|
+
body: JSON.stringify({ token })
|
|
39
|
+
});
|
|
40
|
+
return response.ok;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn("[block-auth] failed to bridge session cookie", error);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function clearSessionCookie(apiUrl) {
|
|
47
|
+
if (typeof fetch === "undefined") return false;
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch(buildApiUrl("/auth/logout", apiUrl), {
|
|
50
|
+
method: "POST",
|
|
51
|
+
credentials: "include"
|
|
52
|
+
});
|
|
53
|
+
return response.ok;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.warn("[block-auth] failed to clear session cookie", error);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function fetchWsTicket(apiUrl) {
|
|
60
|
+
if (typeof fetch === "undefined") return null;
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch(buildApiUrl("/auth/ws-ticket", apiUrl), {
|
|
63
|
+
method: "GET",
|
|
64
|
+
credentials: "include"
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) return null;
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
return data?.ticket || null;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.warn("[block-auth] failed to fetch ws ticket", error);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/protocol/WsClient.ts
|
|
24
76
|
var WsClient = class {
|
|
25
|
-
|
|
77
|
+
/**
|
|
78
|
+
* @param url - the wss:// endpoint to connect to.
|
|
79
|
+
* @param reconnect - allow socket.io to auto-reconnect.
|
|
80
|
+
* @param apiUrl - backend base url used to fetch the short-lived WS
|
|
81
|
+
* connect ticket (GET /auth/ws-ticket) right before opening the socket.
|
|
82
|
+
* Defaults to https://api.block-auth.io. The cookie set by
|
|
83
|
+
* POST /auth/session is host-only to the API origin, so it can't reach
|
|
84
|
+
* this (different-host) WS endpoint directly — the ticket is what
|
|
85
|
+
* actually authenticates the connection now.
|
|
86
|
+
*/
|
|
87
|
+
constructor(url = "", reconnect = false, apiUrl) {
|
|
26
88
|
this._uiConfig = {};
|
|
27
89
|
this._accessToken = "";
|
|
28
90
|
this._refreshToken = "";
|
|
@@ -32,8 +94,13 @@ var WsClient = class {
|
|
|
32
94
|
this._logs = [];
|
|
33
95
|
this._kycIssuerByAddress = {};
|
|
34
96
|
this._wsUrl = url || "wss://wss.block-auth.io/";
|
|
97
|
+
this._apiUrl = apiUrl;
|
|
35
98
|
this._wsConfig = {
|
|
36
99
|
transports: ["websocket"],
|
|
100
|
+
// No longer load-bearing for auth (the session cookie can't reach
|
|
101
|
+
// this host), kept as a harmless default; see the ticket-based `auth`
|
|
102
|
+
// option added in connect() below for the auth that actually matters.
|
|
103
|
+
withCredentials: true,
|
|
37
104
|
reconnection: reconnect,
|
|
38
105
|
reconnectionDelay: 100,
|
|
39
106
|
reconnectionDelayMax: 3e3,
|
|
@@ -58,6 +125,9 @@ var WsClient = class {
|
|
|
58
125
|
*/
|
|
59
126
|
async connect(url = "", waitMs = 5e3, retries = 3) {
|
|
60
127
|
const _url = url || this._wsUrl;
|
|
128
|
+
this._wsConfig.auth = (done) => {
|
|
129
|
+
fetchWsTicket(this._apiUrl).then((ticket) => done(ticket ? { ticket } : {})).catch(() => done({}));
|
|
130
|
+
};
|
|
61
131
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
62
132
|
if (this._ws) {
|
|
63
133
|
this._ws.disconnect();
|
|
@@ -111,6 +181,24 @@ var WsClient = class {
|
|
|
111
181
|
this.on("sdk:roles", this.onSdkRoles);
|
|
112
182
|
this.on("sdk:logs", this.onSdkLogs);
|
|
113
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Re-authenticates the CURRENT connection in place: fetches a fresh
|
|
186
|
+
* ws-ticket and sends it over the already-open socket, so the server
|
|
187
|
+
* updates its view of who this connection belongs to without a
|
|
188
|
+
* disconnect/reconnect. A full reconnect would replace `this._ws` with a
|
|
189
|
+
* brand new socket.io instance, silently dropping every listener
|
|
190
|
+
* authRuntime registered on the old one (e.g. the response side of
|
|
191
|
+
* requestSignin -> user:txns:create -> sign) - this avoids that.
|
|
192
|
+
* No-op if there is no open connection yet (connect() will pick up a
|
|
193
|
+
* ticket on its own once one exists).
|
|
194
|
+
* @returns Promise<void>
|
|
195
|
+
*/
|
|
196
|
+
async refreshAuth() {
|
|
197
|
+
if (!this.isConnected()) return;
|
|
198
|
+
const ticket = await fetchWsTicket(this._apiUrl);
|
|
199
|
+
if (!ticket) return;
|
|
200
|
+
this._ws.emit("auth:refresh", ticket);
|
|
201
|
+
}
|
|
114
202
|
/**
|
|
115
203
|
* Allow you to subscribe to an event, and
|
|
116
204
|
* verify if the event is already subscribed
|
|
@@ -519,9 +607,9 @@ var hasAnyRoleBySlug = (user, roleSlugs) => {
|
|
|
519
607
|
|
|
520
608
|
// src/protocol/BlockAuthProvider.ts
|
|
521
609
|
var BlockAuthProvider = class {
|
|
522
|
-
constructor(apiKey = "", apiSecret = "", wsUrl = "wss://wss.block-auth.io") {
|
|
610
|
+
constructor(apiKey = "", apiSecret = "", wsUrl = "wss://wss.block-auth.io", options = {}) {
|
|
523
611
|
this._rpc = new RpcClient();
|
|
524
|
-
this._wsc = new WsClient(wsUrl, true);
|
|
612
|
+
this._wsc = new WsClient(wsUrl, true, options.apiUrl);
|
|
525
613
|
this._apiKey = apiKey;
|
|
526
614
|
this._apiSecret = apiSecret;
|
|
527
615
|
}
|
|
@@ -962,9 +1050,7 @@ var UI_CONFIG = {
|
|
|
962
1050
|
isLocked: false
|
|
963
1051
|
};
|
|
964
1052
|
var SESSION_CONFIG = {
|
|
965
|
-
did: ""
|
|
966
|
-
token: ""
|
|
967
|
-
};
|
|
1053
|
+
did: ""};
|
|
968
1054
|
var EXTERNAL_SERVICE_CONFIG = {
|
|
969
1055
|
connected: false,
|
|
970
1056
|
service: "blockauth",
|
|
@@ -982,6 +1068,11 @@ function getStorage() {
|
|
|
982
1068
|
return null;
|
|
983
1069
|
}
|
|
984
1070
|
var BrowserBase = class {
|
|
1071
|
+
constructor() {
|
|
1072
|
+
// In-memory only - see the SECURITY NOTE above. Never persisted.
|
|
1073
|
+
this._sessionToken = "";
|
|
1074
|
+
this._externalToken = "";
|
|
1075
|
+
}
|
|
985
1076
|
/**
|
|
986
1077
|
* Wipe every SDK-owned localStorage key and reseed the defaults. Unlike a
|
|
987
1078
|
* per-key reset it also clears the `blockauth-logged-out` /
|
|
@@ -1000,6 +1091,8 @@ var BrowserBase = class {
|
|
|
1000
1091
|
if (keepExtensionInstalled) {
|
|
1001
1092
|
storage.setItem(UI, JSON.stringify({ ...UI_CONFIG, installed: true }));
|
|
1002
1093
|
}
|
|
1094
|
+
this._sessionToken = "";
|
|
1095
|
+
this._externalToken = "";
|
|
1003
1096
|
this.getUI();
|
|
1004
1097
|
this.getSession();
|
|
1005
1098
|
this.getExternalService();
|
|
@@ -1016,10 +1109,12 @@ var BrowserBase = class {
|
|
|
1016
1109
|
}
|
|
1017
1110
|
if (target === "session") {
|
|
1018
1111
|
storage?.removeItem(SESSION);
|
|
1112
|
+
this._sessionToken = "";
|
|
1019
1113
|
this.getSession();
|
|
1020
1114
|
}
|
|
1021
1115
|
if (target === "external") {
|
|
1022
1116
|
storage?.removeItem(EXTERNAL_SERVICE);
|
|
1117
|
+
this._externalToken = "";
|
|
1023
1118
|
this.getExternalService();
|
|
1024
1119
|
}
|
|
1025
1120
|
}
|
|
@@ -1079,33 +1174,55 @@ var BrowserBase = class {
|
|
|
1079
1174
|
})
|
|
1080
1175
|
);
|
|
1081
1176
|
}
|
|
1177
|
+
/**
|
|
1178
|
+
* `did` is read from localStorage; `token` is never persisted there (see
|
|
1179
|
+
* the SECURITY NOTE above) and comes from the in-memory field instead, so
|
|
1180
|
+
* it reads back as '' after a page reload even though `did` survives.
|
|
1181
|
+
*/
|
|
1082
1182
|
getSession() {
|
|
1083
1183
|
const storage = getStorage();
|
|
1084
|
-
if (!storage) return {
|
|
1184
|
+
if (!storage) return { did: "", token: this._sessionToken };
|
|
1085
1185
|
const currentConfig = storage.getItem(SESSION);
|
|
1086
|
-
if (currentConfig)
|
|
1087
|
-
|
|
1088
|
-
|
|
1186
|
+
if (currentConfig) {
|
|
1187
|
+
const { did } = JSON.parse(currentConfig);
|
|
1188
|
+
return { did: did || "", token: this._sessionToken };
|
|
1189
|
+
}
|
|
1190
|
+
storage.setItem(SESSION, JSON.stringify({ did: SESSION_CONFIG.did }));
|
|
1191
|
+
return { did: "", token: this._sessionToken };
|
|
1089
1192
|
}
|
|
1090
1193
|
/**
|
|
1091
|
-
* Obtains the configuration about the address and the service
|
|
1092
|
-
*
|
|
1194
|
+
* Obtains the configuration about the address and the service where the
|
|
1195
|
+
* user is connected. As with `getSession()`, `token` is never persisted
|
|
1196
|
+
* to localStorage - it's overlaid here from the in-memory field.
|
|
1093
1197
|
*/
|
|
1094
1198
|
getExternalService() {
|
|
1095
1199
|
const storage = getStorage();
|
|
1096
|
-
if (!storage) return { ...EXTERNAL_SERVICE_CONFIG };
|
|
1200
|
+
if (!storage) return { ...EXTERNAL_SERVICE_CONFIG, token: this._externalToken };
|
|
1097
1201
|
const currentConfig = storage.getItem(EXTERNAL_SERVICE);
|
|
1098
|
-
if (currentConfig)
|
|
1099
|
-
|
|
1202
|
+
if (currentConfig) {
|
|
1203
|
+
const parsed = JSON.parse(currentConfig);
|
|
1204
|
+
return { ...parsed, token: this._externalToken };
|
|
1205
|
+
}
|
|
1100
1206
|
storage.setItem(EXTERNAL_SERVICE, JSON.stringify(EXTERNAL_SERVICE_CONFIG));
|
|
1101
|
-
return
|
|
1102
|
-
storage.getItem(EXTERNAL_SERVICE)
|
|
1103
|
-
);
|
|
1207
|
+
return { ...EXTERNAL_SERVICE_CONFIG, token: this._externalToken };
|
|
1104
1208
|
}
|
|
1105
1209
|
/**
|
|
1106
|
-
* Auxiliary method to update the SESSION configuration using websocket
|
|
1210
|
+
* Auxiliary method to update the SESSION configuration using websocket
|
|
1211
|
+
* events.
|
|
1212
|
+
*
|
|
1213
|
+
* IMPORTANT: the wallet JWT (`token`) is never persisted to localStorage
|
|
1214
|
+
* anymore (see the SECURITY NOTE at the top of this file). It's kept in
|
|
1215
|
+
* the `_sessionToken`/`_externalToken` in-memory fields instead, and -
|
|
1216
|
+
* when it's a fresh/changed `blockauth` token - bridged into an httpOnly
|
|
1217
|
+
* `blockauth-session` cookie via the `/auth/session` backend endpoint.
|
|
1218
|
+
* Only the (non-sensitive) `did` is persisted, for UI/reload purposes.
|
|
1219
|
+
*
|
|
1220
|
+
* Returns a Promise once the (best-effort) session-bridge call has
|
|
1221
|
+
* settled; callers that don't need to wait for it can keep calling this
|
|
1222
|
+
* without awaiting, same as before - every state mutation below happens
|
|
1223
|
+
* synchronously, before the `await`.
|
|
1107
1224
|
*/
|
|
1108
|
-
setSession({
|
|
1225
|
+
async setSession({
|
|
1109
1226
|
installed = void 0,
|
|
1110
1227
|
isUser = void 0,
|
|
1111
1228
|
isUserActive = void 0,
|
|
@@ -1113,7 +1230,8 @@ var BrowserBase = class {
|
|
|
1113
1230
|
did = void 0,
|
|
1114
1231
|
token = void 0,
|
|
1115
1232
|
externalService = void 0,
|
|
1116
|
-
serviceName = "blockauth"
|
|
1233
|
+
serviceName = "blockauth",
|
|
1234
|
+
apiUrl = void 0
|
|
1117
1235
|
} = {}) {
|
|
1118
1236
|
const storage = getStorage();
|
|
1119
1237
|
if (!storage) return;
|
|
@@ -1130,16 +1248,20 @@ var BrowserBase = class {
|
|
|
1130
1248
|
isLocked: isLockedValue
|
|
1131
1249
|
};
|
|
1132
1250
|
storage.setItem(UI, JSON.stringify(newCfgUI));
|
|
1251
|
+
let tokenToBridge;
|
|
1133
1252
|
if (serviceName === "blockauth") {
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1253
|
+
const didValue = did !== void 0 ? did : cfgSession.did || "";
|
|
1254
|
+
const tokenValue = token !== void 0 ? token : cfgSession.token || "";
|
|
1255
|
+
storage.setItem(SESSION, JSON.stringify({ did: didValue }));
|
|
1256
|
+
if (tokenValue && tokenValue !== this._sessionToken) {
|
|
1257
|
+
tokenToBridge = tokenValue;
|
|
1258
|
+
}
|
|
1259
|
+
this._sessionToken = tokenValue;
|
|
1139
1260
|
}
|
|
1140
1261
|
if (externalService) {
|
|
1141
1262
|
const cfgExternalService = this.getExternalService();
|
|
1142
1263
|
const isBlockauth = serviceName === "blockauth";
|
|
1264
|
+
const prevExternalToken = this._externalToken;
|
|
1143
1265
|
const connected = externalService.connected;
|
|
1144
1266
|
const service = externalService.service;
|
|
1145
1267
|
const didEs = externalService.did;
|
|
@@ -1161,20 +1283,29 @@ var BrowserBase = class {
|
|
|
1161
1283
|
account: !isBlockauth ? accountValue : "",
|
|
1162
1284
|
networkId: !isBlockauth ? networkIdValue : ""
|
|
1163
1285
|
};
|
|
1164
|
-
storage.setItem(
|
|
1286
|
+
storage.setItem(
|
|
1287
|
+
EXTERNAL_SERVICE,
|
|
1288
|
+
JSON.stringify({ ...newCfgExternalService, token: "" })
|
|
1289
|
+
);
|
|
1290
|
+
this._externalToken = newCfgExternalService.token;
|
|
1165
1291
|
if (!isBlockauth) {
|
|
1166
1292
|
storage.setItem(
|
|
1167
1293
|
SESSION,
|
|
1168
|
-
JSON.stringify({
|
|
1169
|
-
did: newCfgExternalService.did,
|
|
1170
|
-
token: newCfgExternalService.token
|
|
1171
|
-
})
|
|
1294
|
+
JSON.stringify({ did: newCfgExternalService.did, token: "" })
|
|
1172
1295
|
);
|
|
1296
|
+
this._sessionToken = newCfgExternalService.token;
|
|
1297
|
+
if (newCfgExternalService.token && newCfgExternalService.token !== prevExternalToken) {
|
|
1298
|
+
tokenToBridge = newCfgExternalService.token;
|
|
1299
|
+
}
|
|
1173
1300
|
}
|
|
1174
1301
|
}
|
|
1302
|
+
if (tokenToBridge) {
|
|
1303
|
+
await bridgeSessionCookie(tokenToBridge, apiUrl);
|
|
1304
|
+
}
|
|
1175
1305
|
}
|
|
1176
1306
|
externalServiceDisconnect() {
|
|
1177
1307
|
const storage = getStorage();
|
|
1308
|
+
this._externalToken = "";
|
|
1178
1309
|
if (!storage) return;
|
|
1179
1310
|
storage.setItem(
|
|
1180
1311
|
EXTERNAL_SERVICE,
|
|
@@ -1792,12 +1923,16 @@ function startExtensionSync() {
|
|
|
1792
1923
|
}
|
|
1793
1924
|
|
|
1794
1925
|
// src/auth/connectBlockAuth.ts
|
|
1795
|
-
function connectBlockAuth() {
|
|
1926
|
+
function connectBlockAuth(apiUrl) {
|
|
1796
1927
|
setServiceName("blockauth");
|
|
1797
|
-
|
|
1928
|
+
if (typeof localStorage !== "undefined") {
|
|
1929
|
+
localStorage.removeItem("blockauth-logged-out");
|
|
1930
|
+
}
|
|
1931
|
+
void browserBase.setSession({
|
|
1798
1932
|
...browserBase.getSession(),
|
|
1799
1933
|
externalService: { service: "blockauth", connected: true },
|
|
1800
|
-
serviceName: "blockauth"
|
|
1934
|
+
serviceName: "blockauth",
|
|
1935
|
+
apiUrl
|
|
1801
1936
|
});
|
|
1802
1937
|
setIsServiceConnected(true);
|
|
1803
1938
|
setWaitingForSuccessLogInSince(0);
|
|
@@ -1806,7 +1941,7 @@ function connectBlockAuth() {
|
|
|
1806
1941
|
|
|
1807
1942
|
// src/auth/logout.ts
|
|
1808
1943
|
async function performLogout(args) {
|
|
1809
|
-
const { wsc, token, apiKey, sessionId } = args;
|
|
1944
|
+
const { wsc, token, apiKey, sessionId, apiUrl } = args;
|
|
1810
1945
|
await new Promise((resolve) => {
|
|
1811
1946
|
let done = false;
|
|
1812
1947
|
const finish = () => {
|
|
@@ -1822,6 +1957,7 @@ async function performLogout(args) {
|
|
|
1822
1957
|
if (typeof localStorage !== "undefined") {
|
|
1823
1958
|
localStorage.setItem("blockauth-logged-out", "true");
|
|
1824
1959
|
}
|
|
1960
|
+
await clearSessionCookie(apiUrl);
|
|
1825
1961
|
resetWs();
|
|
1826
1962
|
resetUi();
|
|
1827
1963
|
resetWallet();
|
|
@@ -2057,7 +2193,8 @@ function createBlockAuthClient(config3) {
|
|
|
2057
2193
|
const provider = new BlockAuthProvider(
|
|
2058
2194
|
config3.apiKey,
|
|
2059
2195
|
config3.apiSecret,
|
|
2060
|
-
config3.wsUrl ?? "wss://wss.block-auth.io"
|
|
2196
|
+
config3.wsUrl ?? "wss://wss.block-auth.io",
|
|
2197
|
+
{ apiUrl: config3.apiUrl }
|
|
2061
2198
|
);
|
|
2062
2199
|
const evm = createEvmWallet({
|
|
2063
2200
|
walletConnectProjectId: config3.walletConnectProjectId,
|
|
@@ -2122,7 +2259,7 @@ function createBlockAuthClient(config3) {
|
|
|
2122
2259
|
web3: { signup: web3Signup },
|
|
2123
2260
|
// BlockAuth extension connect (sets blockauth as the active service);
|
|
2124
2261
|
// the txn-signing flow is driven by the caller via requestSignin.
|
|
2125
|
-
connectBlockAuth: () => connectBlockAuth(),
|
|
2262
|
+
connectBlockAuth: () => connectBlockAuth(config3.apiUrl),
|
|
2126
2263
|
// oauth
|
|
2127
2264
|
oauth: {
|
|
2128
2265
|
...oauth_exports,
|
|
@@ -2191,7 +2328,8 @@ function createBlockAuthClient(config3) {
|
|
|
2191
2328
|
wsc: provider.wsc,
|
|
2192
2329
|
token: userToken(),
|
|
2193
2330
|
apiKey: config3.apiKey,
|
|
2194
|
-
sessionId: browserBase.getDeviceSessionId()
|
|
2331
|
+
sessionId: browserBase.getDeviceSessionId(),
|
|
2332
|
+
apiUrl: config3.apiUrl
|
|
2195
2333
|
}),
|
|
2196
2334
|
// modals (stack — supports overlaying signin on top of signup)
|
|
2197
2335
|
openModal,
|
|
@@ -2200,6 +2338,9 @@ function createBlockAuthClient(config3) {
|
|
|
2200
2338
|
// opciones del connect inicial del WS (las consume createAuthRuntime)
|
|
2201
2339
|
wsConnectTimeout: config3.wsConnectTimeout ?? 300,
|
|
2202
2340
|
wsConnectRetries: config3.wsConnectRetries ?? 3,
|
|
2341
|
+
// Backend base url for the session/logout/ws-ticket bridge (consumed by
|
|
2342
|
+
// createAuthRuntime and by browserBase.setSession callers here above).
|
|
2343
|
+
apiUrl: config3.apiUrl,
|
|
2203
2344
|
// acceso crudo al provider si hace falta
|
|
2204
2345
|
provider
|
|
2205
2346
|
};
|
|
@@ -2307,6 +2448,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2307
2448
|
if (typeof localStorage !== "undefined") {
|
|
2308
2449
|
localStorage.setItem("blockauth-logged-out", "true");
|
|
2309
2450
|
}
|
|
2451
|
+
await clearSessionCookie(client.apiUrl);
|
|
2310
2452
|
const serviceName = browserBase.getExternalService().service;
|
|
2311
2453
|
setIsServiceConnected(false);
|
|
2312
2454
|
setWaitingForSuccessLogInSince(0);
|
|
@@ -2331,6 +2473,18 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2331
2473
|
console.error("[sdk] applyLocalLogout failed (storage event):", err);
|
|
2332
2474
|
});
|
|
2333
2475
|
};
|
|
2476
|
+
const onExtensionSessionBridged = (event) => {
|
|
2477
|
+
const did = event.detail?.did;
|
|
2478
|
+
if (did) {
|
|
2479
|
+
void browserBase.setSession({
|
|
2480
|
+
did,
|
|
2481
|
+
serviceName: "blockauth",
|
|
2482
|
+
apiUrl: client.apiUrl
|
|
2483
|
+
});
|
|
2484
|
+
setDid(did);
|
|
2485
|
+
}
|
|
2486
|
+
void wsc().refreshAuth();
|
|
2487
|
+
};
|
|
2334
2488
|
const deletion = createDeletionService({ provider });
|
|
2335
2489
|
const handleUserDeleted = (forAddress = null) => {
|
|
2336
2490
|
const handled = deletion.handleUserDeleted(forAddress);
|
|
@@ -2351,10 +2505,11 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2351
2505
|
if (service === "blockauth" || prevDid && prevDid.toLowerCase() !== String(did).toLowerCase()) {
|
|
2352
2506
|
browserBase.clearBrowserState({ keepExtensionInstalled: keepInstalled });
|
|
2353
2507
|
}
|
|
2354
|
-
browserBase.setSession({
|
|
2508
|
+
void browserBase.setSession({
|
|
2355
2509
|
...result,
|
|
2356
|
-
serviceName: service
|
|
2357
|
-
|
|
2510
|
+
serviceName: service,
|
|
2511
|
+
apiUrl: client.apiUrl
|
|
2512
|
+
}).then(() => wsc().refreshAuth());
|
|
2358
2513
|
setDid(did);
|
|
2359
2514
|
setToken(token);
|
|
2360
2515
|
setServiceIcon(imgUrlByService(service));
|
|
@@ -2421,10 +2576,6 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2421
2576
|
const signinUnsigned = async () => {
|
|
2422
2577
|
setIsSignedFirstCheck(true);
|
|
2423
2578
|
if (!hookState.isSigned) {
|
|
2424
|
-
const ext = browserBase.getExternalService();
|
|
2425
|
-
if (ext.connected && typeof localStorage !== "undefined") {
|
|
2426
|
-
localStorage.setItem("blockauth-logged-out", "true");
|
|
2427
|
-
}
|
|
2428
2579
|
await _onError();
|
|
2429
2580
|
}
|
|
2430
2581
|
};
|
|
@@ -2631,7 +2782,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2631
2782
|
if (!activeDid || activeDid !== changedAddress) return;
|
|
2632
2783
|
await fetchUserProfile(provider, activeDid);
|
|
2633
2784
|
};
|
|
2634
|
-
const onSdkRestore = (data) => {
|
|
2785
|
+
const onSdkRestore = async (data) => {
|
|
2635
2786
|
if (data.success) {
|
|
2636
2787
|
deletion.resetHandlingState();
|
|
2637
2788
|
setIsOnDeletion(false);
|
|
@@ -2642,15 +2793,17 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2642
2793
|
browserBase.clearBrowserState({
|
|
2643
2794
|
keepExtensionInstalled: keepInstalled
|
|
2644
2795
|
});
|
|
2645
|
-
browserBase.setSession({
|
|
2796
|
+
await browserBase.setSession({
|
|
2646
2797
|
did: session.did,
|
|
2647
2798
|
token: session.token,
|
|
2648
|
-
serviceName: "blockauth"
|
|
2799
|
+
serviceName: "blockauth",
|
|
2800
|
+
apiUrl: client.apiUrl
|
|
2649
2801
|
});
|
|
2650
2802
|
if (session.serviceName && session.serviceName !== "blockauth") {
|
|
2651
|
-
browserBase.setSession({
|
|
2803
|
+
await browserBase.setSession({
|
|
2652
2804
|
...session,
|
|
2653
|
-
serviceName: session.serviceName
|
|
2805
|
+
serviceName: session.serviceName,
|
|
2806
|
+
apiUrl: client.apiUrl
|
|
2654
2807
|
});
|
|
2655
2808
|
}
|
|
2656
2809
|
}
|
|
@@ -2677,7 +2830,8 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2677
2830
|
setDid(_did);
|
|
2678
2831
|
setToken(_token);
|
|
2679
2832
|
setApiKey(client.apiKey ?? $ws.get().apiKey);
|
|
2680
|
-
|
|
2833
|
+
const isLoggedOut = typeof localStorage !== "undefined" && localStorage.getItem("blockauth-logged-out") === "true";
|
|
2834
|
+
setIsServiceConnected(isLoggedOut ? false : externalService.connected);
|
|
2681
2835
|
setServiceName(externalService.service);
|
|
2682
2836
|
setServiceIcon(imgUrlByService(externalService.service));
|
|
2683
2837
|
await provider.connect(
|
|
@@ -2721,6 +2875,12 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2721
2875
|
if (typeof window !== "undefined") {
|
|
2722
2876
|
window.addEventListener("storage", onStorageLogout);
|
|
2723
2877
|
}
|
|
2878
|
+
if (typeof document !== "undefined") {
|
|
2879
|
+
document.addEventListener(
|
|
2880
|
+
"blockauth:session-bridged",
|
|
2881
|
+
onExtensionSessionBridged
|
|
2882
|
+
);
|
|
2883
|
+
}
|
|
2724
2884
|
const { domain, signinCallbackUrl, config: config3 } = await provider.app();
|
|
2725
2885
|
setUiConfig({ domain, signinCallbackUrl, config: config3 });
|
|
2726
2886
|
setReady(true);
|
|
@@ -2763,6 +2923,12 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2763
2923
|
if (typeof window !== "undefined") {
|
|
2764
2924
|
window.removeEventListener("storage", onStorageLogout);
|
|
2765
2925
|
}
|
|
2926
|
+
if (typeof document !== "undefined") {
|
|
2927
|
+
document.removeEventListener(
|
|
2928
|
+
"blockauth:session-bridged",
|
|
2929
|
+
onExtensionSessionBridged
|
|
2930
|
+
);
|
|
2931
|
+
}
|
|
2766
2932
|
provider.disconnect();
|
|
2767
2933
|
};
|
|
2768
2934
|
const logout = async () => {
|