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 +++++++-------------- apps/web/components/signin/SignInForm.tsx | 74 ++++-- .../web/components/signin/SignInProviderButton.tsx | 1 + 3 files changed, 138 insertions(+), 232 deletions(-) (limited to 'apps/web/components/signin') 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 + +

+
+
); } diff --git a/apps/web/components/signin/SignInForm.tsx b/apps/web/components/signin/SignInForm.tsx index ca8f3137..8ad39f8f 100644 --- a/apps/web/components/signin/SignInForm.tsx +++ b/apps/web/components/signin/SignInForm.tsx @@ -1,4 +1,13 @@ +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; import { authOptions } from "@/server/auth"; +import { Info } from "lucide-react"; import serverConfig from "@karakeep/shared/config"; @@ -16,34 +25,47 @@ export default async function SignInForm() { } return ( -
- {serverConfig.demoMode && ( -
-

Demo Mode

-

Email: {serverConfig.demoMode.email}

-

Password: {serverConfig.demoMode.password}

-
- )} - +
+ + + Welcome Back + Sign in to your Karakeep account + + + {serverConfig.demoMode && ( + + + +
+

Demo Mode

+

Email: {serverConfig.demoMode.email}

+

Password: {serverConfig.demoMode.password}

+
+
+
+ )} - {providerValues && providerValues.length > 0 && ( - <> -
-
- Or -
-
-
- {providerValues.map((provider) => ( -
- + + + {providerValues && providerValues.length > 0 && ( + <> +
+
+ Or +
+
+
+ {providerValues.map((provider) => ( + + ))}
- ))} -
- - )} + + )} + +
); } diff --git a/apps/web/components/signin/SignInProviderButton.tsx b/apps/web/components/signin/SignInProviderButton.tsx index e866c878..edb411e6 100644 --- a/apps/web/components/signin/SignInProviderButton.tsx +++ b/apps/web/components/signin/SignInProviderButton.tsx @@ -18,6 +18,7 @@ export default function SignInProviderButton({ callbackUrl: "/", }) } + className="w-full" > Sign in with {provider.name} -- cgit v1.2.3-70-g09d2