-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: navbar positioning and remove gradient backgrounds
Changes made: - Removed gradient background animations from globals.css - Fixed navbar positioning to be properly fixed at top - Removed unnecessary padding and margins from layout - Simplified glass-morphism styling with minimal transparency - Updated border styling for better visual consistency - Cleaned up container and grid padding - Optimized main content layout structure
- Loading branch information
1 parent
55b5d36
commit 3cab9f9
Showing
43 changed files
with
3,872 additions
and
1,622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
const jwt = require('jsonwebtoken'); | ||
const asyncHandler = require('express-async-handler'); | ||
const User = require('../models/User'); | ||
|
||
// Protect routes | ||
const protect = asyncHandler(async (req, res, next) => { | ||
let token; | ||
|
||
if ( | ||
req.headers.authorization && | ||
req.headers.authorization.startsWith('Bearer') | ||
) { | ||
try { | ||
// Get token from header | ||
token = req.headers.authorization.split(' ')[1]; | ||
|
||
// Verify token | ||
const decoded = jwt.verify(token, process.env.JWT_SECRET); | ||
|
||
// Get user from token | ||
req.user = await User.findById(decoded.id).select('-password'); | ||
|
||
next(); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(401); | ||
throw new Error('Not authorized'); | ||
} | ||
} | ||
|
||
if (!token) { | ||
res.status(401); | ||
throw new Error('Not authorized, no token'); | ||
} | ||
}); | ||
|
||
// Admin middleware | ||
const admin = (req, res, next) => { | ||
if (req.user && req.user.role === 'admin') { | ||
next(); | ||
} else { | ||
res.status(401); | ||
throw new Error('Not authorized as admin'); | ||
} | ||
}; | ||
|
||
// Renter middleware | ||
const renter = (req, res, next) => { | ||
if (req.user && req.user.role === 'renter') { | ||
next(); | ||
} else { | ||
res.status(401); | ||
throw new Error('Not authorized as renter'); | ||
} | ||
}; | ||
|
||
// Super admin middleware | ||
const superAdmin = (req, res, next) => { | ||
if (req.user && req.user.role === 'superadmin') { | ||
next(); | ||
} else { | ||
res.status(401); | ||
throw new Error('Not authorized as super admin'); | ||
} | ||
}; | ||
|
||
// Check if user is authenticated and has required role | ||
const authorize = (roles = []) => { | ||
if (typeof roles === 'string') { | ||
roles = [roles]; | ||
} | ||
|
||
return [ | ||
protect, | ||
(req, res, next) => { | ||
if (roles.length && !roles.includes(req.user.role)) { | ||
res.status(401); | ||
throw new Error(`Not authorized as ${roles.join(', ')}`); | ||
} | ||
next(); | ||
} | ||
]; | ||
}; | ||
|
||
module.exports = { | ||
protect, | ||
admin, | ||
renter, | ||
superAdmin, | ||
authorize | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const ErrorResponse = require('../utils/errorResponse'); | ||
|
||
const errorHandler = (err, req, res, next) => { | ||
let error = { ...err }; | ||
error.message = err.message; | ||
|
||
// Log to console for dev | ||
console.error(err.stack.red); | ||
|
||
// Mongoose bad ObjectId | ||
if (err.name === 'CastError') { | ||
const message = `Resource not found with id of ${err.value}`; | ||
error = new ErrorResponse(message, 404); | ||
} | ||
|
||
// Mongoose duplicate key | ||
if (err.code === 11000) { | ||
const message = 'Duplicate field value entered'; | ||
error = new ErrorResponse(message, 400); | ||
} | ||
|
||
// Mongoose validation error | ||
if (err.name === 'ValidationError') { | ||
const message = Object.values(err.errors).map(val => val.message); | ||
error = new ErrorResponse(message, 400); | ||
} | ||
|
||
// JWT errors | ||
if (err.name === 'JsonWebTokenError') { | ||
const message = 'Invalid token. Please log in again!'; | ||
error = new ErrorResponse(message, 401); | ||
} | ||
|
||
if (err.name === 'TokenExpiredError') { | ||
const message = 'Your token has expired! Please log in again.'; | ||
error = new ErrorResponse(message, 401); | ||
} | ||
|
||
res.status(error.statusCode || 500).json({ | ||
success: false, | ||
error: error.message || 'Server Error', | ||
stack: process.env.NODE_ENV === 'development' ? err.stack : undefined | ||
}); | ||
}; | ||
|
||
module.exports = errorHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ErrorResponse extends Error { | ||
constructor(message, statusCode) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; | ||
this.isOperational = true; | ||
|
||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
|
||
module.exports = ErrorResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:react/recommended', | ||
'plugin:react-hooks/recommended', | ||
'plugin:@next/next/recommended', | ||
'next/core-web-vitals', | ||
], | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['react', 'react-hooks', '@next/next'], | ||
settings: { | ||
react: { | ||
version: 'detect', | ||
}, | ||
}, | ||
rules: { | ||
// React specific rules | ||
'react/react-in-jsx-scope': 'off', | ||
'react/prop-types': 'off', | ||
'react/display-name': 'off', | ||
'react/no-unescaped-entities': 'off', | ||
|
||
// Next.js specific rules | ||
'@next/next/no-img-element': 'warn', | ||
'@next/next/no-html-link-for-pages': 'error', | ||
|
||
// React Hooks rules | ||
'react-hooks/rules-of-hooks': 'error', | ||
'react-hooks/exhaustive-deps': 'warn', | ||
|
||
// General JavaScript/ES6 rules | ||
'no-unused-vars': ['warn', { | ||
argsIgnorePattern: '^_', | ||
varsIgnorePattern: '^_' | ||
}], | ||
'no-console': ['warn', { allow: ['warn', 'error'] }], | ||
'prefer-const': 'warn', | ||
'no-var': 'error', | ||
|
||
// Import rules | ||
'import/no-anonymous-default-export': 'off', | ||
}, | ||
globals: { | ||
React: 'writable', | ||
JSX: 'writable', | ||
Promise: 'writable', | ||
Set: 'writable', | ||
Map: 'writable', | ||
}, | ||
}; |
Oops, something went wrong.