mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2026-05-07 13:09:08 -05:00
WIP: Plex Auth Form
This commit is contained in:
@@ -20,6 +20,9 @@ module.exports = {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
},
|
||||
plexToken: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
|
||||
@@ -6,6 +6,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
lastName: DataTypes.STRING,
|
||||
googleId: DataTypes.STRING,
|
||||
email: {type: DataTypes.STRING, unique: true},
|
||||
plexToken: DataTypes.STRING,
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user