Skip to content

Commit 405ee42

Browse files
committed
fix: auth in electron
1 parent d42f52d commit 405ee42

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

apps/renderer/src/modules/auth/Form.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,23 @@ import {
88
FormMessage,
99
} from "@follow/components/ui/form/index.js"
1010
import { Input } from "@follow/components/ui/input/Input.js"
11+
import type { LoginRuntime } from "@follow/shared/auth"
1112
import { loginHandler, signUp } from "@follow/shared/auth"
13+
import { env } from "@follow/shared/env"
1214
import { zodResolver } from "@hookform/resolvers/zod"
1315
import { useForm } from "react-hook-form"
1416
import { useTranslation } from "react-i18next"
15-
import { Link } from "react-router"
1617
import { toast } from "sonner"
1718
import { z } from "zod"
1819

1920
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
2021

21-
async function onSubmit(values: z.infer<typeof formSchema>) {
22-
const res = await loginHandler("credential", "browser", values)
23-
if (res?.error) {
24-
toast.error(res.error.message)
25-
return
26-
}
27-
window.location.reload()
28-
}
2922
const formSchema = z.object({
3023
email: z.string().email(),
3124
password: z.string().max(128),
3225
})
33-
export function LoginWithPassword() {
26+
27+
export function LoginWithPassword({ runtime }: { runtime?: LoginRuntime }) {
3428
const { t } = useTranslation("app")
3529
const form = useForm<z.infer<typeof formSchema>>({
3630
resolver: zodResolver(formSchema),
@@ -44,6 +38,15 @@ export function LoginWithPassword() {
4438
const { present } = useModalStack()
4539
const { dismiss } = useCurrentModal()
4640

41+
async function onSubmit(values: z.infer<typeof formSchema>) {
42+
const res = await loginHandler("credential", runtime ?? "browser", values)
43+
if (res?.error) {
44+
toast.error(res.error.message)
45+
return
46+
}
47+
window.location.reload()
48+
}
49+
4750
return (
4851
<Form {...form}>
4952
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
@@ -73,9 +76,14 @@ export function LoginWithPassword() {
7376
</FormItem>
7477
)}
7578
/>
76-
<Link to="/forget-password" className="block py-1 text-xs text-accent hover:underline">
79+
<a
80+
href={`${env.VITE_WEB_URL}/forget-password`}
81+
target="_blank"
82+
rel="noreferrer"
83+
className="block py-1 text-xs text-accent hover:underline"
84+
>
7785
{t("login.forget_password.note")}
78-
</Link>
86+
</a>
7987
<Button
8088
type="submit"
8189
className="w-full"

apps/renderer/src/modules/auth/LoginModalContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export const AuthProvidersRender: FC<{
214214

215215
if (provider.id === "credential") {
216216
present({
217-
content: LoginWithPassword,
217+
content: () => <LoginWithPassword runtime={runtime} />,
218218
title: t("login.with_email.title"),
219219
})
220220
return

packages/shared/src/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const loginHandler = async (
5858
},
5959
) => {
6060
const { email, password } = args ?? {}
61-
if (IN_ELECTRON) {
61+
if (IN_ELECTRON && provider !== "credential") {
6262
window.open(`${WEB_URL}/login?provider=${provider}`)
6363
} else {
6464
if (provider === "credential") {

0 commit comments

Comments
 (0)