diff --git a/src/app/api/auth/[...all]/route.ts b/src/app/api/auth/[...all]/route.ts new file mode 100644 index 0000000..195a923 --- /dev/null +++ b/src/app/api/auth/[...all]/route.ts @@ -0,0 +1,4 @@ +import { auth } from "@/utils/auth"; +import { toNextJsHandler } from "better-auth/next-js"; + +export const { GET, POST } = toNextJsHandler(auth); diff --git a/src/app/page.tsx b/src/app/page.tsx index 295f8fd..7568ce8 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -3,63 +3,7 @@ import Image from "next/image"; export default function Home() { return (
-
- Next.js logo -
-

- To get started, edit the page.tsx file. -

-

- Looking for a starting point or more instructions? Head over to{" "} - - Templates - {" "} - or the{" "} - - Learning - {" "} - center. -

-
-
- - Vercel logomark - Deploy Now - - - Documentation - -
-
+
); } diff --git a/src/app/sign-ip.tsx b/src/app/sign-ip.tsx new file mode 100644 index 0000000..7a690c5 --- /dev/null +++ b/src/app/sign-ip.tsx @@ -0,0 +1,100 @@ +"use client"; + +import { authClient } from "@/utils/auth-client"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; + +export default function SignUp() { + const [isSignUp, setIsSignUp] = useState(false); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [rememberMe, setRememberMe] = useState(false); + + const handleSignUp = async () => { + const { data, error } = await authClient.signUp.email({ + name, + email, + password, + callbackURL: "/", + }); + if (error) { + console.error(error); + window.alert(error.message); + } + }; + + const handleSignIn = async () => { + const { data, error } = await authClient.signIn.email({ + email, + password, + rememberMe, + callbackURL: "/", + }); + if (error) { + console.error(error); + window.alert(error.message); + } + }; + + if (isSignUp) { + return ( +
+

Sign Up

+ setName(e.target.value)} + /> + setEmail(e.target.value)} + /> + setPassword(e.target.value)} + /> + setRememberMe(e.target.checked)} + /> + + +
+ ); + } + return ( +
+

Sign In

+ setEmail(e.target.value)} + /> + setPassword(e.target.value)} + /> + setRememberMe(e.target.checked)} + /> + + +
+ ); +} diff --git a/src/utils/auth-client.ts b/src/utils/auth-client.ts new file mode 100644 index 0000000..e87eaf0 --- /dev/null +++ b/src/utils/auth-client.ts @@ -0,0 +1,5 @@ +import { createAuthClient } from "better-auth/client"; + +export const authClient = createAuthClient({ + baseURL: process.env.BETTER_AUTH_URL!, +});