This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.js. The page auto-updates as you edit the file.
This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details
A modern, role-based authentication system built with Next.js 13+ App Router, Firebase, and Tailwind CSS.
src/
βββ app/
β βββ auth/
β β βββ page.jsx # Main authentication page
β βββ verify/
β β βββ page.jsx # Email verification page (create as needed)
β βββ profile/
β β βββ page.jsx # Profile setup page (create as needed)
β βββ student/
β β βββ dashboard/
β β βββ page.jsx # Student dashboard
β βββ teacher/
β β βββ dashboard/
β β βββ page.jsx # Teacher dashboard
β βββ institute/
β β βββ dashboard/
β β βββ page.jsx # Institute dashboard
β βββ admin/
β β βββ dashboard/
β β βββ page.jsx # Admin dashboard
β βββ layout.jsx # Root layout
β βββ page.jsx # Home page
β
βββ components/
β βββ AuthForm.jsx # Main authentication form
β βββ RoleSelection.jsx # Role selection interface
β βββ HeroSection.jsx # Marketing/hero content
β βββ ForgotPasswordModal.jsx # Password reset modal
β βββ Navbar.jsx # Navigation component
β
βββ constants/
β βββ userRoles.js # User roles and configurations
β
βββ services/
β βββ authService.js # Firebase authentication services
β
βββ utils/
β βββ authUtils.js # Authentication utility functions
β
βββ hooks/
β βββ useAuth.js # Custom authentication hook
β
βββ lib/
βββ firebaseConfig.js # Firebase configuration
- Before (Pages Router):
pages/auth.jsx - After (App Router):
app/auth/page.jsx
// App Router uses next/navigation instead of next/router
import { useRouter } from "next/navigation";// App Router pages export default function
export default function AuthPage() {
// Component logic
}The routing in App Router is based on folder structure:
/authβapp/auth/page.jsx/verifyβapp/verify/page.jsx/student/dashboardβapp/student/dashboard/page.jsx
app/verify/page.jsx (Email Verification):
"use client";
export default function VerifyPage() {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-center">
<h1>Check Your Email</h1>
<p>We've sent you a verification link.</p>
</div>
</div>
);
}app/profile/page.jsx (Profile Setup):
"use client";
export default function ProfilePage() {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-center">
<h1>Complete Your Profile</h1>
{/* Profile setup form */}
</div>
</div>
);
}Dashboard Pages (create as needed):
// app/student/dashboard/page.jsx
"use client";
export default function StudentDashboard() {
return <div>Student Dashboard</div>;
}
// app/teacher/dashboard/page.jsx
"use client";
export default function TeacherDashboard() {
return <div>Teacher Dashboard</div>;
}
// app/institute/dashboard/page.jsx
"use client";
export default function InstituteDashboard() {
return <div>Institute Dashboard</div>;
}
// app/admin/dashboard/page.jsx
"use client";
export default function AdminDashboard() {
return <div>Admin Dashboard</div>;
}import './globals.css'
export const metadata = {
title: 'Premium Auth System',
description: 'Role-based authentication system',
}
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}The redirectBasedOnRole function works the same way since we're using router.push() from next/navigation.
- Create the folder structure as shown above
- Move/create files in their respective App Router locations
- Update imports to use
next/navigation - Create missing pages (verify, profile, dashboards)
- Test the routing to ensure all redirects work properly
- Faster navigation with client-side routing
- Better SEO with server-side rendering support
- Simplified routing based on file system
- Improved performance with automatic code splitting
- Better TypeScript support (when using TypeScript)
- All interactive components must use
"use client"directive - Server components can be used for static content (like layouts)
- Metadata is handled differently in App Router
- Error handling and loading states work similarly
- Route groups can be used with
(auth)folders if needed
- Move
pages/auth.jsxtoapp/auth/page.jsx - Update imports from
next/routertonext/navigation - Add
"use client"to interactive components - Create missing dashboard pages
- Create verify and profile pages
- Update any API routes (if using)
- Test all authentication flows
- Test role-based redirections
This structure follows Next.js 13+ App Router conventions and provides better performance and developer experience!