Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jun 5, 2024
2 parents 2abf537 + 1e21d76 commit 5a46bb1
Showing 1 changed file with 43 additions and 45 deletions.
88 changes: 43 additions & 45 deletions src/renderer/src/pages/(external)/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ import { APP_NAME } from "@renderer/lib/constants"
import { useEffect, useState } from "react"
import { useNavigate } from "react-router-dom"

const LOGIN_CALLBACK_URL = `${import.meta.env.VITE_WEB_URL}/redirect?app=follow`
const loginHandler = (provider: string) => {
if (window.electron) {
window.open(
`${import.meta.env.VITE_WEB_URL}/login?provider=${provider}`,
)
} else {
signIn(provider, {
callbackUrl: LOGIN_CALLBACK_URL,
})
}
}
export function Component() {
const { status } = useSession()
const navigate = useNavigate()
const [redirecting, setRedirecting] = useState(false)

const callbackUrl = `${import.meta.env.VITE_WEB_URL}/redirect?app=follow`

const urlParams = new URLSearchParams(window.location.search)
const provider = urlParams.get("provider")
useEffect(() => {
if (!window.electron && provider) {
signIn(provider, {
callbackUrl,
callbackUrl: LOGIN_CALLBACK_URL,
})
setRedirecting(true)
}
Expand All @@ -33,50 +43,38 @@ export function Component() {
<h1 className="text-3xl font-bold">
Log in to
{" "}

{APP_NAME}
</h1>
{redirecting ?
(
<div>Redirecting</div>
) :
(
<div className="flex flex-col gap-3">
<Button
className="text-lg"
size="xl"
onClick={() => {
if (window.electron) {
window.open(
`${import.meta.env.VITE_WEB_URL}/login?provider=github`,
)
} else {
signIn("github", {
callbackUrl,
})
}
}}
>
<i className="i-mingcute-github-fill mr-2 text-xl" />
{" "}
Continue with
GitHub
</Button>
<Button
className="bg-blue-500 text-lg hover:bg-blue-500/90"
size="xl"
onClick={() =>
signIn("google", {
callbackUrl,
})}
>
<i className="i-mingcute-google-fill mr-2 text-xl" />
{" "}
Continue with
Google
</Button>
</div>
)}
{redirecting ? (
<div>Redirecting</div>
) : (
<div className="flex flex-col gap-3">
<Button
className="bg-black text-lg text-white"
size="xl"
onClick={() => {
loginHandler("github")
}}
>
<i className="i-mingcute-github-fill mr-2 text-xl" />
{" "}
Continue with
GitHub
</Button>
<Button
className="bg-blue-500 text-lg text-white hover:bg-blue-500/90"
size="xl"
onClick={() => {
loginHandler("google")
}}
>
<i className="i-mingcute-google-fill mr-2 text-xl" />
{" "}
Continue with
Google
</Button>
</div>
)}
</div>
)
}

0 comments on commit 5a46bb1

Please sign in to comment.