Skip to content

Commit 0fcdbc2

Browse files
committed
RFR: upgrade notion to v4.2 and use new auth methods
1 parent f8ad0f6 commit 0fcdbc2

File tree

4 files changed

+40
-41
lines changed

4 files changed

+40
-41
lines changed

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"publisher": "neurosity",
5757
"dependencies": {
58-
"@neurosity/notion": "^3.10.2",
58+
"@neurosity/notion": "^4.2.0",
5959
"@sindresorhus/do-not-disturb": "^1.1.0",
6060
"@types/regression": "^2.0.0",
6161
"@types/universal-analytics": "^0.4.3",

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function activate(context: vscode.ExtensionContext) {
3737

3838
loginCallback(() => {
3939
// Save current login state
40-
let loginState = notion.api.firebase.app.auth().currentUser;
40+
let loginState = notion.auth().currentUser;
4141
context.globalState.update("notion.loginState", loginState);
4242

4343
loginStatusBarItem.hide();

src/login.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,11 @@ export function loginFromSavedState(saved_state: any) {
8989
});
9090

9191
// This try/catch might be able to detect invalid saved state, as
92-
// firebase will probably throw an error
92+
// it will probably throw an error
9393
try {
94-
const user = new notion.api.firebase.app.firebase_.User(
95-
saved_state,
96-
saved_state.stsTokenManager,
97-
saved_state
98-
);
99-
100-
notion.api.firebase.app
94+
notion
10195
.auth()
102-
.updateCurrentUser(user)
96+
.updateCurrentUser(saved_state)
10397
.then(() => {
10498
logged_in = true;
10599
if (login_callback) login_callback();
@@ -165,23 +159,29 @@ function getOrPrompt(
165159
* @param sections - 2d array, where each item is an array of params passed to getOrPrompt()
166160
*/
167161
function ensureConfigValues(sections: string[][]) {
168-
return new Promise<(string | undefined)[]>(async (resolve, reject) => {
169-
let values: (string | undefined)[] = [];
170-
171-
for (let i = 0; i < sections.length; i++) {
172-
let params = sections[i];
173-
174-
try {
175-
let value = await getOrPrompt(params[0], params[1], params[2]);
176-
values.push(value);
177-
} catch (error) {
178-
reject(error);
179-
return;
162+
return new Promise<(string | undefined)[]>(
163+
async (resolve, reject) => {
164+
let values: (string | undefined)[] = [];
165+
166+
for (let i = 0; i < sections.length; i++) {
167+
let params = sections[i];
168+
169+
try {
170+
let value = await getOrPrompt(
171+
params[0],
172+
params[1],
173+
params[2]
174+
);
175+
values.push(value);
176+
} catch (error) {
177+
reject(error);
178+
return;
179+
}
180180
}
181-
}
182181

183-
resolve(values);
184-
});
182+
resolve(values);
183+
}
184+
);
185185
}
186186

187187
function handleLogin(method: vscode.QuickPickItem | undefined) {
@@ -192,7 +192,6 @@ function handleLogin(method: vscode.QuickPickItem | undefined) {
192192

193193
// Login with email
194194
if (method.label == email_label) {
195-
// See: https://firebase.google.com/docs/auth/web/email-link-auth
196195
ensureConfigValues([
197196
["email", email_prompt, email_placeholder],
198197
["deviceId", deviceid_prompt, deviceid_placeholder]
@@ -232,7 +231,7 @@ function sendLoginEmail() {
232231
deviceId
233232
});
234233

235-
notion.api.firebase.app
234+
notion
236235
.auth()
237236
.sendSignInLinkToEmail(email, {
238237
url: "https://console.neurosity.co/vscode",
@@ -266,16 +265,16 @@ function loginWithEmailCred() {
266265
deviceId
267266
});
268267

269-
// This is very hacky, should clean up firebase API usage
268+
// This is very hacky, should clean up API usage
270269
try {
271-
let credential = notion.api.firebase.app.firebase_.auth.EmailAuthProvider.credentialWithLink(
270+
let credential = Notion.credentialWithLink(
272271
email,
273272
"https://console.neurosity.co/account-manager?apiKey=none&mode=signIn&oobCode=" +
274273
code +
275274
"&continueUrl=https://console.neurosity.co/vscode&lang=en"
276275
);
277276

278-
notion.api.firebase.app
277+
notion
279278
.auth()
280279
.signInWithCredential(credential)
281280
.then(

0 commit comments

Comments
 (0)