WIP: Plex Auth Form

This commit is contained in:
mjrode
2019-03-31 22:25:40 -05:00
parent 17b1f579ea
commit 9670b4329b
12 changed files with 112 additions and 28 deletions
@@ -20,6 +20,9 @@ module.exports = {
type: Sequelize.STRING,
unique: true,
},
plexToken: {
type: Sequelize.STRING,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
+1
View File
@@ -6,6 +6,7 @@ module.exports = (sequelize, DataTypes) => {
lastName: DataTypes.STRING,
googleId: DataTypes.STRING,
email: {type: DataTypes.STRING, unique: true},
plexToken: DataTypes.STRING,
},
{},
);
+5 -4
View File
@@ -7,14 +7,15 @@ const getAuthToken = async (req, res) => {
const {username} = req.query;
const {password} = req.query;
auth(username, password).then(data => {
return res.json(data);
});
const token = await auth(username, password);
req.user.plexToken = token;
const user = await req.user.save();
return res.json(user);
};
const getUsers = (req, res) => {
plexApi
.getUsers()
.getUsers(req.user.plexToken)
.then(users => {
res.json(users);
})
+4 -4
View File
@@ -1,12 +1,12 @@
import config from '../../../config';
import helpers from '../helpers';
const getUsersUrlParams = function() {
const getUsersUrlParams = function(token) {
return {
host: config.plex.plexApiUrl,
path: '/users',
queryParams: {
'X-Plex-Token': config.plex.token,
'X-Plex-Token': config.plex.token || token,
},
};
};
@@ -44,9 +44,9 @@ const getLibraryDataBySectionUrlParams = function(sectionId) {
};
};
const getUsers = async function() {
const getUsers = async function(token) {
try {
const urlParams = getUsersUrlParams();
const urlParams = getUsersUrlParams(token);
const getUsersUrl = helpers.buildUrl(urlParams);
const response = await helpers.request(getUsersUrl);
return response.MediaContainer.User;