mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
const express = require('express');
|
|
const usersRepo = require('../repositories/usersRepo');
|
|
const config = require('../config');
|
|
const asyncHandler = require('../lib/asyncHandler');
|
|
|
|
const router = express.Router();
|
|
|
|
function authentikAccountUrl() {
|
|
if (!config.authentikPublicUrl) return null;
|
|
return new URL('/if/user/', config.authentikPublicUrl).href;
|
|
}
|
|
|
|
router.get(
|
|
'/me',
|
|
asyncHandler(async (req, res) => {
|
|
const { id, name, username, email, avatar_url, is_admin } = req.user;
|
|
res.json({
|
|
id,
|
|
name,
|
|
username,
|
|
email,
|
|
avatarUrl: avatar_url,
|
|
isAdmin: is_admin,
|
|
authentikAccountUrl: authentikAccountUrl(),
|
|
});
|
|
})
|
|
);
|
|
|
|
router.get(
|
|
'/me/profile',
|
|
asyncHandler(async (req, res) => {
|
|
const { id, name, username, email, avatar_url, groups, is_admin, created_at } = req.user;
|
|
const stats = await usersRepo.getActivityStats(id);
|
|
res.json({
|
|
id,
|
|
name,
|
|
username,
|
|
email,
|
|
avatarUrl: avatar_url,
|
|
groups,
|
|
isAdmin: is_admin,
|
|
createdAt: created_at,
|
|
stats,
|
|
authentikAccountUrl: authentikAccountUrl(),
|
|
});
|
|
})
|
|
);
|
|
|
|
module.exports = router;
|