A prompt workshop app made with nextjs.
npm install bcrypt # hash passpord
npm install mongodb # database
npm install mongoose # manage database
npm install next-auth # 3rd party authentication - google, facebook etc
# only display directories and ignore node_modules
tree -d -I node_modules
output:
├── app # main code logics
├── components # components
├── models # models for database
├── public # public assets
│ └── assets # assets
│ ├── icons # icons
│ └── images # images
├── styles # styles
└── utils # utilitity functions
# NextAuth Secret Environment Variable( generate by openssl )
openssl rand -base64 32
# remove cached .env
git rm .env --cached
[1]. implement search functionality
- Search by prompt
- Search by tag
- Search by username
[2]. implement click on tag
[3]. implement view other profiles
-
Support both
Server Side Rendering( SSR )
andClient Side Rendering( CSR )
, which is benenficial to SEO. -
Routing systems become simple:
1. ReactJS Routing
ReactJS -> React-Router-DOM -> Create Routes
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
# Rap your app with BrowserRouter
<BrowserRouter>
<App />
</BrowserRouter>
# Define you Routes in your app and import it on the top
<Routes>
<Route path="/" element={<Home />} />
<Route path="/create" element={<Create />} />
<Route path="/blogs/:id" element={<BlogDetails />} />
<Route path="*" element={<NotFound />} />
</Routes>
# Now you are all set. You can use this with
<Link to="/create" element={Create}/>
2. NextJS Routing
# Use a directory based routing system
app
|---blog -> /blog
|---about -> /about
|---profile -> /profile
|---services -> /services
handler: app/blog/page.jsx
- Fullstack Application Support
API routes -> serverless functions to handle API requests
# dir
app
|---api
|---|
|------profile
|------|
|---------route.js
API handler: app/api/profile/route.js -> localhost:3000/api/profile
# code
# GET request
export const GET = async (req, res) => {
// ...
};
# POST request
export const POST = async (req, res) => {
// ...
};
- Automatic code splitting
This feature would load code chunks when needed, reducing the initial load time of a website.
- It's still React, we, developers, just need to focus on business logic.
# static export
export const metadata = {
title: "",
description: ""
};
# dynamic export
export async function generateMeta() {
// ...
// some code logic
// ....
return {
title: "",
description: ""
};
};
NB: static export and dynamic export cannot be coexisted in a single file
-
Google Authentication: https://console.cloud.google.com/
-
MongoDB Atlas: https://www.mongodb.com/atlas
-
NextAuth Documentation: https://next-auth.js.org/getting-started/example
-
NextAuth Provider Config: https://next-auth.js.org/configuration/providers/oauth
-
OpenSSL Terminal Online: https://www.cryptool.org/en/cto/openssl
-
Vercel Deployment: https://vercel.com/
-
Github OAuth 2.0 Authentication: https://github.com/settings/developers
This project is licensed under the terms of the MIT license.