Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkout #42

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Dockerfile

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@

## Build a basic version of PayTM

- Frontend { Responsive }
- Moving db to cloud
24 changes: 24 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
config.js
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
5 changes: 5 additions & 0 deletions backend/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//backend/config.js
module.exports = {
JWT_SECRET: "your-jwt-secret",
ConnectDB : "mongodb+srv://anuragpratapsingh4845:[email protected]/?"
}
56 changes: 56 additions & 0 deletions backend/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// backend/db.js
const mongoose = require('mongoose');
const { ConnectDB } = require('./config')
const connectDB = async () => {
await mongoose.connect(ConnectDB).then(()=>(console.log("connected")))
}
connectDB()

// Create a Schema for Users
const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
trim: true,
lowercase: true,
minLength: 3,
maxLength: 30
},
password: {
type: String,
required: true,
},
firstName: {
type: String,
required: true,
trim: true,
maxLength: 50
},
lastName: {
type: String,
required: true,
trim: true,
maxLength: 50
}
});

const accountSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId, // Reference to User model
ref: 'User',
required: true
},
balance: {
type: Number,
required: true
}
});

const Account = mongoose.model('Account', accountSchema);
const User = mongoose.model('User', userSchema);

module.exports = {
User,
Account
};
12 changes: 11 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const express = require("express");
// backend/index.js
const express = require('express');
const cors = require("cors");
const rootRouter = require("./routes/index");
const port = process.env.port || 3000;
const app = express();

app.use(cors());
app.use(express.json());

app.use("/api/v1", rootRouter);

app.listen(port);
26 changes: 26 additions & 0 deletions backend/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { JWT_SECRET } = require("./config");
const jwt = require("jsonwebtoken");

const authMiddleware = (req, res, next) => {
const authHeader = req.headers.authorization;

if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(403).json({});
}

const token = authHeader.split(' ')[1];

try {
const decoded = jwt.verify(token, JWT_SECRET);

req.userId = decoded.userId;

next();
} catch (err) {
return res.status(403).json({});
}
};

module.exports = {
authMiddleware
}
Loading