mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Login if the user is already registered
This commit is contained in:
parent
e6083c310f
commit
a4af3bc423
@ -53,6 +53,28 @@ export async function registerUser(username: string, displayname: string, passwo
|
||||
await new Promise(resolve => setTimeout(resolve, REGISTRATION_RETRY_BASE_DELAY_MS * i * i));
|
||||
continue;
|
||||
}
|
||||
|
||||
// If already created, try logging in.
|
||||
if (ex?.body?.errcode === 'M_USER_IN_USE') {
|
||||
const loginUrl = `${config.homeserverUrl}/_matrix/client/r0/login`
|
||||
const params = {
|
||||
uri: loginUrl,
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({
|
||||
"type": "m.login.password",
|
||||
"identifier": {
|
||||
"type": "m.id.user",
|
||||
"user": username
|
||||
},
|
||||
"password": password
|
||||
}),
|
||||
timeout: 60000
|
||||
}
|
||||
return await new Promise((resolve, reject) => {
|
||||
getRequestFn()(params, (error, result) => error ? reject(error) : resolve(result));
|
||||
});
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
@ -60,21 +60,7 @@ async function configureMjolnir() {
|
||||
);
|
||||
return access_token;
|
||||
} catch (e) {
|
||||
if (e.isAxiosError) {
|
||||
console.log('Received error while registering', e.response.data || e.response);
|
||||
if (e.response.data && e.response.data.errcode === 'M_USER_IN_USE') {
|
||||
console.log('mjolnir already registered, skipping');
|
||||
// Needed for encryption tests
|
||||
return (await new MatrixClient(config.homeserverUrl, "").doRequest('POST', '/_matrix/client/r0/login', undefined, {
|
||||
"type": "m.login.password",
|
||||
"identifier": {
|
||||
"type": "m.id.user",
|
||||
"user": "mjolnir"
|
||||
},
|
||||
"password": "mjolnir"
|
||||
})).access_token;
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user