Revert "feat: remove callbackURL"

This reverts commit 5b99d74c7b.
This commit is contained in:
DIYgod 2024-12-03 18:45:40 +08:00
parent 5b99d74c7b
commit 2a013773de
No known key found for this signature in database
5 changed files with 13 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import { PanelSplitter } from "@follow/components/ui/divider/index.js"
import { Kbd } from "@follow/components/ui/kbd/Kbd.js"
import { RootPortal } from "@follow/components/ui/portal/index.jsx"
import type { FeedViewType } from "@follow/constants"
import { IN_ELECTRON } from "@follow/shared/constants"
import { preventDefault } from "@follow/utils/dom"
import { cn } from "@follow/utils/utils"
import { Slot } from "@radix-ui/react-slot"
@ -144,7 +145,7 @@ export function MainDestopLayout() {
canClose={false}
clickOutsideToDismiss={false}
>
<LoginModalContent canClose={false} />
<LoginModalContent canClose={false} runtime={IN_ELECTRON ? "app" : "browser"} />
</DeclarativeModal>
</RootPortal>
)}

View File

@ -2,6 +2,7 @@ import { Logo } from "@follow/components/icons/logo.js"
import { ActionButton } from "@follow/components/ui/button/index.js"
import { RootPortal } from "@follow/components/ui/portal/index.js"
import { views } from "@follow/constants"
import { IN_ELECTRON } from "@follow/shared/constants"
import { cn } from "@follow/utils/utils"
import useEmblaCarousel from "embla-carousel-react"
import type { FC } from "react"
@ -83,7 +84,7 @@ export function FeedColumnMobile({ asWidget }: { asWidget?: boolean }) {
canClose={false}
clickOutsideToDismiss={false}
>
<LoginModalContent canClose={false} />
<LoginModalContent canClose={false} runtime={IN_ELECTRON ? "app" : "browser"} />
</DeclarativeModal>
</RootPortal>
)}

View File

@ -2,6 +2,7 @@ import { FollowIcon } from "@follow/components/icons/follow.jsx"
import { MotionButtonBase } from "@follow/components/ui/button/index.js"
import { LoadingCircle } from "@follow/components/ui/loading/index.jsx"
import { authProvidersConfig } from "@follow/constants"
import type { LoginRuntime } from "@follow/shared/auth"
import { loginHandler } from "@follow/shared/auth"
import { stopPropagation } from "@follow/utils/dom"
import clsx from "clsx"
@ -14,12 +15,13 @@ import { useCurrentModal } from "~/components/ui/modal/stacked/hooks"
import { useAuthProviders } from "~/queries/users"
interface LoginModalContentProps {
runtime?: LoginRuntime
canClose?: boolean
}
export const LoginModalContent = (props: LoginModalContentProps) => {
const modal = useCurrentModal()
const { canClose = true } = props
const { canClose = true, runtime } = props
const { t } = useTranslation()
const { data: authProviders } = useAuthProviders()
@ -72,7 +74,7 @@ export const LoginModalContent = (props: LoginModalContentProps) => {
)}
disabled={disabled}
onClick={() => {
loginHandler(key)
loginHandler(key, runtime)
setLoadingLockSet(key)
window.analytics?.capture("login", {
type: key,

View File

@ -25,7 +25,7 @@ export const LoginButton: FC<LoginProps> = (props) => {
CustomModalComponent: PlainModal,
title: "Login",
id: "login",
content: () => <LoginModalContent />,
content: () => <LoginModalContent runtime={window.electron ? "app" : "browser"} />,
clickOutsideToDismiss: true,
})
}

View File

@ -23,12 +23,15 @@ const authClient = createAuthClient({
export const { signIn, signOut, getSession, getProviders, createSession } = authClient
export const loginHandler = (provider: string) => {
export const LOGIN_CALLBACK_URL = `${WEB_URL}/login`
export type LoginRuntime = "browser" | "app"
export const loginHandler = (provider: string, runtime: LoginRuntime = "app") => {
if (IN_ELECTRON) {
window.open(`${WEB_URL}/login?provider=${provider}`)
} else {
signIn.social({
provider: provider as "google" | "github" | "apple",
callbackURL: runtime === "app" ? LOGIN_CALLBACK_URL : WEB_URL,
})
}
}