diff --git a/apps/renderer/src/modules/app-layout/feed-column/index.mobile.tsx b/apps/renderer/src/modules/app-layout/feed-column/index.mobile.tsx index 3986a88fc..a146f2f95 100644 --- a/apps/renderer/src/modules/app-layout/feed-column/index.mobile.tsx +++ b/apps/renderer/src/modules/app-layout/feed-column/index.mobile.tsx @@ -27,6 +27,7 @@ export const MobileRootLayout = () => { contentClassName="overflow-visible pb-safe" title="Login" hideHeader + dismissableClassName="hidden" content={} /> diff --git a/apps/renderer/src/modules/auth/Form.tsx b/apps/renderer/src/modules/auth/Form.tsx new file mode 100644 index 000000000..a6f3e6223 --- /dev/null +++ b/apps/renderer/src/modules/auth/Form.tsx @@ -0,0 +1,198 @@ +import { Button } from "@follow/components/ui/button/index.js" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@follow/components/ui/form/index.js" +import { Input } from "@follow/components/ui/input/Input.js" +import { loginHandler, signUp } from "@follow/shared/auth" +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) { + 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() { + const { t } = useTranslation("app") + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + email: "", + password: "", + }, + }) + const { isValid } = form.formState + + const { present } = useModalStack() + const { dismiss } = useCurrentModal() + + return ( +
+ + ( + + {t("login.email")} + + + + + + )} + /> + ( + + {t("login.password")} + + + + + + )} + /> + + {t("login.forget_password.note")} + + + + + + ) +} + +const registerFormSchema = z + .object({ + email: z.string().email(), + password: z.string().min(8).max(128), + confirmPassword: z.string(), + }) + .refine((data) => data.password === data.confirmPassword, { + message: "Passwords don't match", + path: ["confirmPassword"], + }) + +function RegisterForm() { + const { t } = useTranslation("app") + + const form = useForm>({ + resolver: zodResolver(registerFormSchema), + defaultValues: { + email: "", + password: "", + confirmPassword: "", + }, + }) + + const { isValid } = form.formState + + function onSubmit(values: z.infer) { + return signUp.email({ + email: values.email, + password: values.password, + name: values.email.split("@")[0], + callbackURL: "/", + fetchOptions: { + onSuccess() { + window.location.reload() + }, + onError(context) { + toast.error(context.error.message) + }, + }, + }) + } + + return ( +
+
+ + ( + + {t("register.email")} + + + + + + )} + /> + ( + + {t("register.password")} + + + + + + )} + /> + ( + + {t("register.confirm_password")} + + + + + + )} + /> + + + +
+ ) +} diff --git a/apps/renderer/src/modules/auth/LoginModalContent.tsx b/apps/renderer/src/modules/auth/LoginModalContent.tsx index 9cef7315b..f3ef0fcae 100644 --- a/apps/renderer/src/modules/auth/LoginModalContent.tsx +++ b/apps/renderer/src/modules/auth/LoginModalContent.tsx @@ -12,10 +12,12 @@ import type { FC } from "react" import { useEffect, useMemo, useRef, useState } from "react" import { useTranslation } from "react-i18next" -import { useCurrentModal } from "~/components/ui/modal/stacked/hooks" +import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks" import type { AuthProvider } from "~/queries/users" import { useAuthProviders } from "~/queries/users" +import { LoginWithPassword } from "./Form" + interface LoginModalContentProps { runtime?: LoginRuntime canClose?: boolean @@ -35,10 +37,12 @@ const defaultProviders = { icon: '', }, } + const overrideProviderIconMap = { apple: , credential: , } + export const LoginModalContent = (props: LoginModalContentProps) => { const modal = useCurrentModal() @@ -194,7 +198,9 @@ export const AuthProvidersRender: FC<{ providers: AuthProvider[] runtime?: LoginRuntime }> = ({ providers, runtime }) => { + const { t } = useTranslation() const [authProcessingLockSet, setAuthProcessingLockSet] = useState(() => new Set()) + const { present } = useModalStack() return ( {providers.length > 0 && ( @@ -205,6 +211,14 @@ export const AuthProvidersRender: FC<{ disabled={authProcessingLockSet.has(provider.id)} onClick={() => { if (authProcessingLockSet.has(provider.id)) return + + if (provider.id === "credential") { + present({ + content: LoginWithPassword, + title: t("login.with_email.title"), + }) + return + } loginHandler(provider.id, runtime) setAuthProcessingLockSet((prev) => { diff --git a/locales/app/en.json b/locales/app/en.json index 94bf861c3..e41ce2a2e 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -228,6 +228,14 @@ "feed_view_type.pictures": "Pictures", "feed_view_type.social_media": "Social Media", "feed_view_type.videos": "Videos", + "login.confirm_password.label": "Confirm Password", + "login.continueWith": "Continue with {{provider}}", + "login.email": "Email", + "login.forget_password.note": "Forgot your password?", + "login.password": "Password", + "login.signUp": "Sign up with email", + "login.submit": "Submit", + "login.with_email.title": "Login with Email", "mark_all_read_button.auto_confirm_info": "Will be confirmed automatically after {{countdown}}s.", "mark_all_read_button.confirm": "Confirm", "mark_all_read_button.confirm_mark_all": "Mark as read?", @@ -287,6 +295,13 @@ "player.volume": "Volume", "quick_add.placeholder": "Quick follow a feed, typing feed url here...", "quick_add.title": "Quick Follow", + "register.confirm_password": "Confirm Password", + "register.email": "Email", + "register.label": "Create a {{app_name}} account", + "register.login": "Login", + "register.note": "Already have an account? ", + "register.password": "Password", + "register.submit": "Create account", "resize.tooltip.double_click_to_collapse": "Double click to collapse", "resize.tooltip.drag_to_resize": "Drag to resize", "search.empty.no_results": "No results found.", @@ -393,6 +408,7 @@ "words.browser": "Browser", "words.confirm": "Confirm", "words.discover": "Discover", + "words.email": "Email", "words.feeds": "Feeds", "words.import": "Import", "words.inbox": "Inbox",