2021-05-27 20:17:05 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { WebAPIConnectType, WebAPIType } from '../textsecure/WebAPI';
|
2021-06-15 00:09:37 +00:00
|
|
|
import { StorageInterface } from '../types/Storage.d';
|
2021-05-27 20:17:05 +00:00
|
|
|
|
|
|
|
export function connectToServerWithStoredCredentials(
|
|
|
|
WebAPI: WebAPIConnectType,
|
2021-06-15 00:09:37 +00:00
|
|
|
storage: Pick<StorageInterface, 'get'>
|
2021-05-27 20:17:05 +00:00
|
|
|
): WebAPIType {
|
|
|
|
const username = storage.get('uuid_id') || storage.get('number_id');
|
|
|
|
if (typeof username !== 'string') {
|
|
|
|
throw new Error(
|
|
|
|
'Username in storage was not a string. Cannot connect to WebAPI'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const password = storage.get('password');
|
|
|
|
if (typeof password !== 'string') {
|
|
|
|
throw new Error(
|
|
|
|
'Password in storage was not a string. Cannot connect to WebAPI'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return WebAPI.connect({ username, password });
|
|
|
|
}
|