From 303c5abfb42939011dd1bd48f5516a4ec2f2ac1d Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 31 Oct 2021 16:01:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=AF=E3=83=A9=E3=82=A4=E3=82=A2?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=A7=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?id=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B=E3=82=AF?= =?UTF-8?q?=E3=82=A8=E3=83=AA(loginId=3D:userId)=20(#7929)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ログインするアカウントのIDをクエリ文字列で指定する機能 * await? * rename --- 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..654e176398 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 { getUrlWithoutLoginId } 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 = getUrlWithoutLoginId(location.href); + + if (!$i || $i.id !== loginId) { + const account = await getAccountFromId(loginId); + if (account) { + await 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..0f9c6be4a9 --- /dev/null +++ b/src/client/scripts/login-id.ts @@ -0,0 +1,11 @@ +export function getUrlWithLoginId(url: string, loginId: string) { + const u = new URL(url, origin); + u.searchParams.append('loginId', loginId); + return u.toString(); +} + +export function getUrlWithoutLoginId(url: string) { + const u = new URL(url); + u.searchParams.delete('loginId'); + return u.toString(); +}