diff --git a/apps/web/src/app/auth/login/page.tsx b/apps/web/src/app/auth/login/page.tsx new file mode 100644 index 0000000..5eadb85 --- /dev/null +++ b/apps/web/src/app/auth/login/page.tsx @@ -0,0 +1,98 @@ +"use client"; + +import { useSearchParams, useRouter } from "next/navigation"; +import { authClient } from "@/lib/auth-client"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Suspense, useState } from "react"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import Link from "next/link"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; + +function LoginForm() { + const searchParams = useSearchParams(); + const router = useRouter(); + const redirectUrl = searchParams.get("redirect"); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [error, setError] = useState(null); + + const handleLogin = async () => { + setError(null); + const { error } = await authClient.signIn.email({ + email, + password, + }); + + if (error) { + setError(error.message || "An unexpected error occurred."); + return; + } + + router.push(redirectUrl || "/"); + }; + + return ( +
+ {error && ( + + Error + {error} + + )} +
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+ +
+ ); +} + +export default function LoginPage() { + return ( +
+ + + Login + + Enter your email and password to login. + + + + Loading...
}> + + +
+ Don't have an account?{" "} + + Sign up + +
+ + + + ); +} diff --git a/apps/web/src/app/auth/signup/page.tsx b/apps/web/src/app/auth/signup/page.tsx new file mode 100644 index 0000000..f328851 --- /dev/null +++ b/apps/web/src/app/auth/signup/page.tsx @@ -0,0 +1,108 @@ +"use client"; + +import { useSearchParams, useRouter } from "next/navigation"; +import { authClient } from "@/lib/auth-client"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Suspense, useState } from "react"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import Link from "next/link"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; + +function SignUpForm() { + const searchParams = useSearchParams(); + const router = useRouter(); + const redirectUrl = searchParams.get("redirect"); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [error, setError] = useState(null); + + const handleSignUp = async () => { + setError(null); + const { error } = await authClient.signUp.email({ + name, + email, + password, + }); + + if (error) { + setError(error.message || "An unexpected error occurred."); + return; + } + + router.push(redirectUrl || "/"); + }; + + return ( +
+ {error && ( + + Error + {error} + + )} +
+ + setName(e.target.value)} + /> +
+
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+ +
+ ); +} + +export default function SignUpPage() { + return ( +
+ + + Sign Up + Create an account to get started. + + + Loading...
}> + + +
+ Already have an account?{" "} + + Login + +
+ + + + ); +} diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts index d381e6a..4cfaa6f 100644 --- a/apps/web/src/lib/auth.ts +++ b/apps/web/src/lib/auth.ts @@ -14,7 +14,7 @@ export const auth = betterAuth({ }, }, emailAndPassword: { - enabled: false, + enabled: true, }, appName: "OpenCut", trustedOrigins: ["http://localhost:3000"],