Settings System (#46)

* feat(api): settings system

Also includes /auth/me endpoint for ticket ch76 and OpenAPI 3.0 compatibility for ch77

* refactor(api): remove unused imports
This commit is contained in:
sct
2020-09-03 19:17:15 +09:00
committed by GitHub
parent af95c2fb47
commit 5d46f8d76d
17 changed files with 1076 additions and 31 deletions

View File

@@ -2,9 +2,26 @@ import { Router } from 'express';
import { getRepository } from 'typeorm';
import { User } from '../entity/User';
import PlexTvAPI from '../api/plextv';
import { isAuthenticated } from '../middleware/auth';
const authRoutes = Router();
authRoutes.get('/me', isAuthenticated, async (req, res) => {
const userRepository = getRepository(User);
if (!req.user) {
return res.status(500).json({
status: 500,
error:
'Requsted user endpoint withuot valid authenticated user in session',
});
}
const user = await userRepository.findOneOrFail({
where: { id: req.user.id },
});
return res.status(200).json(user.filter());
});
authRoutes.post('/login', async (req, res) => {
const userRepository = getRepository(User);
const body = req.body as { authToken?: string };