From 4f7ae81d5f20d392ec2fb9df6542446a1659ad48 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 29 Oct 2021 00:55:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AEID=E3=82=92=E3=82=AF=E3=82=A8=E3=83=AA=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=88=97=E3=81=A7=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B?= =?UTF-8?q?=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/init.ts | 21 +++++++++++++++++++++ src/client/scripts/login-id.ts | 11 +++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/client/scripts/login-id.ts diff --git a/src/client/init.ts b/src/client/init.ts index 123d4020e1..e64804e54b 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -37,6 +37,8 @@ import { isMobile } from '@client/scripts/is-mobile'; import { initializeSw } from '@client/scripts/initialize-sw'; import { reloadChannel } from '@client/scripts/unison-reload'; import { reactionPicker } from '@client/scripts/reaction-picker'; +import { deleteLoginId } from '@client/scripts/login-id'; +import { getAccountFromId } from '@client/scripts/get-account-from-id'; console.info(`Misskey v${version}`); @@ -116,6 +118,25 @@ const html = document.documentElement; html.setAttribute('lang', lang); //#endregion +//#region loginId +const params = new URLSearchParams(location.search); +const loginId = params.get('loginId'); + +if (loginId) { + const target = deleteLoginId(location.href); + + if (!$i || $i.id !== loginId) { + const account = await getAccountFromId(loginId); + if (account) { + login(account.token, target); + } + } + + history.replaceState({ misskey: 'loginId' }, '', target); +} + +//#endregion + //#region Fetch user if ($i && $i.token) { if (_DEV_) { diff --git a/src/client/scripts/login-id.ts b/src/client/scripts/login-id.ts new file mode 100644 index 0000000000..50e5229558 --- /dev/null +++ b/src/client/scripts/login-id.ts @@ -0,0 +1,11 @@ +export function appendLoginId(url: string, loginId: string) { + const u = new URL(url, origin); + u.searchParams.append('loginId', loginId); + return u.toString(); +} + +export function deleteLoginId(url: string) { + const u = new URL(url); + u.searchParams.delete('loginId'); + return u.toString(); +}