Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add basic user types

thecodrr873cfb13b4ca
diff --git a/packages/core/api/user-manager.js b/packages/core/api/user-manager.js
index 2d836c73c..03b4d7d66 100644
--- a/packages/core/api/user-manager.js
+++ b/packages/core/api/user-manager.js
@@ -1,3 +1,4 @@
+import "../types";
import http from "../utils/http";
import constants from "../utils/constants";
import TokenManager from "./token-manager";
@@ -58,10 +59,21 @@ class UserManager {
client_id: "notesnook",
});
EV.publish(EVENTS.userSignedUp);
- return await this.login(email, password, hashedPassword);
+ return await this._login({ email, password, hashedPassword });
}
- async login(email, password, code, hashedPassword = undefined) {
+ async login(email, password) {
+ return this._login({ email, password });
+ }
+
+ async mfaLogin(email, password, { code, method }) {
+ return this._login({ email, password, code, method });
+ }
+
+ /**
+ * @private
+ */
+ async _login({ email, password, hashedPassword, code, method }) {
if (!hashedPassword) {
hashedPassword = await this._storage.hash(password, email);
}
@@ -70,10 +82,11 @@ class UserManager {
await http.post(`${constants.AUTH_HOST}${ENDPOINTS.token}`, {
username: email,
password: hashedPassword,
- code,
grant_type: "password",
scope: "notesnook.sync offline_access openid IdentityServerApi",
client_id: "notesnook",
+ "mfa:code": code,
+ "mfa:method": method,
})
);
@@ -132,6 +145,10 @@ class UserManager {
return this._storage.write("user", user);
}
+ /**
+ *
+ * @returns {Promise<User>}
+ */
getUser() {
return this._storage.read("user");
}
@@ -162,6 +179,10 @@ class UserManager {
return true;
}
+ /**
+ *
+ * @returns {Promise<User>}
+ */
async fetchUser() {
try {
let token = await this.tokenManager.getAccessToken();
diff --git a/packages/core/types.js b/packages/core/types.js
index 27e46876e..34099d302 100644
--- a/packages/core/types.js
+++ b/packages/core/types.js
@@ -9,3 +9,17 @@
/**
* @typedef {"home" | "notes" | "notebooks" | "tags" | "topics" | "trash" | "favorites"} GroupingKey
*/
+
+/**
+ * @typedef {{
+ * id: string,
+ * email: string,
+ * isEmailConfirmed: boolean,
+ * mfa: {
+ * isEnabled: boolean,
+ * primaryMethod: string,
+ * secondaryMethod: string,
+ * remainingValidCodes: number
+ * }
+ * }} User
+ */