Skip to content

Commit

Permalink
Merge branch 'RSSNext:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dai authored Dec 25, 2024
2 parents ab54e33 + 405ee42 commit fa0ee8e
Show file tree
Hide file tree
Showing 7 changed files with 595 additions and 666 deletions.
32 changes: 20 additions & 12 deletions apps/renderer/src/modules/auth/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,23 @@ import {
FormMessage,
} from "@follow/components/ui/form/index.js"
import { Input } from "@follow/components/ui/input/Input.js"
import type { LoginRuntime } from "@follow/shared/auth"
import { loginHandler, signUp } from "@follow/shared/auth"
import { env } from "@follow/shared/env"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { Link } from "react-router"
import { toast } from "sonner"
import { z } from "zod"

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

async function onSubmit(values: z.infer<typeof formSchema>) {
const res = await loginHandler("credential", "browser", values)
if (res?.error) {
toast.error(res.error.message)
return
}
window.location.reload()
}
const formSchema = z.object({
email: z.string().email(),
password: z.string().max(128),
})
export function LoginWithPassword() {

export function LoginWithPassword({ runtime }: { runtime?: LoginRuntime }) {
const { t } = useTranslation("app")
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand All @@ -44,6 +38,15 @@ export function LoginWithPassword() {
const { present } = useModalStack()
const { dismiss } = useCurrentModal()

async function onSubmit(values: z.infer<typeof formSchema>) {
const res = await loginHandler("credential", runtime ?? "browser", values)
if (res?.error) {
toast.error(res.error.message)
return
}
window.location.reload()
}

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
Expand Down Expand Up @@ -73,9 +76,14 @@ export function LoginWithPassword() {
</FormItem>
)}
/>
<Link to="/forget-password" className="block py-1 text-xs text-accent hover:underline">
<a
href={`${env.VITE_WEB_URL}/forget-password`}
target="_blank"
rel="noreferrer"
className="block py-1 text-xs text-accent hover:underline"
>
{t("login.forget_password.note")}
</Link>
</a>
<Button
type="submit"
className="w-full"
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/modules/auth/LoginModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const AuthProvidersRender: FC<{

if (provider.id === "credential") {
present({
content: LoginWithPassword,
content: () => <LoginWithPassword runtime={runtime} />,
title: t("login.with_email.title"),
})
return
Expand Down
4 changes: 2 additions & 2 deletions apps/renderer/src/modules/profile/profile-setting-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { CopyButton } from "~/components/ui/code-highlighter"
import { toastFetchError } from "~/lib/error-parser"

const formSchema = z.object({
handle: z.string().max(50),
handle: z.string().max(50).optional(),
name: z.string().min(3).max(50),
image: z.string().url(),
})
Expand All @@ -43,7 +43,7 @@ export const ProfileSettingForm = ({
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
handle: user?.handle || "",
handle: user?.handle || undefined,
name: user?.name || "",
image: user?.image || "",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@electron-toolkit/tsconfig": "^1.0.1",
"@hono/node-server": "1.13.7",
"@t3-oss/env-core": "^0.11.1",
"better-auth": "1.0.14",
"better-auth": "1.1.3",
"drizzle-orm": "0.37.0",
"hono": "4.6.13",
"react": "^18.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const loginHandler = async (
},
) => {
const { email, password } = args ?? {}
if (IN_ELECTRON) {
if (IN_ELECTRON && provider !== "credential") {
window.open(`${WEB_URL}/login?provider=${provider}`)
} else {
if (provider === "credential") {
Expand Down
Loading

0 comments on commit fa0ee8e

Please sign in to comment.