Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Priyanshu471/ad-management/llms.txt

Use this file to discover all available pages before exploring further.

Signing in to Ad Management System requires an email address and password that match an existing record in MongoDB. When the credentials are verified, the Zustand useUser store updates session state and the app automatically redirects you to the dashboard that corresponds to your assigned role — /admin, /advertiser, or /creator.

How to Log In

1

Open the login page

Navigate to http://localhost:3000/. The root route serves the Login page by default (see LOGIN_ROUTE = "/").
2

Enter your credentials

Type your registered email address and password into the form fields.
3

Submit the form

Click Sign In. The app calls useUser().login(), which POSTs your credentials to /api/login.
4

Get redirected

On a successful response, useUser stores your session data and the login component redirects you to your role dashboard (/admin, /advertiser, or /creator).

API Request

The login form triggers the following fetch call inside useUser.login():
hooks/useUser.tsx
const res = await fetch("/api/login", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ email, password }),
});
The server handler connects to MongoDB, queries for a user document matching both email and password, and returns the result.

Successful Response

On a valid match the API returns HTTP 200 with the user object:
{
  "user": {
    "_id": "65f1a2b3c4d5e6f7a8b9c0d1",
    "name": "jane doe",
    "email": "jane@example.com",
    "role": "advertiser",
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:30:00.000Z"
  }
}

Error Responses

If login fails, the API returns a plain-text error message with one of the following status codes:
StatusCauseMessage
400Wrong email or passwordEmail or password is incorrect
500Database or server errorInternal server error
The login component surfaces these messages directly in the UI so the user can correct their input.
Passwords are currently stored and compared as plain text. For production use, integrate bcrypt (already listed in the project’s dependencies) to hash passwords before saving them and to safely compare them at login time.

Post-Login Session State

After a successful login, the useUser() store holds the following values for the duration of the browser session:
FieldValue
userIdMongoDB _id of the authenticated user
nameUser’s display name
emailUser’s email address
roleadmin, advertiser, or creator
isLoggedIntrue

Build docs developers (and LLMs) love