Authentication API
Endpoints for user authentication.
Register
Create a new user account.
Request Body
Validation Rules
| Field | Rules |
|---|---|
name | Required, min 2 characters |
email | Required, valid email format |
password | Required, min 6 characters |
Response
Success (201 Created)
Error (400 Bad Request)
Sign In
Authentication is handled by NextAuth.js. Use the built-in sign-in methods.
Email/Password
This is automatically handled by the NextAuth.js login form.
Google OAuth
Redirect users to:
Sign Out
Or use the NextAuth.js signOut() function.
Get Session
Check the current user's session.
Response (Authenticated)
{
"user": {
"id": "clm...",
"name": "John Doe",
"email": "john@example.com",
"image": null
},
"expires": "2024-02-15T10:30:00Z"
}
Response (Not Authenticated)
Using NextAuth.js Client
In your React components:
import { useSession, signIn, signOut } from "next-auth/react"
function Component() {
const { data: session, status } = useSession()
if (status === "loading") {
return <div>Loading...</div>
}
if (session) {
return (
<div>
<p>Welcome, {session.user.name}</p>
<button onClick={() => signOut()}>Sign out</button>
</div>
)
}
return <button onClick={() => signIn()}>Sign in</button>
}
Protected Routes
Routes under /dashboard, /favorites, /chat, etc. require authentication. Unauthenticated users are redirected to /login.