Permission System (#47)

* feat(api): permissions system

Adds a permission system for isAuthenticated middleware. Also adds user CRUD.
This commit is contained in:
sct
2020-09-03 19:20:14 +09:00
committed by GitHub
parent 5d46f8d76d
commit cfc84ce2f3
8 changed files with 240 additions and 20 deletions

View File

@@ -3,10 +3,11 @@ import { getRepository } from 'typeorm';
import { User } from '../entity/User';
import PlexTvAPI from '../api/plextv';
import { isAuthenticated } from '../middleware/auth';
import { Permission } from '../lib/permissions';
const authRoutes = Router();
authRoutes.get('/me', isAuthenticated, async (req, res) => {
authRoutes.get('/me', isAuthenticated(), async (req, res) => {
const userRepository = getRepository(User);
if (!req.user) {
return res.status(500).json({
@@ -54,7 +55,7 @@ authRoutes.post('/login', async (req, res) => {
user = new User({
email: account.email,
plexToken: account.authToken,
// TODO: When we add permissions in #52, set admin here
permissions: Permission.ADMIN,
});
await userRepository.save(user);
}