38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
|
|
const express = require('express');
|
||
|
|
const router = express.Router();
|
||
|
|
const { authenticate } = require('../middleware/auth');
|
||
|
|
|
||
|
|
// Проверка авторизации и получение данных пользователя
|
||
|
|
router.post('/verify', authenticate, async (req, res) => {
|
||
|
|
try {
|
||
|
|
const user = await req.user.populate([
|
||
|
|
{ path: 'followers', select: 'username firstName lastName photoUrl' },
|
||
|
|
{ path: 'following', select: 'username firstName lastName photoUrl' }
|
||
|
|
]);
|
||
|
|
|
||
|
|
res.json({
|
||
|
|
success: true,
|
||
|
|
user: {
|
||
|
|
id: user._id,
|
||
|
|
telegramId: user.telegramId,
|
||
|
|
username: user.username,
|
||
|
|
firstName: user.firstName,
|
||
|
|
lastName: user.lastName,
|
||
|
|
photoUrl: user.photoUrl,
|
||
|
|
bio: user.bio,
|
||
|
|
role: user.role,
|
||
|
|
followersCount: user.followers.length,
|
||
|
|
followingCount: user.following.length,
|
||
|
|
settings: user.settings,
|
||
|
|
banned: user.banned
|
||
|
|
}
|
||
|
|
});
|
||
|
|
} catch (error) {
|
||
|
|
console.error('Ошибка verify:', error);
|
||
|
|
res.status(500).json({ error: 'Ошибка сервера' });
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
module.exports = router;
|
||
|
|
|