A stylish and customizable Next.js blog template with a sleek dark and light theme, powered by Prisma for MongoDB database access.
Before you begin, ensure you have the following installed:
-
Clone the Repository:
git clone https://github.com/FREDVUNI/nextjs-blog.git cd nextjs-blog
-
Install Dependencies:
npm install
-
Configure Prisma:
Rename
.env.example
to.env
and update the MongoDB connection string. -
Generate Prisma Client:
npx prisma generate
pages/
: Next.js pages for routing.components/
: Reusable React components.styles/
: CSS styles and theme-specific styles.api/
: API routes for CRUD operations.prisma/
: Prisma schema and configuration.
To run the blog locally, use the following command:
npm run dev
The blog will be available at http://localhost:3000
.
This blog supports both dark 🌙 and light ☀️ themes. Users can switch between themes by clicking a theme switcher button. Styles and themes can be customized in the styles/
directory.
This guide outlines the steps required to integrate Prisma with Google Authentication while utilizing MongoDB as the database.
- Node.js installed
- Prisma CLI installed globally (
npm install prisma -g
) - MongoDB database set up
- Google Developer Console project and OAuth 2.0 credentials
Clone the repository to your local machine:
git clone <repository_url>
cd <repository_folder>
Install project dependencies using npm or yarn:
npm install
# or
yarn install
Edit the Prisma schema to define your data model (schema.prisma
):
// schema.prisma
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(uuid())
email String @unique
name String?
// Add other fields as needed
}
Run the Prisma CLI to generate the Prisma Client:
npx prisma generate
# or
prisma generate
Set up the Google Developer Console project and obtain OAuth 2.0 credentials (client ID and secret).
Integrate Google Authentication using libraries like Passport.js or the Google Auth library.
Update the .env
file with your MongoDB connection string:
DATABASE_URL="mongodb://<username>:<password>@<host>:<port>/<database>"
Run the application:
npm start
# or
yarn start
Visit http://localhost:3000
in your browser to access the application.
- Ensure proper error handling and security measures for authentication.
- Refer to Prisma and MongoDB documentation for detailed configurations and usage.
API routes in the api/
directory handle CRUD operations for blog posts. You can customize and extend these routes as needed.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the Repository.
- Create a New Branch: Use a descriptive name for your feature or bug fix.
- Make Your Changes: Write clean and well-documented code.
- Push Your Changes: Push your branch to your fork.
- Create a Pull Request: Submit your changes to the
main
branch of this repository.