Skip to content

Commit

Permalink
feat: Add User auth and refactor client api urls for data fetching
Browse files Browse the repository at this point in the history
Added login, logout and register api endpoints in server

Changes data fetching urls in client
  • Loading branch information
builtbysuraj committed Feb 11, 2024
1 parent ff690ce commit 025b735
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 314 deletions.
2 changes: 1 addition & 1 deletion client/src/context/ServerStatusProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ServerStatusProvider({ children }: PropsWithChildren) {
useEffect(() => {
const checkServerStatus = async () => {
try {
const { data } = await axios.get(`${ENV.SERVER_URL}/api/status`)
const { data } = await axios.get(`${ENV.SERVER_URL}/api/v1/status`)

if (data.status) {
setServerStatus(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function PlaceOrder() {
amount: order.amount,
currency: 'INR',
name: 'RazorPay',
description: 'Tutorial of RazorPay',
description: 'Secure payment through RazorPay',
// image: 'https://avatars.githubusercontent.com/u/25058652?v=4',
order_id: order.id,
callback_url: 'http://localhost:5000/api/v1/paymentverification',
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/payment-success/PaymentSuccessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function PaymentSuccessPage() {
if (referenceNum) {
console.log(referenceNum)
const response = await fetch(
`http://localhost:5000/verify-payment?paymentId=${referenceNum}`
`http://localhost:5000/api/v1/verify-payment?paymentId=${referenceNum}`
)
const data = await response.json()
if (data.success) {
Expand Down
238 changes: 0 additions & 238 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "nodemon src/index.ts",
"start": "node index.js",
"format": "prettier --write ./src",
"check-format": "prettier --check ./src"
"check-format": "prettier --check ./src",
"check-types": "tsc --pretty --noEmit"
},
"dependencies": {
"bcryptjs": "^2.4.3",
Expand All @@ -16,14 +17,12 @@
"express": "^4.18.2",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.1.1",
"pg": "^8.11.3",
"razorpay": "^2.9.2"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^20.10.5",
"@types/pg": "^8.10.9",
"nodemon": "^3.0.3",
"prettier": "^3.1.1",
"ts-node": "^10.9.2",
Expand Down
31 changes: 5 additions & 26 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,12 @@ app.use(express.static('public'))
app.use(cookieParser())

// Routes
import { Payment } from './models/payment.model'
import paymentRoute from './routes/payment.routes'

app.get('/api/status', (req, res) => {
res.json({ status: true, message: 'Server is running' })
})
import generalRoute from './routes/general.route'
import paymentRoute from './routes/payment.route'
import userRoute from './routes/user.route'

app.use('/api/v1', generalRoute)
app.use('/api/v1', paymentRoute)

app.get('/api/v1/get-key', (req, res) =>
res.status(200).json({ key: ENV.RAZORPAY_API_KEY })
)

app.get('/verify-payment', async (req, res) => {
const paymentId = req.query.paymentId
console.log(paymentId)
try {
const payment = await Payment.findOne({ razorpay_payment_id: paymentId })

if (payment) {
res.json({ success: true })
} else {
res.json({ success: false })
}
} catch (error) {
res.status(500).json({ success: false })
}
})
app.use('/api/v1', userRoute)

export default app
Loading

0 comments on commit 025b735

Please sign in to comment.