Auth: Fixes for non-default DC users

This commit is contained in:
Alexander Zinchuk 2021-06-14 16:01:12 +03:00
parent a14d380647
commit 570bed3010
2 changed files with 13 additions and 4 deletions

View File

@ -89,7 +89,7 @@ class CallbackSession extends MemorySession {
.keys(this._authKeys)
.forEach((dcId) => {
const authKey = this._authKeys[dcId];
if (!authKey._key) return;
if (!authKey || !authKey._key) return;
sessionData.keys[dcId] = authKey._key.toString('hex');
sessionData.hashes[dcId] = authKey._hash.toString('hex');

View File

@ -32,13 +32,22 @@ export function clearStoredSession() {
}
export function loadStoredSession(): ApiSessionData | undefined {
const legacySessionJson = localStorage.getItem(SESSION_USER_KEY);
if (!legacySessionJson) return undefined;
const userAuthJson = localStorage.getItem(SESSION_USER_KEY);
if (!userAuthJson) return undefined;
const { dcID: mainDcId } = JSON.parse(legacySessionJson);
let mainDcId: number | undefined;
const keys: Record<number, string> = {};
const hashes: Record<number, string> = {};
try {
const userAuth = JSON.parse(userAuthJson);
mainDcId = Number(userAuth.dcID);
} catch (err) {
// Do nothing.
}
if (!mainDcId) return undefined;
DC_IDS.forEach((dcId) => {
try {
const key = localStorage.getItem(`dc${dcId}_auth_key`);