mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	サインアップ・ログアウト周りの怪しい挙動を修正 (#7750)
* fix #7749 * fix * fix logout behavior when there is no push subscription * fix logout behavior when there is no push subscription 2 * clean up service worker registration * fix lint * remove submodules
This commit is contained in:
		
							parent
							
								
									8407702b38
								
							
						
					
					
						commit
						48f46333f8
					
				
					 4 changed files with 32 additions and 18 deletions
				
			
		| 
						 | 
					@ -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 { reactive } from 'vue';
 | 
				
			||||||
import { apiUrl } from '@client/config';
 | 
					import { apiUrl } from '@client/config';
 | 
				
			||||||
import { waiting } from '@client/os';
 | 
					import { waiting } from '@client/os';
 | 
				
			||||||
| 
						 | 
					@ -26,21 +26,33 @@ export async function signout() {
 | 
				
			||||||
	//#region Remove account
 | 
						//#region Remove account
 | 
				
			||||||
	const accounts = await getAccounts();
 | 
						const accounts = await getAccounts();
 | 
				
			||||||
	accounts.splice(accounts.findIndex(x => x.id === $i.id), 1);
 | 
						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
 | 
						//#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Remove push notification registration
 | 
						//#region Remove service worker registration
 | 
				
			||||||
	try {
 | 
						try {
 | 
				
			||||||
		const registration = await navigator.serviceWorker.ready;
 | 
							if (navigator.serviceWorker.controller) {
 | 
				
			||||||
		const push = await registration.pushManager.getSubscription();
 | 
								const registration = await navigator.serviceWorker.ready;
 | 
				
			||||||
		if (!push) return;
 | 
								const push = await registration.pushManager.getSubscription();
 | 
				
			||||||
		await fetch(`${apiUrl}/sw/unregister`, {
 | 
								if (push) {
 | 
				
			||||||
			method: 'POST',
 | 
									await fetch(`${apiUrl}/sw/unregister`, {
 | 
				
			||||||
			body: JSON.stringify({
 | 
										method: 'POST',
 | 
				
			||||||
				i: $i.token,
 | 
										body: JSON.stringify({
 | 
				
			||||||
				endpoint: push.endpoint,
 | 
											i: $i.token,
 | 
				
			||||||
			}),
 | 
											endpoint: push.endpoint,
 | 
				
			||||||
		});
 | 
										}),
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (accounts.length === 0) {
 | 
				
			||||||
 | 
								await navigator.serviceWorker.getRegistrations()
 | 
				
			||||||
 | 
									.then(registrations => {
 | 
				
			||||||
 | 
										return Promise.all(registrations.map(registration => registration.unregister()));
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} catch (e) {}
 | 
						} catch (e) {}
 | 
				
			||||||
	//#endregion
 | 
						//#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +111,9 @@ export default defineComponent({
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		onLogin(res) {
 | 
							onLogin(res) {
 | 
				
			||||||
			if (this.autoSet) {
 | 
								if (this.autoSet) {
 | 
				
			||||||
				login(res.i);
 | 
									return login(res.i);
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -144,7 +146,7 @@ export default defineComponent({
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			}).then(res => {
 | 
								}).then(res => {
 | 
				
			||||||
				this.$emit('login', res);
 | 
									this.$emit('login', res);
 | 
				
			||||||
				this.onLogin(res);
 | 
									return this.onLogin(res);
 | 
				
			||||||
			}).catch(err => {
 | 
								}).catch(err => {
 | 
				
			||||||
				if (err === null) return;
 | 
									if (err === null) return;
 | 
				
			||||||
				os.dialog({
 | 
									os.dialog({
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -178,14 +178,14 @@ export default defineComponent({
 | 
				
			||||||
				'hcaptcha-response': this.hCaptchaResponse,
 | 
									'hcaptcha-response': this.hCaptchaResponse,
 | 
				
			||||||
				'g-recaptcha-response': this.reCaptchaResponse,
 | 
									'g-recaptcha-response': this.reCaptchaResponse,
 | 
				
			||||||
			}).then(() => {
 | 
								}).then(() => {
 | 
				
			||||||
				os.api('signin', {
 | 
									return os.api('signin', {
 | 
				
			||||||
					username: this.username,
 | 
										username: this.username,
 | 
				
			||||||
					password: this.password
 | 
										password: this.password
 | 
				
			||||||
				}).then(res => {
 | 
									}).then(res => {
 | 
				
			||||||
					this.$emit('signup', res);
 | 
										this.$emit('signup', res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if (this.autoSet) {
 | 
										if (this.autoSet) {
 | 
				
			||||||
						login(res.i);
 | 
											return login(res.i);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
			}).catch(() => {
 | 
								}).catch(() => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ export default defineComponent({
 | 
				
			||||||
				username: this.username,
 | 
									username: this.username,
 | 
				
			||||||
				password: this.password,
 | 
									password: this.password,
 | 
				
			||||||
			}).then(res => {
 | 
								}).then(res => {
 | 
				
			||||||
				login(res.i);
 | 
									return login(res.token);
 | 
				
			||||||
			}).catch(() => {
 | 
								}).catch(() => {
 | 
				
			||||||
				this.submitting = false;
 | 
									this.submitting = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue