feat: Added ability to log out all sign in in accounts

This commit is contained in:
NoriDev 2022-09-15 16:39:18 +09:00
parent 6a5365b2bf
commit 32da3d95d2
6 changed files with 55 additions and 2 deletions

View file

@ -30,6 +30,7 @@
- 클라이언트: 타임라인 전환시 맨 위로 이동하도록 변경
- 클라이언트: 위젯 위치 변경 방식 개선
- 클라이언트: 네비게이션 바 편집 환경 개선
- 클라이언트: 로그인된 모든 계정을 로그아웃하는 기능 추가
### Bugfixes
- 클라이언트: 채팅방에서 메시지를 입력하고 있을 때 움직이지 않는 온점(.)이 표시되는 문제

View file

@ -31,6 +31,8 @@ noAccountDescription: "This user has not written their bio yet."
login: "Sign In"
loggingIn: "Signing In"
logout: "Sign Out"
logoutAll: "Sign Out all accounts"
logoutAllConfirm: "Are you sure to delete all accounts added to this device?"
signup: "Sign Up"
uploading: "Uploading..."
save: "Save"

View file

@ -31,6 +31,8 @@ noAccountDescription: "自己紹介はありません"
login: "ログイン"
loggingIn: "ログイン中"
logout: "ログアウト"
logoutAll: "全アカウントをログアウト"
logoutAllConfirm: "このデバイスに追加した全てのアカウントをログアウトしますか?"
signup: "新規登録"
uploading: "アップロード中"
save: "保存"

View file

@ -32,7 +32,7 @@ login: "로그인"
loggingIn: "로그인하고 있어요!"
logout: "로그아웃"
logoutAll: "모든 계정 로그아웃"
logoutAllConfirm: "이 기기에 추가한 모든 계정을 로그아웃 하시겠어요?"
logoutAllConfirm: "이 기기에 추가한 계정을 전부 로그아웃 할까요?"
signup: "회원 가입"
uploading: "업로드하고 있어요!"
save: "저장"

View file

@ -58,6 +58,41 @@ export async function signout() {
else unisonReload('/');
}
export async function signoutAll() {
waiting();
localStorage.removeItem('account');
localStorage.removeItem('accounts');
await del('accounts');
//#region Remove service worker registration
try {
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,
}),
});
}
}
await navigator.serviceWorker.getRegistrations()
.then(registrations => {
return Promise.all(registrations.map(registration => registration.unregister()));
});
} catch (err) {}
//#endregion
document.cookie = 'igi=; path=/';
unisonReload('/');
}
export async function getAccounts(): Promise<{ id: Account['id'], token: Account['token'] }[]> {
return (await get('accounts')) || [];
}

View file

@ -27,7 +27,7 @@ import { i18n } from '@/i18n';
import MkInfo from '@/components/MkInfo.vue';
import MkSuperMenu from '@/components/MkSuperMenu.vue';
import { scroll } from '@/scripts/scroll';
import { signout , $i } from '@/account';
import { signout, signoutAll, $i } from '@/account';
import { unisonReload } from '@/scripts/unison-reload';
import { instance } from '@/instance';
import { useRouter } from '@/router';
@ -197,6 +197,19 @@ const menuDef = computed(() => [{
signout();
},
danger: true,
}, {
type: 'button',
icon: 'fas fa-sign-in-alt fa-flip-horizontal',
text: i18n.ts.logoutAll,
action: async () => {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.ts.logoutAllConfirm,
});
if (canceled) return;
signoutAll();
},
danger: true,
}],
}]);