样式优化,markdown优化

This commit is contained in:
2025-08-22 17:14:38 +08:00
parent a1537e3f9f
commit b3d63e4181
11 changed files with 163 additions and 36 deletions

View File

@@ -3,6 +3,7 @@ import { Schema, model, Document } from 'mongoose';
export interface IUser extends Document {
email: string;
passwordHash: string;
name?: string;
createdAt: Date;
updatedAt: Date;
}
@@ -10,6 +11,7 @@ export interface IUser extends Document {
const UserSchema = new Schema<IUser>({
email: { type: String, required: true, unique: true, index: true },
passwordHash: { type: String, required: true }
, name: { type: String }
}, { timestamps: true });
export const User = model<IUser>('User', UserSchema);

View File

@@ -6,13 +6,13 @@ import { signToken } from '../middleware/auth.js';
const router = Router();
router.post('/register', async (req, res) => {
const { email, password } = req.body || {};
const { email, password, name } = req.body || {};
if (!email || !password) return res.status(400).json({ error: 'MISSING_FIELDS' });
const exist = await User.findOne({ email });
if (exist) return res.status(409).json({ error: 'EMAIL_EXISTS' });
const passwordHash = await bcrypt.hash(password, 10);
const user = await User.create({ email, passwordHash });
return res.json({ token: signToken(user.id), user: { id: user.id, email: user.email } });
const user = await User.create({ email, passwordHash, name });
return res.json({ token: signToken(user.id), user: { id: user.id, email: user.email, name: user.name } });
});
router.post('/login', async (req, res) => {
@@ -22,7 +22,7 @@ router.post('/login', async (req, res) => {
if (!user) return res.status(401).json({ error: 'INVALID_CREDENTIALS' });
const ok = await bcrypt.compare(password, user.passwordHash);
if (!ok) return res.status(401).json({ error: 'INVALID_CREDENTIALS' });
return res.json({ token: signToken(user.id), user: { id: user.id, email: user.email } });
return res.json({ token: signToken(user.id), user: { id: user.id, email: user.email, name: user.name } });
});
export default router;