Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Bulk reformats. `git config blame.ignoreRevsFile .git-blame-ignore-revs`
6931e92c330346f224e44283fde38346afb1d527 # prettier, 199 files
28 changes: 14 additions & 14 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
version: 2
updates:
# JavaScript/TypeScript dependencies (npm)
- package-ecosystem: "npm"
directory: "/"
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: "weekly"
day: "monday"
interval: 'weekly'
day: 'monday'
open-pull-requests-limit: 10
commit-message:
prefix: "deps"
prefix: 'deps'
labels:
- "dependencies"
- "security"
- 'dependencies'
- 'security'

# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: "weekly"
day: "monday"
interval: 'weekly'
day: 'monday'
commit-message:
prefix: "ci"
prefix: 'ci'
labels:
- "ci"
- "dependencies"
- 'ci'
- 'dependencies'
26 changes: 26 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build output and vendored trees — formatting these is noise.
node_modules
.next
dist
build
out
coverage
.turbo
.vercel
*.min.js
*.min.css

# Lockfiles are generated; prettier would rewrite them wholesale.
package-lock.json
pnpm-lock.yaml
yarn.lock

# Markdown is deliberately out of scope for now. Prettier rewraps prose, which
# is where it is most opinionated and least useful, and it would bury the real
# diff. Remove this line when you want docs formatted too.
*.md

# Generated during the build CI runs before format:check, so it never exists
# locally at check time. Contentlayer output also uses import assertions,
# which prettier cannot parse.
.contentlayer
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"trailingComma": "all",
"arrowParens": "always",
"endOfLine": "lf"
}
79 changes: 45 additions & 34 deletions backend/controllers/authController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const prisma = require('../lib/prisma');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const { success, error, validationError, unauthorized, notFound, created } = require('../utils/responseHandlers');
const {
success,
error,
validationError,
unauthorized,
notFound,
created,
} = require('../utils/responseHandlers');
const redis = require('../lib/redis');

function setAuthCookies(res, token) {
Expand All @@ -26,7 +33,7 @@ exports.register = async (req, res) => {

// Check if user already exists
const existingUser = await prisma.user.findUnique({
where: { email }
where: { email },
});

if (existingUser) {
Expand All @@ -43,23 +50,23 @@ exports.register = async (req, res) => {
email,
passwordHash,
name: name || null,
role: 'USER'
role: 'USER',
},
select: {
id: true,
email: true,
name: true,
role: true,
createdAt: true
}
createdAt: true,
},
});

// Create and sign a JWT
const payload = {
user: {
id: user.id,
email: user.email,
role: user.role
role: user.role,
},
};

Expand All @@ -74,7 +81,7 @@ exports.register = async (req, res) => {
}
setAuthCookies(res, token);
return created(res, { token, user }, 'User registered successfully');
}
},
);
} catch (err) {
console.error('Registration error:', err);
Expand All @@ -101,8 +108,8 @@ exports.login = async (req, res) => {
role: true,
passwordHash: true,
isActive: true,
createdAt: true
}
createdAt: true,
},
});

if (!user || !user.isActive) {
Expand All @@ -120,7 +127,7 @@ exports.login = async (req, res) => {
user: {
id: user.id,
email: user.email,
role: user.role
role: user.role,
},
};

Expand All @@ -134,17 +141,21 @@ exports.login = async (req, res) => {
return error(res, 'Token generation failed');
}
setAuthCookies(res, token);
return success(res, {
token,
user: {
id: user.id,
email: user.email,
name: user.name,
role: user.role,
createdAt: user.createdAt
}
}, 'Login successful');
}
return success(
res,
{
token,
user: {
id: user.id,
email: user.email,
name: user.name,
role: user.role,
createdAt: user.createdAt,
},
},
'Login successful',
);
},
);
} catch (err) {
console.error('Login error:', err);
Expand All @@ -170,10 +181,10 @@ exports.getProfile = async (req, res) => {
select: {
id: true,
name: true,
slug: true
}
}
}
slug: true,
},
},
},
});

if (!user) {
Expand All @@ -191,21 +202,21 @@ exports.getProfile = async (req, res) => {
exports.updateProfile = async (req, res) => {
try {
const { name, avatar } = req.body;

const user = await prisma.user.update({
where: { id: req.user.id },
data: {
...(name && { name }),
...(avatar && { avatar })
...(avatar && { avatar }),
},
select: {
id: true,
email: true,
name: true,
role: true,
avatar: true,
updatedAt: true
}
updatedAt: true,
},
});

return success(res, { user }, 'Profile updated successfully');
Expand All @@ -229,8 +240,8 @@ exports.changePassword = async (req, res) => {
where: { id: req.user.id },
select: {
id: true,
passwordHash: true
}
passwordHash: true,
},
});

if (!user || !user.passwordHash) {
Expand All @@ -250,7 +261,7 @@ exports.changePassword = async (req, res) => {
// Update password
await prisma.user.update({
where: { id: req.user.id },
data: { passwordHash: newPasswordHash }
data: { passwordHash: newPasswordHash },
});

return success(res, {}, 'Password changed successfully');
Expand All @@ -269,7 +280,7 @@ exports.verifyToken = async (req, res) => {
console.error('Verify token error:', err);
return error(res, 'Server error verifying token', 500, err);
}
};
};

// Logout: clear cookie
exports.logout = async (req, res) => {
Expand All @@ -279,4 +290,4 @@ exports.logout = async (req, res) => {
} catch (err) {
return error(res, 'Server error during logout', 500, err);
}
};
};
Loading