Session: Simplify storage (#5775)
This commit is contained in:
parent
aef7c39809
commit
6673937e24
@ -103,7 +103,6 @@ export interface ApiWebSession {
|
||||
export interface ApiSessionData {
|
||||
mainDcId: number;
|
||||
keys: Record<number, string | number[]>;
|
||||
hashes: Record<number, string | number[]>;
|
||||
isTest?: true;
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ export default class CallbackSession extends MemorySession {
|
||||
const {
|
||||
mainDcId,
|
||||
keys,
|
||||
hashes,
|
||||
isTest,
|
||||
} = this._sessionData;
|
||||
const {
|
||||
@ -45,16 +44,8 @@ export default class CallbackSession extends MemorySession {
|
||||
? Buffer.from(keys[dcId] as string, 'hex')
|
||||
: Buffer.from(keys[dcId]);
|
||||
|
||||
if (hashes[dcId]) {
|
||||
const hash = typeof hashes[dcId] === 'string'
|
||||
? Buffer.from(hashes[dcId] as string, 'hex')
|
||||
: Buffer.from(hashes[dcId]);
|
||||
|
||||
this._authKeys[dcId] = new AuthKey(key, hash);
|
||||
} else {
|
||||
this._authKeys[dcId] = new AuthKey();
|
||||
await this._authKeys[dcId].setKey(key);
|
||||
}
|
||||
this._authKeys[dcId] = new AuthKey();
|
||||
await this._authKeys[dcId].setKey(key);
|
||||
}));
|
||||
}
|
||||
|
||||
@ -85,7 +76,6 @@ export default class CallbackSession extends MemorySession {
|
||||
const sessionData: SessionData = {
|
||||
mainDcId: this._dcId,
|
||||
keys: {},
|
||||
hashes: {},
|
||||
isTest: this._isTestServer || undefined,
|
||||
};
|
||||
|
||||
@ -97,7 +87,6 @@ export default class CallbackSession extends MemorySession {
|
||||
if (!authKey?._key) return;
|
||||
|
||||
sessionData.keys[dcId] = authKey._key.toString('hex');
|
||||
sessionData.hashes[dcId] = authKey._hash!.toString('hex');
|
||||
});
|
||||
|
||||
return sessionData;
|
||||
|
||||
@ -20,6 +20,5 @@ export type EntityLike =
|
||||
export interface SessionData {
|
||||
mainDcId: number;
|
||||
keys: Record<number, string | number[]>;
|
||||
hashes: Record<number, string | number[]>;
|
||||
isTest?: true;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ export function hasStoredSession() {
|
||||
|
||||
export function storeSession(sessionData: ApiSessionData, currentUserId?: string) {
|
||||
const {
|
||||
mainDcId, keys, hashes, isTest,
|
||||
mainDcId, keys, isTest,
|
||||
} = sessionData;
|
||||
|
||||
localStorage.setItem(SESSION_USER_KEY, JSON.stringify({
|
||||
@ -40,12 +40,6 @@ export function storeSession(sessionData: ApiSessionData, currentUserId?: string
|
||||
Object.keys(keys).map(Number).forEach((dcId) => {
|
||||
localStorage.setItem(`dc${dcId}_auth_key`, JSON.stringify(keys[dcId]));
|
||||
});
|
||||
|
||||
if (hashes) {
|
||||
Object.keys(hashes).map(Number).forEach((dcId) => {
|
||||
localStorage.setItem(`dc${dcId}_hash`, JSON.stringify(hashes[dcId]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function clearStoredSession() {
|
||||
@ -72,7 +66,6 @@ export function loadStoredSession(): ApiSessionData | undefined {
|
||||
const mainDcId = Number(userAuth.dcID);
|
||||
const isTest = userAuth.test;
|
||||
const keys: Record<number, string> = {};
|
||||
const hashes: Record<number, string> = {};
|
||||
|
||||
DC_IDS.forEach((dcId) => {
|
||||
try {
|
||||
@ -80,11 +73,6 @@ export function loadStoredSession(): ApiSessionData | undefined {
|
||||
if (key) {
|
||||
keys[dcId] = JSON.parse(key);
|
||||
}
|
||||
|
||||
const hash = localStorage.getItem(`dc${dcId}_hash`);
|
||||
if (hash) {
|
||||
hashes[dcId] = JSON.parse(hash);
|
||||
}
|
||||
} catch (err) {
|
||||
if (DEBUG) {
|
||||
// eslint-disable-next-line no-console
|
||||
@ -99,7 +87,6 @@ export function loadStoredSession(): ApiSessionData | undefined {
|
||||
return {
|
||||
mainDcId,
|
||||
keys,
|
||||
hashes,
|
||||
isTest,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user