From 0fa7a8221cbd0ea019cd58603f5ffcc8763286a1 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 21 Oct 2025 21:45:24 +0800 Subject: [PATCH] feat: add last used login method tracking and localization updates --- .../src/modules/auth/LoginModalContent.tsx | 2 +- apps/ssr/client/lib/auth.ts | 1 + apps/ssr/client/modules/login/index.tsx | 27 +++++++++++++++++-- locales/app/en.json | 1 + locales/app/zh-CN.json | 1 + locales/external/en.json | 1 + locales/external/zh-CN.json | 1 + 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/auth/LoginModalContent.tsx b/apps/desktop/layer/renderer/src/modules/auth/LoginModalContent.tsx index f16fb08f0..34a4061a5 100644 --- a/apps/desktop/layer/renderer/src/modules/auth/LoginModalContent.tsx +++ b/apps/desktop/layer/renderer/src/modules/auth/LoginModalContent.tsx @@ -144,7 +144,7 @@ export const LoginModalContent = (props: LoginModalContentProps) => { {t("login.continueWith", { provider: provider.name })} {lastMethod === key && (
- Last used + {t("login.lastUsed")}
)} diff --git a/apps/ssr/client/lib/auth.ts b/apps/ssr/client/lib/auth.ts index 3f74cafda..e9bb192b7 100644 --- a/apps/ssr/client/lib/auth.ts +++ b/apps/ssr/client/lib/auth.ts @@ -21,6 +21,7 @@ export const { changePassword, forgetPassword, getAccountInfo, + getLastUsedLoginMethod, getProviders, getSession, linkSocial, diff --git a/apps/ssr/client/modules/login/index.tsx b/apps/ssr/client/modules/login/index.tsx index 475251d93..7cbf34a91 100644 --- a/apps/ssr/client/modules/login/index.tsx +++ b/apps/ssr/client/modules/login/index.tsx @@ -1,5 +1,11 @@ import { UserAvatar } from "@client/components/ui/user-avatar" -import { loginHandler, oneTimeToken, signOut, twoFactor } from "@client/lib/auth" +import { + getLastUsedLoginMethod, + loginHandler, + oneTimeToken, + signOut, + twoFactor, +} from "@client/lib/auth" import { openInFollowApp } from "@client/lib/helper" import { queryClient } from "@client/lib/query-client" import { useSession } from "@client/query/auth" @@ -66,6 +72,17 @@ export function Login() { const [callbackUrl, setCallbackUrl] = useState() const callbackUrlWithScheme = callbackUrl ? `${DEEPLINK_SCHEME}${callbackUrl}` : undefined + const [lastMethod, setLastMethod] = useState(null) + useEffect(() => { + let lastMethodValue = getLastUsedLoginMethod() + if (lastMethodValue === "email") { + lastMethodValue = "credential" + } + if (lastMethodValue) { + setLastMethod(lastMethodValue) + } + }, [lastMethod]) + const handleOpenApp = useCallback(async () => { const callbackUrl = await getCallbackUrl() if (!callbackUrl) return @@ -168,7 +185,7 @@ export function Login() { loginHandler(key, "app") } }} - className="center relative w-full gap-2 rounded-xl border p-2.5 pl-5 font-semibold duration-200 hover:bg-material-medium" + className="center relative w-full gap-2 rounded-xl border py-3 pl-5 font-semibold duration-200 hover:bg-material-medium" > {t("login.continueWith", { provider: provider.name })} + {lastMethod === key && ( +
+ {t("login.lastUsed")} +
+ )} ))} @@ -219,6 +241,7 @@ export function Login() { openFailed, callbackUrl, isDark, + lastMethod, ]) const Content = useMemo(() => { switch (true) { diff --git a/locales/app/en.json b/locales/app/en.json index fa8de28cd..562a97568 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -246,6 +246,7 @@ "login.enter_token": "Enter authorization token to continue", "login.forget_password.note": "Forgot your password?", "login.have_account": "Already have an account? Sign in", + "login.lastUsed": "Last used", "login.no_account": "Don't have an account? Sign up", "login.or": "OR", "login.password": "Password", diff --git a/locales/app/zh-CN.json b/locales/app/zh-CN.json index 9ce948407..be9c649ac 100644 --- a/locales/app/zh-CN.json +++ b/locales/app/zh-CN.json @@ -244,6 +244,7 @@ "login.enter_token": "输入授权令牌以继续", "login.forget_password.note": "忘记了密码?", "login.have_account": "已有账户?登录", + "login.lastUsed": "上次使用", "login.no_account": "没有账户?注册", "login.or": "或", "login.password": "密码", diff --git a/locales/external/en.json b/locales/external/en.json index 63d056717..b4e55e171 100644 --- a/locales/external/en.json +++ b/locales/external/en.json @@ -50,6 +50,7 @@ "login.forget_password.note": "Forgot your password?", "login.forget_password.success": "Email has been sent successfully", "login.have_account": "Already have an account? Sign in", + "login.lastUsed": "Last used", "login.logInTo": "Sign in to", "login.logInWithEmail": "Sign in with email", "login.new_password.label": "New Password", diff --git a/locales/external/zh-CN.json b/locales/external/zh-CN.json index 08b915586..19c75a097 100644 --- a/locales/external/zh-CN.json +++ b/locales/external/zh-CN.json @@ -50,6 +50,7 @@ "login.forget_password.note": "忘记了密码?", "login.forget_password.success": "邮件已成功发送。", "login.have_account": "已有账户?登录", + "login.lastUsed": "上次使用", "login.logInTo": "登录 ", "login.logInWithEmail": "使用邮件地址登录", "login.new_password.label": "新密码",