Successfully migrated from Clerk to NextAuth with Google OAuth provider.
- ✅ Removed all Clerk references from codebase
- ✅ Created NextAuth configuration in
src/pages/api/auth/[...nextauth].ts - ✅ Updated environment variables for Google OAuth
- ✅ Created AuthContext wrapper for NextAuth
- ✅ Updated User model to use string IDs (required for NextAuth)
- ✅ Added NextAuth required tables: Account, Session, VerificationToken
- ✅ Updated foreign key references in Booking, Review, and Post models
- ✅ Created new AuthContext using NextAuth hooks
- ✅ Updated LayoutWrapper to use SessionProvider
- ✅ Updated login/register pages to use Google OAuth
- ✅ Fixed all components using
logoutto usesignOut - ✅ Created reusable AuthButton component
- ✅ Removed Clerk CSP references from next.config.ts
- ✅ Updated environment file comments
Run the following commands to apply the schema changes:
npm run db:migrate- Start the development server:
npm run dev - Navigate to
/loginor/register - Test Google OAuth sign-in
- Verify user data is stored correctly
Ensure these are set in your .env file:
NEXTAUTH_URL=http://localhost:3000NEXTAUTH_SECRET=your-secret-hereGOOGLE_CLIENT_ID=your-google-client-idGOOGLE_CLIENT_SECRET=your-google-client-secret
- User clicks "Sign In" → triggers
signIn('google') - Redirected to Google OAuth consent screen
- After approval, redirected back to app
- NextAuth creates/updates user in database
- Session is established and user is authenticated
import { useAuth } from '@/contexts/AuthContext';
const {
user, // Current user object
isLoading, // Loading state
isAuthenticated, // Boolean auth status
signIn, // Function to sign in
signOut, // Function to sign out
session // Full NextAuth session
} = useAuth();Use the ProtectedRoute component to secure pages:
import ProtectedRoute from '@/components/ProtectedRoute';
<ProtectedRoute allowedRoles={['admin']}>
<AdminContent />
</ProtectedRoute>