Skip to content

Commit a9569cc

Browse files
committed
fix(external): continue in browser should reload page
Signed-off-by: Innei <tukon479@gmail.com>
1 parent 58d0e9c commit a9569cc

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

apps/server/client/pages/(login)/login.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Logo } from "@follow/components/icons/logo.jsx"
55
import { Button } from "@follow/components/ui/button/index.js"
66
import { DEEPLINK_SCHEME } from "@follow/shared/constants"
77
import { SessionProvider, signIn, signOut, useSession } from "@hono/auth-js/react"
8-
import { useEffect, useState } from "react"
8+
import { useCallback, useEffect, useRef, useState } from "react"
99
import { useTranslation } from "react-i18next"
10-
import { useLocation, useNavigate } from "react-router"
10+
import { useLocation } from "react-router"
1111

1212
export function Component() {
1313
return (
@@ -19,7 +19,7 @@ export function Component() {
1919

2020
function Login() {
2121
const { status } = useSession()
22-
const navigate = useNavigate()
22+
2323
const [redirecting, setRedirecting] = useState(false)
2424

2525
const location = useLocation()
@@ -39,13 +39,26 @@ function Login() {
3939
}
4040
}, [status])
4141

42-
const getCallbackUrl = async () => {
42+
const getCallbackUrl = useCallback(async () => {
4343
const { data } = await apiClient["auth-app"]["new-session"].$post({})
4444
return {
4545
url: `${DEEPLINK_SCHEME}auth?token=${data.sessionToken}&userId=${data.userId}`,
4646
userId: data.userId,
4747
}
48-
}
48+
}, [])
49+
50+
const handleOpenApp = useCallback(async () => {
51+
const { url } = await getCallbackUrl()
52+
window.open(url, "_top")
53+
}, [getCallbackUrl])
54+
55+
const onceRef = useRef(false)
56+
useEffect(() => {
57+
if (isAuthenticated && !onceRef.current) {
58+
handleOpenApp()
59+
}
60+
onceRef.current = true
61+
}, [handleOpenApp, isAuthenticated])
4962

5063
return (
5164
<div className="flex h-screen w-full flex-col items-center justify-center gap-10">
@@ -80,19 +93,13 @@ function Login() {
8093
variant="text"
8194
className="h-14 text-base"
8295
onClick={() => {
83-
navigate("/")
96+
window.location.href = "/"
8497
}}
8598
>
8699
{t("redirect.continueInBrowser")}
87100
</Button>
88101

89-
<Button
90-
className="h-14 !rounded-full px-5 text-lg"
91-
onClick={async () => {
92-
const { url } = await getCallbackUrl()
93-
window.open(url, "_top")
94-
}}
95-
>
102+
<Button className="h-14 !rounded-full px-5 text-lg" onClick={handleOpenApp}>
96103
{t("redirect.openApp", { app_name: APP_NAME })}
97104
</Button>
98105
</div>

0 commit comments

Comments
 (0)