Login on reload

To get a new access_token if the old one has expired. Should fix issue #36.
This commit is contained in:
N-Pex 2021-01-27 12:57:23 +01:00
parent 5645e32cf0
commit 933de4a2ec
5 changed files with 64 additions and 18 deletions

View file

@ -1,8 +1,31 @@
export default class User {
constructor(server, username, password, is_guest) {
this.server = server;
this.username = username;
constructor(home_server, user_id, password, is_guest) {
this.home_server = home_server;
this.user_id = user_id;
this.password = password;
this.is_guest = is_guest || false
}
normalize = function() {
if (this.user_id.startsWith('@') && this.user_id.includes(':')) {
const parts = this.user_id.split(":");
this.user_id = parts[0].substring(1);
this.home_server = "https://" + parts[1];
}
};
static homeServerUrl = function(home_server) {
if (home_server && !home_server.startsWith("https://")) {
return "https://" + home_server;
}
return home_server;
};
static localPart(user_id) {
if (user_id && user_id.startsWith('@') && user_id.includes(':')) {
const parts = user_id.split(":");
return parts[0].substring(1);
}
return user_id;
}
}