Server Side Rendering
This guide will help you implement the server-side rendering blog and credential management system in your Next.js portfolio website.
Implementation Guide
This guide will help you implement the server-side rendering blog and credential management system in your Next.js portfolio website.
1. Server-Side Blog Rendering Implementation
Step 1: Update Blog Page Components
Replace your existing blog page components with the server-side rendering versions:
app/blog/page.tsx
- Main blog listing pageapp/blog/[slug]/page.tsx
- Individual blog post page
Both files now include:
// Force dynamic rendering
export const dynamic = 'force-dynamic';
export const revalidate = 0;
These directives tell Next.js to always render these pages server-side on every request, ensuring you always see the latest content.
Step 2: Update Markdown Utilities
Replace your lib/utils/markdown.ts
file with the updated version that:
- Uses
cache: 'no-store'
for fetch requests to ensure fresh content - Includes better error handling for real-time data fetching
- Maintains proper typing for blog post data
2. Credentials Management System Implementation
Step 1: Install Required Dependencies
npm install bcrypt @types/bcrypt
# or
yarn add bcrypt @types/bcrypt
Step 2: Add Type Definitions
Create the file lib/types/auth.ts
with type definitions for:
Credentials
- Admin username and passwordJwtPayload
- JSON Web Token payload structureAuthVerification
- Authentication verification resultPasswordChangeRequest
- Password change request structurePasswordChangeResponse
- Password change response structure
Step 3: Create Credentials Management System
Add the file lib/auth/credentials.ts
implementing:
getCredentials()
- Gets current credentials from file or env varsupdateCredentials()
- Updates credentials with password hashingverifyCredentials()
- Verifies username and password
Step 4: Create Default Credentials File
Create a file credentials.json
in your project root:
{
"username": "admin",
"password": "password"
}
Step 5: Update API Routes
Replace your authentication API routes:
app/api/admin/auth/route.ts
- Updated for credential systemapp/api/admin/change-password/route.ts
- New route for password changes
Step 6: Update Settings Panel Component
Fix the TypeScript errors in your components/admin/settings-panel.tsx
component:
- Add proper return type:
export default function SettingsPanel(): JSX.Element
- Fix nested state update functions
- Improve type safety for form handling
3. Configuration Updates
Environment Variables
Add the following to your .env.local
file:
JWT_SECRET=your-secret-key-change-me
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password
Type Safety for bcrypt
Add the proper type definitions for bcrypt to avoid TypeScript issues.
4. Testing Your Implementation
Testing Server-Side Blog Rendering
- Deploy your site to Vercel
- Upload a new blog post to Vercel Blob storage
- Verify the new post appears on your blog without redeploying
Testing Credential Management
- Log in to your admin dashboard
- Go to Settings > Account
- Update your password using the security form
- Log out and log back in with the new password
- Verify the password has been updated and hashed in credentials.json
5. Security Considerations
- In production, consider using environment variables exclusively rather than a credentials file
- Ensure credentials.json is added to .gitignore to prevent accidental exposure
- Use a strong JWT_SECRET in production
- Implement password complexity requirements
- Consider adding rate limiting to authentication