Skip to content

Commit ecc60a5

Browse files
committed
RFR: upgrade notion to v4.2 and use new auth methods
1 parent 8ddce3c commit ecc60a5

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
@@ -65,7 +65,7 @@
6565
},
6666
"publisher": "neurosity",
6767
"dependencies": {
68-
"@neurosity/notion": "^3.10.2",
68+
"@neurosity/notion": "^4.2.0",
6969
"@sindresorhus/do-not-disturb": "^1.1.0",
7070
"@types/regression": "^2.0.0",
7171
"@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
@@ -87,17 +87,11 @@ export function loginFromSavedState(saved_state: any) {
8787
});
8888

8989
// This try/catch might be able to detect invalid saved state, as
90-
// firebase will probably throw an error
90+
// it will probably throw an error
9191
try {
92-
const user = new notion.api.firebase.app.firebase_.User(
93-
saved_state,
94-
saved_state.stsTokenManager,
95-
saved_state
96-
);
97-
98-
notion.api.firebase.app
92+
notion
9993
.auth()
100-
.updateCurrentUser(user)
94+
.updateCurrentUser(saved_state)
10195
.then(() => {
10296
logged_in = true;
10397
if (login_callback) login_callback();
@@ -159,23 +153,29 @@ function getOrPrompt(section: string, prompt: string, placeHolder?: string) {
159153
* @param sections - 2d array, where each item is an array of params passed to getOrPrompt()
160154
*/
161155
function ensureConfigValues(sections: string[][]) {
162-
return new Promise<(string | undefined)[]>(async (resolve, reject) => {
163-
let values: (string | undefined)[] = [];
164-
165-
for (let i = 0; i < sections.length; i++) {
166-
let params = sections[i];
167-
168-
try {
169-
let value = await getOrPrompt(params[0], params[1], params[2]);
170-
values.push(value);
171-
} catch (error) {
172-
reject(error);
173-
return;
156+
return new Promise<(string | undefined)[]>(
157+
async (resolve, reject) => {
158+
let values: (string | undefined)[] = [];
159+
160+
for (let i = 0; i < sections.length; i++) {
161+
let params = sections[i];
162+
163+
try {
164+
let value = await getOrPrompt(
165+
params[0],
166+
params[1],
167+
params[2]
168+
);
169+
values.push(value);
170+
} catch (error) {
171+
reject(error);
172+
return;
173+
}
174174
}
175-
}
176175

177-
resolve(values);
178-
});
176+
resolve(values);
177+
}
178+
);
179179
}
180180

181181
function handleLogin(method: vscode.QuickPickItem | undefined) {
@@ -186,7 +186,6 @@ function handleLogin(method: vscode.QuickPickItem | undefined) {
186186

187187
// Login with email
188188
if (method.label == email_label) {
189-
// See: https://firebase.google.com/docs/auth/web/email-link-auth
190189
ensureConfigValues([
191190
["email", email_prompt, email_placeholder],
192191
["deviceId", deviceid_prompt, deviceid_placeholder]
@@ -225,7 +224,7 @@ function sendLoginEmail() {
225224
deviceId
226225
});
227226

228-
notion.api.firebase.app
227+
notion
229228
.auth()
230229
.sendSignInLinkToEmail(email, {
231230
url: "https://console.neurosity.co/vscode",
@@ -256,16 +255,16 @@ function loginWithEmailCred() {
256255
deviceId
257256
});
258257

259-
// This is very hacky, should clean up firebase API usage
258+
// This is very hacky, should clean up API usage
260259
try {
261-
let credential = notion.api.firebase.app.firebase_.auth.EmailAuthProvider.credentialWithLink(
260+
let credential = Notion.credentialWithLink(
262261
email,
263262
"https://console.neurosity.co/account-manager?apiKey=none&mode=signIn&oobCode=" +
264263
code +
265264
"&continueUrl=https://console.neurosity.co/vscode&lang=en"
266265
);
267266

268-
notion.api.firebase.app
267+
notion
269268
.auth()
270269
.signInWithCredential(credential)
271270
.then(

0 commit comments

Comments
 (0)