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 theDocumentation 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.
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:- The login form calls
useUser().login(email, password). - The hook POSTs
{ email, password }to/api/login. - The API handler connects to MongoDB and queries for a matching
{ email, password }document. - On a match, the server returns the full user object with HTTP 200.
- The Zustand store sets
isLoggedIn: true,role,name,email, anduserIdfrom the response. - The login component reads
roleand 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:| Role | Dashboard Route |
|---|---|
admin | /admin |
advertiser | /advertiser |
creator | /creator |
Route Protection
Each portal is wrapped by anAuthGuard 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.
Next Steps
Login
Sign in with an existing account and get routed to your dashboard.
Register
Create a new account and select your role.