From db9a02b84724c621a37ec161b8cebc0b313985fb Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 12 Jul 2025 09:45:41 +0000 Subject: feat(ui): Revamp the signin/signup page --- apps/web/components/signin/CredentialsForm.tsx | 295 ++++++++----------------- 1 file changed, 89 insertions(+), 206 deletions(-) (limited to 'apps/web/components/signin/CredentialsForm.tsx') diff --git a/apps/web/components/signin/CredentialsForm.tsx b/apps/web/components/signin/CredentialsForm.tsx index 05aa1cef..1ad240a7 100644 --- a/apps/web/components/signin/CredentialsForm.tsx +++ b/apps/web/components/signin/CredentialsForm.tsx @@ -1,8 +1,10 @@ "use client"; import { useState } from "react"; +import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { ActionButton } from "@/components/ui/action-button"; +import { Alert, AlertTitle } from "@/components/ui/alert"; import { Form, FormControl, @@ -12,17 +14,13 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useClientConfig } from "@/lib/clientConfig"; -import { api } from "@/lib/trpc"; import { zodResolver } from "@hookform/resolvers/zod"; -import { TRPCClientError } from "@trpc/client"; +import { AlertCircle, Lock } from "lucide-react"; import { signIn } from "next-auth/react"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { zSignUpSchema } from "@karakeep/shared/types/users"; - const signInSchema = z.object({ email: z.string().email(), password: z.string(), @@ -33,7 +31,7 @@ const OAUTH_FAILED = "OAuth login failed: "; const VERIFY_EMAIL_ERROR = "Please verify your email address before signing in"; -function SignIn() { +export default function CredentialsForm() { const [signinError, setSigninError] = useState(""); const router = useRouter(); const searchParams = useSearchParams(); @@ -50,229 +48,114 @@ function SignIn() { if (clientConfig.auth.disablePasswordAuth) { return ( - <> +
{signinError && ( -

{signinError}

+ + + {signinError} + )} -

- Password authentication is currently disabled. -

- + + + + Password authentication is currently disabled. + + +
); } return ( -
- { - const resp = await signIn("credentials", { - redirect: false, - email: value.email.trim(), - password: value.password, - }); - if (!resp || !resp?.ok || resp.error) { - if (resp?.error === "CredentialsSignin") { - setSigninError(SIGNIN_FAILED); - } else if (resp?.error === VERIFY_EMAIL_ERROR) { - router.replace( - `/check-email?email=${encodeURIComponent(value.email.trim())}`, - ); - } else { - setSigninError(resp?.error ?? SIGNIN_FAILED); +
+ + { + const resp = await signIn("credentials", { + redirect: false, + email: value.email.trim(), + password: value.password, + }); + if (!resp || !resp?.ok || resp.error) { + if (resp?.error === "CredentialsSignin") { + setSigninError(SIGNIN_FAILED); + } else if (resp?.error === VERIFY_EMAIL_ERROR) { + router.replace( + `/check-email?email=${encodeURIComponent(value.email.trim())}`, + ); + } else { + setSigninError(resp?.error ?? SIGNIN_FAILED); + } + return; } - return; - } - router.replace("/"); - })} - > -
+ router.replace("/"); + })} + className="space-y-4" + > {signinError && ( -

{signinError}

+ + + {signinError} + )} + { - return ( - - Email - - - - - - ); - }} + render={({ field }) => ( + + Email + + + + + + )} /> + { - return ( - - Password - - - - - - ); - }} + render={({ field }) => ( + + Password + + + + + + )} /> + Sign In -
- - - ); -} - -function SignUp() { - const form = useForm>({ - resolver: zodResolver(zSignUpSchema), - }); - const [errorMessage, setErrorMessage] = useState(""); - - const router = useRouter(); - - const createUserMutation = api.users.create.useMutation(); - - return ( -
- { - try { - await createUserMutation.mutateAsync(value); - } catch (e) { - if (e instanceof TRPCClientError) { - setErrorMessage(e.message); - } - return; - } - const resp = await signIn("credentials", { - redirect: false, - email: value.email.trim(), - password: value.password, - }); - if (!resp || !resp.ok || resp.error) { - if (resp?.error === VERIFY_EMAIL_ERROR) { - router.replace( - `/check-email?email=${encodeURIComponent(value.email.trim())}`, - ); - } else { - setErrorMessage( - resp?.error ?? "Hit an unexpected error while signing in", - ); - } - return; - } - router.replace("/"); - })} - > -
- {errorMessage && ( -

- {errorMessage} -

- )} - { - return ( - - Name - - - - - - ); - }} - /> - { - return ( - - Email - - - - - - ); - }} - /> - { - return ( - - Password - - - - - - ); - }} - /> - { - return ( - - Confirm Password - - - - - - ); - }} - /> - - Sign Up - -
-
- - ); -} - -export default function CredentialsForm() { - const clientConfig = useClientConfig(); - - return ( - - - Sign In - Sign Up - - - - - - {clientConfig.auth.disableSignups || - clientConfig.auth.disablePasswordAuth ? ( -

Signups are currently disabled.

- ) : ( - - )} -
-
+ + + +
+

+ Don't have an account?{" "} + + Sign up + +

+
+
); } -- cgit v1.2.3-70-g09d2