feat: add last used login method tracking in LoginModalContent

This commit is contained in:
DIYgod
2025-10-21 20:01:10 +08:00
parent d3bf8a89db
commit 79b0dab3b4
2 changed files with 25 additions and 3 deletions
@@ -9,12 +9,12 @@ import type { LoginRuntime } from "@follow/shared/auth"
import { stopPropagation } from "@follow/utils/dom"
import { cn } from "@follow/utils/utils"
import { m } from "motion/react"
import { useState } from "react"
import { useEffect, useState } from "react"
import { Trans, useTranslation } from "react-i18next"
import { useServerConfigs } from "~/atoms/server-configs"
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
import { loginHandler } from "~/lib/auth"
import { authClient, loginHandler } from "~/lib/auth"
import { useAuthProviders } from "~/queries/users"
import { LoginWithPassword, RegisterForm } from "./Form"
@@ -67,6 +67,18 @@ export const LoginModalContent = (props: LoginModalContentProps) => {
setIsRegister(state === "register")
}
const [lastMethod, setLastMethod] = useState<string | null>(null)
useEffect(() => {
let lastMethodValue = authClient.getLastUsedLoginMethod()
if (lastMethodValue === "email") {
lastMethodValue = "credential"
}
if (lastMethodValue) {
setIsRegister(false)
setLastMethod(lastMethodValue)
}
}, [lastMethod])
const Inner = (
<>
{isEmail && (
@@ -130,6 +142,11 @@ export const LoginModalContent = (props: LoginModalContentProps) => {
src={isDark ? provider.iconDark64 || provider.icon64 : provider.icon64}
/>
<span>{t("login.continueWith", { provider: provider.name })}</span>
{lastMethod === key && (
<div className="absolute -right-2 -top-2 rounded-xl bg-accent px-2 py-0.5 text-sm text-white">
Last used
</div>
)}
</MotionButtonBase>
))}
+6 -1
View File
@@ -3,7 +3,11 @@ import { IN_ELECTRON } from "@follow/shared"
import type { AuthPlugins } from "@follow-app/client-sdk/auth"
import type { BetterAuthClientPlugin, BetterFetchOption } from "better-auth/client"
import { createAuthClient } from "better-auth/client"
import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins"
import {
inferAdditionalFields,
lastLoginMethodClient,
twoFactorClient,
} from "better-auth/client/plugins"
type AuthPlugin = AuthPlugins[number]
@@ -47,6 +51,7 @@ export const baseAuthPlugins = [
}),
twoFactorClient(),
stripeClient({ subscription: true }),
lastLoginMethodClient(),
] satisfies BetterAuthClientPlugin[]
export type AuthClient<ExtraPlugins extends BetterAuthClientPlugin[] = []> = ReturnType<