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.

Ad Management System uses a straightforward credentials-based authentication model. User accounts — including name, email, password, and role — are stored in MongoDB. On the client side, Zustand manages session state through the useUser store. There is no JWT, no cookie session, and no server-side session token: once the page is refreshed, all in-memory state is cleared and the user must sign in again.

How Authentication Works

When a user submits their credentials, the following sequence runs:
  1. The login form calls useUser().login(email, password).
  2. The hook POSTs { email, password } to /api/login.
  3. The API handler connects to MongoDB and queries for a matching { email, password } document.
  4. On a match, the server returns the full user object with HTTP 200.
  5. The Zustand store sets isLoggedIn: true, role, name, email, and userId from the response.
  6. The login component reads role and redirects the user to their role-specific dashboard.

Role-Based Routing

After a successful login, the app redirects to a dashboard determined by the user’s role:
RoleDashboard Route
admin/admin
advertiser/advertiser
creator/creator

Route Protection

Each portal is wrapped by an AuthGuard component. On every render, AuthGuard reads isLoggedIn from useUser(). If the value is false, the component renders a fallback screen showing the requested path and a Log In link, while simultaneously calling router.push("/") inside a useEffect to redirect the visitor back to the login page. This dual behaviour ensures the user sees a friendly message for the brief moment before the redirect completes.
Zustand state is not persisted to localStorage by default — refreshing the page clears the session and logs the user out. For a production deployment, consider adding Zustand’s persist middleware to survive page reloads, or migrate to NextAuth.js for a fully managed, cookie-backed session.

Next Steps

Login

Sign in with an existing account and get routed to your dashboard.

Register

Create a new account and select your role.

Build docs developers (and LLMs) love