Defer post-login hydration to async follow-up

This commit is contained in:
thePR0M3TH3AN committed 2025-10-09 16:37:23 -04:00
1 parent f61563d2e2
commit 0a3057d081
3 files changed
+111 -10

No files matched your search

+51 -3
View File
@@ -365,18 +365,66 @@ export default class AuthService {
this.emitProfileList("login");
}
const postLogin = await this.applyPostLoginState();
const activeLoginPubkey = getPubkey();
const normalizedLoginPubkey =
this.normalizeHexPubkey(activeLoginPubkey) || activeLoginPubkey || null;
const detail = {
pubkey: getPubkey(),
pubkey: activeLoginPubkey,
npub: getCurrentUserNpub(),
previousPubkey: previousPubkey || null,
identityChanged,
savedProfiles: this.cloneSavedProfiles(),
activeProfilePubkey: getActiveProfilePubkey(),
postLogin,
postLogin: {
pubkey: normalizedLoginPubkey,
blocksLoaded: false,
relaysLoaded: false,
profile: null,
},
postLoginPromise: null,
postLoginError: null,
};
const postLoginPromise = Promise.resolve()
.then(() => this.applyPostLoginState())
.then((postLogin) => {
detail.postLogin = postLogin;
detail.postLoginError = null;
try {
this.emitProfileList("post-login");
} catch (error) {
this.log("[AuthService] Failed to emit profile list after login", error);
}
this.emit("auth:post-login", {
...detail,
postLogin,
postLoginError: null,
savedProfiles: this.cloneSavedProfiles(),
activeProfilePubkey: getActiveProfilePubkey(),
});
return postLogin;
})
.catch((error) => {
this.log("[AuthService] applyPostLoginState failed", error);
detail.postLoginError = error;
this.emit("auth:post-login", {
...detail,
postLogin: detail.postLogin,
postLoginError: error,
savedProfiles: this.cloneSavedProfiles(),
activeProfilePubkey: getActiveProfilePubkey(),
});
return null;
});
detail.postLoginPromise = postLoginPromise;
try {
Object.defineProperty(detail, "__handled", {
configurable: true,