A comprehensive Next.js application featuring Google/Email authentication via NextAuth and Phantom wallet integration for Solana-based transactions.
- ✅ Google OAuth Authentication - Secure login with Google accounts
- ✅ Email Authentication - Magic link authentication via email
- ✅ Phantom Wallet Integration - Connect and verify Solana wallets
- ✅ Mobile Responsive - Optimized for both desktop and mobile devices
- ✅ Security First - Rate limiting, CSRF protection, and input validation
- ✅ Performance Optimized - Service worker caching and lazy loading
- ✅ Session Management - Secure JWT-based sessions
- ✅ Wallet Verification - Cryptographic signature verification
- Next.js 13.5.6 - React framework with App Router
- NextAuth.js 4.24.5 - Authentication library
- Prisma - Database ORM
- Solana Web3.js - Solana blockchain integration
- Tailwind CSS - Styling framework
- TypeScript - Type safety
- Node.js 18+
- PostgreSQL database
- Google OAuth credentials
- Email service (Gmail recommended)
-
Clone the repository
git clone <your-repo-url> cd nextjs-auth-wallet-connect
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env.local
Fill in your environment variables:
# NextAuth Configuration NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_SECRET=your-secret-key-here # Google OAuth GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret # Database DATABASE_URL="postgresql://username:password@localhost:5432/nextjs_auth_wallet" # Email Configuration EMAIL_SERVER_HOST=smtp.gmail.com EMAIL_SERVER_PORT=587 EMAIL_SERVER_USER=your-email@gmail.com EMAIL_SERVER_PASSWORD=your-app-password EMAIL_FROM=noreply@yourapp.com # Solana Configuration SOLANA_RPC_URL=https://api.mainnet-beta.solana.com SOLANA_NETWORK=mainnet-beta
-
Set up the database
npx prisma generate npx prisma db push
-
Run the development server
npm run dev
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URIs:
http://localhost:3000/api/auth/callback/google(development)https://yourdomain.com/api/auth/callback/google(production)
- Enable 2-factor authentication on your Gmail account
- Generate an App Password:
- Go to Google Account settings
- Security → 2-Step Verification → App passwords
- Generate password for "Mail"
- Use the generated password in
EMAIL_SERVER_PASSWORD
The app automatically detects and connects to Phantom wallets. Users can:
- Connect Wallet - Click "Connect Phantom Wallet" button
- Sign Message - Wallet signs a verification message
- Verify Ownership - Cryptographic verification of wallet ownership
- Disconnect - Remove wallet connection
GET /api/auth/signin- Sign in pagePOST /api/auth/signin/google- Google OAuthPOST /api/auth/signin/email- Email authentication
POST /api/wallet/connect- Connect and verify walletPOST /api/wallet/disconnect- Disconnect walletPOST /api/wallet/verify- Verify wallet signature
GET /api/protected/example- Example protected endpoint
- Rate Limiting - Prevents brute force attacks
- CSRF Protection - Cross-site request forgery prevention
- Input Validation - Sanitizes all user inputs
- Signature Verification - Cryptographic wallet verification
- Secure Headers - Security headers for all responses
- Session Management - Secure JWT-based sessions
- Touch-friendly UI - Optimized for mobile interactions
- Responsive Design - Works on all screen sizes
- Progressive Web App - Service worker for offline functionality
- Mobile Wallet Support - Phantom mobile app integration
- Service Worker Caching - Static asset caching
- Lazy Loading - Component lazy loading
- Image Optimization - Optimized image delivery
- Bundle Splitting - Code splitting for faster loads
- Resource Hints - Preconnect to external domains
- Push your code to GitHub
- Connect your repository to Vercel
- Set environment variables in Vercel dashboard
- Deploy!
The app can be deployed to any platform that supports Next.js:
- Netlify
- Railway
- DigitalOcean App Platform
- AWS Amplify
-
"Phantom wallet not found"
- Ensure Phantom extension is installed
- Check if extension is enabled
-
Database connection errors
- Verify DATABASE_URL is correct
- Ensure PostgreSQL is running
- Run
npx prisma db push
-
Google OAuth errors
- Check client ID and secret
- Verify redirect URIs
- Ensure Google+ API is enabled
-
Email authentication not working
- Verify email credentials
- Check if App Password is correct
- Ensure 2FA is enabled on Gmail
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
For support, please open an issue on GitHub or contact the development team.
Note: This project is compatible with Next.js 13.5.6 and includes optimizations for older versions. For the latest Next.js features, consider upgrading to Next.js 14+.