Browse Source

Improved bot login flow with optional password auth

develop
Drew Short 5 years ago
parent
commit
2100f54451
  1. 32
      bot/bot.js

32
bot/bot.js

@ -17,7 +17,6 @@ class Bot {
logger.info("Creating Matrix Client")
this.client = sdk.createClient({
baseUrl: this.config.baseUrl,
accessToken: this.config.accessToken,
userId: this.config.userId
});
@ -60,10 +59,41 @@ class Bot {
async connect() {
// logger.info("Initializing Crypto");
// await bot.client.initCrypto();
let botClient = this.client;
let botConfig = this.config;
let startServerConnection = async () => {
logger.info("Starting Matrix SDK Client");
await this.client.startClient();
}
let connectWithPassword = (err, data) => {
if (err === null) {
logger.info("Successfully authenticated with password %o", data);
startServerConnection();
} else {
logger.error("Failed to authenticate with password %o", err);
}
}
let connectWithToken = (err, data) => {
if (err === null) {
logger.info("Successfully authenticated with access token %o", data);
startServerConnection();
} else {
logger.error("Failed to authenticate with access token %o", err);
if (typeof botConfig.userPassword !== 'undefined') {
botClient.loginWithPassword(botConfig.userId, botConfig.userPassword, connectWithPassword);
} else {
logger.error("No fallback password provided!");
}
}
}
logger.info("Authenticating With Server");
botClient.loginWithToken(this.config.accessToken, connectWithToken);
}
sendStatusStartup() {
let promises = [Promise.resolve(true)]
if (this.connected) {

Loading…
Cancel
Save