core: use the new login flow in all tests

This commit is contained in:
Abdullah Atta
2023-01-06 12:55:59 +05:00
committed by Abdullah Atta
parent 65cae7888e
commit 22871d8baf
7 changed files with 182 additions and 73 deletions

View File

@@ -147,51 +147,6 @@ class UserManager {
EV.publish(EVENTS.userLoggedIn, user);
}
/**
* @deprecated Please use `authenticateEmail`, `authenticateMultiFactorCode` & `authenticatePassword` for login
*/
async login(email, password, hashedPassword = undefined) {
return this._login({ email, password, hashedPassword });
}
/**
* @deprecated Please use `authenticateEmail`, `authenticateMultiFactorCode` & `authenticatePassword` for login
*/
async mfaLogin(email, password, { code, method }) {
return this._login({ email, password, code, method });
}
/**
* @private
*/
async _login({ email, password, hashedPassword, code, method }) {
email = email && email.toLowerCase();
if (!hashedPassword && password) {
hashedPassword = await this._storage.hash(password, email);
}
await this.tokenManager.saveToken(
await http.post(`${constants.AUTH_HOST}${ENDPOINTS.token}`, {
username: email,
password: hashedPassword,
grant_type: code ? "mfa" : "password",
scope: "notesnook.sync offline_access openid IdentityServerApi",
client_id: "notesnook",
"mfa:code": code,
"mfa:method": method
})
);
const user = await this.fetchUser();
await this._storage.deriveCryptoKey(`_uk_@${user.email}`, {
password,
salt: user.salt
});
EV.publish(EVENTS.userLoggedIn, user);
}
async getSessions() {
const token = await this.tokenManager.getAccessToken();
if (!token) return;