refactor: remove external and proxy server pages
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
import { Outlet } from "react-router"
|
||||
|
||||
import { EnvironmentIndicator } from "~/modules/app/EnvironmentIndicator"
|
||||
import { UserProvider } from "~/providers/user-provider"
|
||||
|
||||
export function Component() {
|
||||
return (
|
||||
<>
|
||||
<UserProvider />
|
||||
<Outlet />
|
||||
|
||||
{!import.meta.env.PROD && <EnvironmentIndicator />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { Button } from "@follow/components/ui/button/index.js"
|
||||
import { DEEPLINK_SCHEME } from "@follow/shared/constants"
|
||||
import { SessionProvider, signIn, useSession } from "@hono/auth-js/react"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useLocation, useNavigate } from "react-router"
|
||||
|
||||
import { useSignOut } from "~/hooks/biz/useSignOut"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { LOGIN_CALLBACK_URL, loginHandler } from "~/lib/auth"
|
||||
import { UserAvatar } from "~/modules/user/UserAvatar"
|
||||
|
||||
export function Component() {
|
||||
return (
|
||||
<SessionProvider>
|
||||
<Login />
|
||||
</SessionProvider>
|
||||
)
|
||||
}
|
||||
function Login() {
|
||||
const { status } = useSession()
|
||||
const navigate = useNavigate()
|
||||
const [redirecting, setRedirecting] = useState(false)
|
||||
const signOut = useSignOut()
|
||||
const location = useLocation()
|
||||
const urlParams = new URLSearchParams(location.search)
|
||||
const provider = urlParams.get("provider")
|
||||
|
||||
const isAuthenticated = status === "authenticated"
|
||||
|
||||
const { t } = useTranslation("external")
|
||||
|
||||
useEffect(() => {
|
||||
if (!window.electron && provider && status === "unauthenticated") {
|
||||
signIn(provider, {
|
||||
callbackUrl: LOGIN_CALLBACK_URL,
|
||||
})
|
||||
setRedirecting(true)
|
||||
}
|
||||
}, [status])
|
||||
|
||||
const getCallbackUrl = async () => {
|
||||
const { data } = await apiClient["auth-app"]["new-session"].$post({})
|
||||
return {
|
||||
url: `${DEEPLINK_SCHEME}auth?token=${data.sessionToken}&userId=${data.userId}`,
|
||||
userId: data.userId,
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-full flex-col items-center justify-center gap-10">
|
||||
<Logo className="size-20" />
|
||||
{!isAuthenticated && (
|
||||
<h1 className="text-3xl font-bold">
|
||||
{t("login.logInTo")}
|
||||
{` ${APP_NAME}`}
|
||||
</h1>
|
||||
)}
|
||||
{redirecting ? (
|
||||
<div>{t("login.redirecting")}</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-3">
|
||||
{isAuthenticated ? (
|
||||
<div className="flex w-full flex-col items-center justify-center gap-10 px-4">
|
||||
<div className="relative flex items-center justify-center">
|
||||
<UserAvatar className="gap-4 px-10 py-4 text-2xl" />
|
||||
<div className="absolute right-0">
|
||||
<Button variant="ghost" onClick={signOut}>
|
||||
<i className="i-mingcute-exit-line text-xl" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<h2 className="text-center">
|
||||
{t("redirect.successMessage", { app_name: APP_NAME })} <br />
|
||||
<br />
|
||||
{t("redirect.instruction", { app_name: APP_NAME })}
|
||||
</h2>
|
||||
<div className="center flex flex-col gap-20 sm:flex-row">
|
||||
<Button
|
||||
variant="text"
|
||||
className="h-14 text-base"
|
||||
onClick={() => {
|
||||
navigate("/")
|
||||
}}
|
||||
>
|
||||
{t("redirect.continueInBrowser")}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
className="h-14 !rounded-full px-5 text-lg"
|
||||
onClick={async () => {
|
||||
const { url } = await getCallbackUrl()
|
||||
window.open(url, "_top")
|
||||
}}
|
||||
>
|
||||
{t("redirect.openApp", { app_name: APP_NAME })}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
className="h-[48px] w-[320px] rounded-[8px] !bg-black font-sans text-base text-white hover:!bg-black/80 focus:!border-black/80 focus:!ring-black/80"
|
||||
onClick={() => {
|
||||
loginHandler("github")
|
||||
}}
|
||||
>
|
||||
<i className="i-mgc-github-cute-fi mr-2 text-xl" /> {t("login.continueWithGitHub")}
|
||||
</Button>
|
||||
<Button
|
||||
className="h-[48px] w-[320px] rounded-[8px] bg-blue-500 font-sans text-base text-white hover:bg-blue-500/90 focus:!border-blue-500/80 focus:!ring-blue-500/80"
|
||||
onClick={() => {
|
||||
loginHandler("google")
|
||||
}}
|
||||
>
|
||||
<i className="i-mgc-google-cute-fi mr-2 text-xl" /> {t("login.continueWithGoogle")}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ function Login() {
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
className="h-[48px] w-[320px] rounded-[8px] !bg-black font-sans text-base text-white hover:!bg-black/80 focus:!border-black/80 focus:!ring-black/80"
|
||||
buttonClassName="h-[48px] w-[320px] rounded-[8px] !bg-black font-sans text-base text-white hover:!bg-black/80 focus:!border-black/80 focus:!ring-black/80"
|
||||
onClick={() => {
|
||||
loginHandler("github")
|
||||
}}
|
||||
@@ -115,7 +115,7 @@ function Login() {
|
||||
<i className="i-mgc-github-cute-fi mr-2 text-xl" /> {t("login.continueWithGitHub")}
|
||||
</Button>
|
||||
<Button
|
||||
className="h-[48px] w-[320px] rounded-[8px] bg-blue-500 font-sans text-base text-white hover:bg-blue-500/90 focus:!border-blue-500/80 focus:!ring-blue-500/80"
|
||||
buttonClassName="h-[48px] w-[320px] rounded-[8px] bg-blue-500 font-sans text-base text-white hover:bg-blue-500/90 focus:!border-blue-500/80 focus:!ring-blue-500/80"
|
||||
onClick={() => {
|
||||
loginHandler("google")
|
||||
}}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"dev:debug": "export DEBUG=true && vite --debug",
|
||||
"dev:server": "pnpm run --filter=server dev",
|
||||
"dev:web": "vite",
|
||||
"dev:web-with-server": "concurrently \"pnpm run dev:web\" \"pnpm run --filter=server dev\"",
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"generator:i18n-template": "tsx scripts/generate-i18n-locale.ts",
|
||||
@@ -76,6 +77,7 @@
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"async-es": "^3.2.6",
|
||||
"autoprefixer": "10.4.20",
|
||||
"concurrently": "9.1.0",
|
||||
"cross-env": "7.0.3",
|
||||
"cssnano": "7.0.6",
|
||||
"dnum": "^2.14.0",
|
||||
|
||||
Generated
+38
@@ -146,6 +146,9 @@ importers:
|
||||
autoprefixer:
|
||||
specifier: 10.4.20
|
||||
version: 10.4.20(postcss@8.4.49)
|
||||
concurrently:
|
||||
specifier: 9.1.0
|
||||
version: 9.1.0
|
||||
cross-env:
|
||||
specifier: 7.0.3
|
||||
version: 7.0.3
|
||||
@@ -5430,6 +5433,11 @@ packages:
|
||||
concat-map@0.0.1:
|
||||
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
|
||||
|
||||
concurrently@9.1.0:
|
||||
resolution: {integrity: sha512-VxkzwMAn4LP7WyMnJNbHN5mKV9L2IbyDjpzemKr99sXNR3GqRNMMHdm7prV1ws9wg7ETj6WUkNOigZVsptwbgg==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
confbox@0.1.8:
|
||||
resolution: {integrity: sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==}
|
||||
|
||||
@@ -9810,6 +9818,9 @@ packages:
|
||||
run-parallel@1.2.0:
|
||||
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
|
||||
|
||||
rxjs@7.8.1:
|
||||
resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==}
|
||||
|
||||
safe-array-concat@1.1.2:
|
||||
resolution: {integrity: sha512-vj6RsCsWBCf19jIeHEfkRMw8DPiBb+DMXklQ/1SGDHOMlHdPUkZXFQ2YdplS23zESTijAcurb1aSgJA3AgMu1Q==}
|
||||
engines: {node: '>=0.4'}
|
||||
@@ -9934,6 +9945,9 @@ packages:
|
||||
resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
shell-quote@1.8.1:
|
||||
resolution: {integrity: sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==}
|
||||
|
||||
shelljs@0.8.5:
|
||||
resolution: {integrity: sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==}
|
||||
engines: {node: '>=4'}
|
||||
@@ -10241,6 +10255,10 @@ packages:
|
||||
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
supports-color@8.1.1:
|
||||
resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
supports-preserve-symlinks-flag@1.0.0:
|
||||
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -16483,6 +16501,16 @@ snapshots:
|
||||
|
||||
concat-map@0.0.1: {}
|
||||
|
||||
concurrently@9.1.0:
|
||||
dependencies:
|
||||
chalk: 4.1.2
|
||||
lodash: 4.17.21
|
||||
rxjs: 7.8.1
|
||||
shell-quote: 1.8.1
|
||||
supports-color: 8.1.1
|
||||
tree-kill: 1.2.2
|
||||
yargs: 17.7.2
|
||||
|
||||
confbox@0.1.8: {}
|
||||
|
||||
config-file-ts@0.2.6:
|
||||
@@ -21622,6 +21650,10 @@ snapshots:
|
||||
dependencies:
|
||||
queue-microtask: 1.2.3
|
||||
|
||||
rxjs@7.8.1:
|
||||
dependencies:
|
||||
tslib: 2.8.1
|
||||
|
||||
safe-array-concat@1.1.2:
|
||||
dependencies:
|
||||
call-bind: 1.0.7
|
||||
@@ -21774,6 +21806,8 @@ snapshots:
|
||||
|
||||
shebang-regex@3.0.0: {}
|
||||
|
||||
shell-quote@1.8.1: {}
|
||||
|
||||
shelljs@0.8.5:
|
||||
dependencies:
|
||||
glob: 7.2.3
|
||||
@@ -22103,6 +22137,10 @@ snapshots:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
|
||||
supports-color@8.1.1:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
|
||||
supports-preserve-symlinks-flag@1.0.0: {}
|
||||
|
||||
svgo@3.3.2:
|
||||
|
||||
+44
-6
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url"
|
||||
import legacy from "@vitejs/plugin-legacy"
|
||||
import { minify as htmlMinify } from "html-minifier-terser"
|
||||
import { cyan, dim, green } from "kolorist"
|
||||
import { parseHTML } from "linkedom"
|
||||
import type { PluginOption, ViteDevServer } from "vite"
|
||||
import { defineConfig, loadEnv } from "vite"
|
||||
import { analyzer } from "vite-bundle-analyzer"
|
||||
@@ -65,17 +66,54 @@ export default ({ mode }) => {
|
||||
watch: {
|
||||
ignored: ["**/dist/**", "**/out/**", "**/public/**", ".git/**"],
|
||||
},
|
||||
...(env.VITE_DEV_PROXY
|
||||
? {
|
||||
proxy: {
|
||||
proxy: {
|
||||
"/login": {
|
||||
target: "http://localhost:2234",
|
||||
changeOrigin: true,
|
||||
selfHandleResponse: true,
|
||||
configure: (proxy, _options) => {
|
||||
proxy.on("proxyRes", (proxyRes, req, res) => {
|
||||
const body = [] as any[]
|
||||
proxyRes.on("data", (chunk: any) => body.push(chunk))
|
||||
proxyRes.on("end", () => {
|
||||
const html = parseHTML(Buffer.concat(body).toString())
|
||||
const doc = html.document
|
||||
|
||||
const $scripts = doc.querySelectorAll("script")
|
||||
$scripts.forEach((script) => {
|
||||
const src = script.getAttribute("src")
|
||||
if (src) {
|
||||
script.setAttribute("src", `http://localhost:2234${src}`)
|
||||
}
|
||||
})
|
||||
|
||||
const $links = doc.querySelectorAll("link")
|
||||
$links.forEach((link) => {
|
||||
const href = link.getAttribute("href")
|
||||
if (href) {
|
||||
link.setAttribute("href", `http://localhost:2234${href}`)
|
||||
}
|
||||
})
|
||||
|
||||
res.setHeader("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
const modifiedHtml = doc.toString()
|
||||
res.end(modifiedHtml)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
|
||||
...(env.VITE_DEV_PROXY
|
||||
? {
|
||||
[env.VITE_DEV_PROXY]: {
|
||||
target: env.VITE_DEV_PROXY_TARGET,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(new RegExp(`^${env.VITE_DEV_PROXY}`), ""),
|
||||
},
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user