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/app/signin/page.tsx | 11 +- apps/web/app/signup/page.tsx | 22 ++ apps/web/components/signin/CredentialsForm.tsx | 295 +++++++-------------- apps/web/components/signin/SignInForm.tsx | 74 ++++-- .../web/components/signin/SignInProviderButton.tsx | 1 + apps/web/components/signup/SignUpForm.tsx | 228 ++++++++++++++++ 6 files changed, 393 insertions(+), 238 deletions(-) create mode 100644 apps/web/app/signup/page.tsx create mode 100644 apps/web/components/signup/SignUpForm.tsx diff --git a/apps/web/app/signin/page.tsx b/apps/web/app/signin/page.tsx index 372429e8..a784dd7e 100644 --- a/apps/web/app/signin/page.tsx +++ b/apps/web/app/signin/page.tsx @@ -10,12 +10,11 @@ export default async function SignInPage() { } return ( -
- -
- -
-
+
+
+
+ +
diff --git a/apps/web/app/signup/page.tsx b/apps/web/app/signup/page.tsx new file mode 100644 index 00000000..841c07a8 --- /dev/null +++ b/apps/web/app/signup/page.tsx @@ -0,0 +1,22 @@ +import { redirect } from "next/dist/client/components/navigation"; +import KarakeepLogo from "@/components/KarakeepIcon"; +import SignUpForm from "@/components/signup/SignUpForm"; +import { getServerAuthSession } from "@/server/auth"; + +export default async function SignUpPage() { + const session = await getServerAuthSession(); + if (session) { + redirect("/"); + } + + return ( +
+
+
+ +
+ +
+
+ ); +} 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} diff --git a/apps/web/components/signup/SignUpForm.tsx b/apps/web/components/signup/SignUpForm.tsx new file mode 100644 index 00000000..85346f98 --- /dev/null +++ b/apps/web/components/signup/SignUpForm.tsx @@ -0,0 +1,228 @@ +"use client"; + +import { useState } from "react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { ActionButton } from "@/components/ui/action-button"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { useClientConfig } from "@/lib/clientConfig"; +import { api } from "@/lib/trpc"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { TRPCClientError } from "@trpc/client"; +import { AlertCircle, UserX } 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 VERIFY_EMAIL_ERROR = "Please verify your email address before signing in"; + +export default function SignUpForm() { + const form = useForm>({ + resolver: zodResolver(zSignUpSchema), + }); + const [errorMessage, setErrorMessage] = useState(""); + const router = useRouter(); + const clientConfig = useClientConfig(); + + const createUserMutation = api.users.create.useMutation(); + + if ( + clientConfig.auth.disableSignups || + clientConfig.auth.disablePasswordAuth + ) { + return ( + + + + Sign Up Unavailable + + + Account registration is currently disabled + + + +
+ + + + Signups are currently disabled. Please contact an administrator + for access. + + + +
+
+
+ ); + } + + return ( + + + + Create Your Account + + + Join Karakeep to start organizing your bookmarks + + + +
+ { + 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("/"); + })} + className="space-y-4" + > + {errorMessage && ( + + + {errorMessage} + + )} + + ( + + Full Name + + + + + + )} + /> + + ( + + Email + + + + + + )} + /> + + ( + + Password + + + + + + )} + /> + + ( + + Confirm Password + + + + + + )} + /> + + + Create Account + + + + +
+

+ Already have an account?{" "} + + Sign in + +

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