Support current WebK auth

This commit is contained in:
Eduard Kuzmenko 2021-06-08 15:24:30 +03:00
parent 54ace14d23
commit e314c421b6
4 changed files with 52 additions and 2 deletions

View File

@ -710,6 +710,8 @@ export class AppDialogsManager {
private onListLengthChange = () => {
//return;
if(this.filterId < 2) return;
const emptyFolder = this.chatList.parentElement.querySelector('.empty-folder');
if(this.scroll.loadedAll.bottom && !this.chatList.childElementCount) {

View File

@ -199,9 +199,10 @@ export class AppStateManager extends EventListenerBase<{
const promises: Promise<any>[] = ALL_KEYS.map(key => stateStorage.get(key))
.concat(sessionStorage.get('user_auth'))
.concat(stateStorage.get('user_auth' as any)) // support old webk format
.concat(storagesPromises);
Promise.all(promises).then((arr) => {
Promise.all(promises).then(async(arr) => {
/* const self = this;
const skipHandleKeys = new Set(['isProxy', 'filters', 'drafts']);
const getHandler = (path?: string) => {
@ -275,6 +276,27 @@ export class AppStateManager extends EventListenerBase<{
}
}
let shiftedWebKAuth = arr.shift() as UserAuth | number;
if(!auth && shiftedWebKAuth) { // support old webk auth
auth = shiftedWebKAuth;
const keys: string[] = ['dc', 'server_time_offset', 'xt_instance'];
for(let i = 1; i <= 5; ++i) {
keys.push(`dc${i}_server_salt`);
keys.push(`dc${i}_auth_key`);
}
const values = await Promise.all(keys.map(key => stateStorage.get(key as any)));
keys.push('user_auth');
values.push(typeof(auth) === 'number' ? {dcID: values[0] || App.baseDcId, id: auth} : auth);
let obj: any = {};
keys.forEach((key, idx) => {
obj[key] = values[idx];
});
await sessionStorage.set(obj);
}
if(auth) {
// ! Warning ! DON'T delete this
state.authState = {_: 'authStateSignedIn'};

View File

@ -160,7 +160,7 @@ export class ApiManager {
// WebPushApiManager.forceUnsubscribe(); // WARNING
const storageResult = await Promise.all(storageKeys.map(key => sessionStorage.get(key as any)));
const logoutPromises = [];
const logoutPromises: Promise<any>[] = [];
for(let i = 0; i < storageResult.length; i++) {
if(storageResult[i]) {
logoutPromises.push(this.invokeApi('auth.logOut', {}, {dcId: i + 1, ignoreErrors: true}));

View File

@ -0,0 +1,26 @@
(async function asd() {
const auth = 1;
const keys = ['dc', 'server_time_offset', 'xt_instance'];
for(let i = 1; i <= 5; ++i) {
keys.push(`dc${i}_server_salt`);
keys.push(`dc${i}_auth_key`);
}
const values = await Promise.all(keys.map(key => appStorage.get(key)));
keys.push('user_auth');
values.push(typeof(auth) === 'number' ? {dcID: values[0] || 2, id: auth} : auth);
let obj = {};
keys.forEach((key, idx) => {
obj[key] = values[idx];
});
window.exported = obj;
console.log(obj);
})();
copy(JSON.stringify(window.exported));
var obj = JSON.parse();
appStorage.set(obj);