From de69cab2399037eacc1ecfd0151508a5cd14a81e Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 20:31:09 +0900 Subject: [PATCH 1/6] fix #7749 --- lib/CubismWebFramework | 1 + misskey-assets | 1 + src/client/components/signin.vue | 6 ++++-- src/client/components/signup.vue | 4 ++-- src/client/pages/welcome.setup.vue | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) create mode 160000 lib/CubismWebFramework create mode 160000 misskey-assets diff --git a/lib/CubismWebFramework b/lib/CubismWebFramework new file mode 160000 index 0000000000..85b4313dbe --- /dev/null +++ b/lib/CubismWebFramework @@ -0,0 +1 @@ +Subproject commit 85b4313dbea6b9765aec2f865977bb7fe8750bab diff --git a/misskey-assets b/misskey-assets new file mode 160000 index 0000000000..0179793ec8 --- /dev/null +++ b/misskey-assets @@ -0,0 +1 @@ +Subproject commit 0179793ec891856d6f37a3be16ba4c22f67a81b5 diff --git a/src/client/components/signin.vue b/src/client/components/signin.vue index 0094038fb6..c051288d0a 100755 --- a/src/client/components/signin.vue +++ b/src/client/components/signin.vue @@ -111,7 +111,9 @@ export default defineComponent({ onLogin(res) { if (this.autoSet) { - login(res.i); + return login(res.i); + } else { + return; } }, @@ -144,7 +146,7 @@ export default defineComponent({ }); }).then(res => { this.$emit('login', res); - this.onLogin(res); + return this.onLogin(res); }).catch(err => { if (err === null) return; os.dialog({ diff --git a/src/client/components/signup.vue b/src/client/components/signup.vue index d584b97209..b53eb6f64a 100644 --- a/src/client/components/signup.vue +++ b/src/client/components/signup.vue @@ -178,14 +178,14 @@ export default defineComponent({ 'hcaptcha-response': this.hCaptchaResponse, 'g-recaptcha-response': this.reCaptchaResponse, }).then(() => { - os.api('signin', { + return os.api('signin', { username: this.username, password: this.password }).then(res => { this.$emit('signup', res); if (this.autoSet) { - login(res.i); + return login(res.token); } }); }).catch(() => { diff --git a/src/client/pages/welcome.setup.vue b/src/client/pages/welcome.setup.vue index de844ece1c..d0091bef67 100644 --- a/src/client/pages/welcome.setup.vue +++ b/src/client/pages/welcome.setup.vue @@ -53,7 +53,7 @@ export default defineComponent({ username: this.username, password: this.password, }).then(res => { - login(res.i); + return login(res.token); }).catch(() => { this.submitting = false; From 2f3a942583f1cc1f469f3fe9266ae781308003f6 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 20:47:39 +0900 Subject: [PATCH 2/6] fix --- src/client/account.ts | 6 ++++-- src/client/components/signup.vue | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index ee1d845493..69755819fe 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -1,4 +1,4 @@ -import { get, set } from '@client/scripts/idb-proxy'; +import { del, get, set } from '@client/scripts/idb-proxy'; import { reactive } from 'vue'; import { apiUrl } from '@client/config'; import { waiting } from '@client/os'; @@ -26,7 +26,9 @@ export async function signout() { //#region Remove account const accounts = await getAccounts(); accounts.splice(accounts.findIndex(x => x.id === $i.id), 1); - set('accounts', accounts); + + if (accounts.length > 0) await set('accounts', accounts); + else await del('accounts'); //#endregion //#region Remove push notification registration diff --git a/src/client/components/signup.vue b/src/client/components/signup.vue index b53eb6f64a..d332274111 100644 --- a/src/client/components/signup.vue +++ b/src/client/components/signup.vue @@ -185,7 +185,7 @@ export default defineComponent({ this.$emit('signup', res); if (this.autoSet) { - return login(res.token); + return login(res.i); } }); }).catch(() => { From f6d8867df2b4db81cb8cca33aa1e54e4c72cae31 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 20:56:01 +0900 Subject: [PATCH 3/6] fix logout behavior when there is no push subscription --- src/client/account.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index 69755819fe..97085aca47 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -35,14 +35,15 @@ export async function signout() { try { const registration = await navigator.serviceWorker.ready; const push = await registration.pushManager.getSubscription(); - if (!push) return; - await fetch(`${apiUrl}/sw/unregister`, { - method: 'POST', - body: JSON.stringify({ - i: $i.token, - endpoint: push.endpoint, - }), - }); + if (push) { + await fetch(`${apiUrl}/sw/unregister`, { + method: 'POST', + body: JSON.stringify({ + i: $i.token, + endpoint: push.endpoint, + }), + }); + } } catch (e) {} //#endregion From b2e21db0b3a71ff9d277109db3d6b3221731b39f Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 21:07:39 +0900 Subject: [PATCH 4/6] fix logout behavior when there is no push subscription 2 --- src/client/account.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/client/account.ts b/src/client/account.ts index 97085aca47..efe9f19527 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -33,16 +33,18 @@ export async function signout() { //#region Remove push notification registration try { - const registration = await navigator.serviceWorker.ready; - const push = await registration.pushManager.getSubscription(); - if (push) { - await fetch(`${apiUrl}/sw/unregister`, { - method: 'POST', - body: JSON.stringify({ - i: $i.token, - endpoint: push.endpoint, - }), - }); + if (navigator.serviceWorker.controller) { + const registration = await navigator.serviceWorker.ready; + const push = await registration.pushManager.getSubscription(); + if (push) { + await fetch(`${apiUrl}/sw/unregister`, { + method: 'POST', + body: JSON.stringify({ + i: $i.token, + endpoint: push.endpoint, + }), + }); + } } } catch (e) {} //#endregion From 106a0226321533fd131a9bc9193bd3128b417828 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 21:42:13 +0900 Subject: [PATCH 5/6] clean up service worker registration --- src/client/account.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/account.ts b/src/client/account.ts index efe9f19527..50eb7ecba3 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -31,7 +31,7 @@ export async function signout() { else await del('accounts'); //#endregion - //#region Remove push notification registration + //#region Remove service worker registration try { if (navigator.serviceWorker.controller) { const registration = await navigator.serviceWorker.ready; @@ -46,6 +46,13 @@ export async function signout() { }); } } + + if (accounts.length === 0) { + await navigator.serviceWorker.getRegistrations() + .then(registrations => { + return Promise.all(registrations.map(registration => registration.unregister())); + }) + } } catch (e) {} //#endregion From 5f2236e6fa22f0531efc4bbafcc13ae57138dfa0 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 31 Aug 2021 21:42:26 +0900 Subject: [PATCH 6/6] fix lint --- src/client/account.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/account.ts b/src/client/account.ts index 50eb7ecba3..e469bae5a2 100644 --- a/src/client/account.ts +++ b/src/client/account.ts @@ -51,7 +51,7 @@ export async function signout() { await navigator.serviceWorker.getRegistrations() .then(registrations => { return Promise.all(registrations.map(registration => registration.unregister())); - }) + }); } } catch (e) {} //#endregion