Uses Express js
- User Sign-Up
- User Login
- User Logout
- Protected Routes
-
Clone the repository:
git clone https://github.com/SUGAM-ARORA/UniCollab cd backend
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory with the following contents:PORT=5000 MONGODB_URI=mongodb://localhost:27017/mydatabase JWT_SECRET=your_jwt_secret
-
Start the application:
node index.js
The server will start on
http://localhost:5000
.
-
Sign-Up
POST /auth/signup
Body:
{ "username": "yourusername", "email": "your.email@example.com", "password": "yourpassword" }
-
Login
POST /auth/login
Body:
{ "email": "your.email@example.com", "password": "yourpassword" }
Response:
- Sets a cookie named
token
with the JWT.
- Sets a cookie named
-
Logout
POST /auth/logout
Response:
- Clears the
token
cookie.
- Clears the
-
Protected Route
GET /protected
Headers:
- Requires
token
cookie set.
Response:
{ "message": "Hello <username>, this is a protected route." }
- Requires
Contributions are welcome! Please open an issue or submit a pull request if you would like to contribute.