+
-
-
-
- );
+
+ );
+ }
}
}
diff --git a/client/src/components/Hero.js b/client/src/components/Hero.js
index 61dc0b7..cbcb6d2 100644
--- a/client/src/components/Hero.js
+++ b/client/src/components/Hero.js
@@ -37,10 +37,10 @@ class Hero extends Component {
- live_tvSign In
+ live_tvGet Started
diff --git a/client/src/reducers/authReducer.js b/client/src/reducers/authReducer.js
index afaec93..90f1903 100644
--- a/client/src/reducers/authReducer.js
+++ b/client/src/reducers/authReducer.js
@@ -1,6 +1,6 @@
import {FETCH_USER} from '../actions/types';
-export default function(state = {}, action) {
+export default function(state = false, action) {
switch (action.type) {
case FETCH_USER:
return action.payload || false;
diff --git a/client/src/reducers/plexReducer.js b/client/src/reducers/plexReducer.js
new file mode 100644
index 0000000..0d7600a
--- /dev/null
+++ b/client/src/reducers/plexReducer.js
@@ -0,0 +1,10 @@
+import {FETCH_PLEX_TOKEN} from '../actions/types';
+
+export default function(state = '', action) {
+ switch (action.type) {
+ case FETCH_PLEX_TOKEN:
+ return action.payload || false;
+ default:
+ return state;
+ }
+}
diff --git a/config/plex.js b/config/plex.js
index 2bd70f1..6864ce6 100644
--- a/config/plex.js
+++ b/config/plex.js
@@ -1,6 +1,6 @@
const plexConfig = {
ip: 'http://192.168.0.44',
- plexServerUrl: 'https://plex.mjrflix.com',
+ plexUrl: 'https://plex.mjrflix.com',
plexApiUrl: 'https://plex.tv/api',
token: process.env.PLEX_API_TOKEN,
};
diff --git a/server/controllers/plex.controller.js b/server/controllers/plex.controller.js
index 79ce303..146cc23 100644
--- a/server/controllers/plex.controller.js
+++ b/server/controllers/plex.controller.js
@@ -3,7 +3,7 @@ import plexService from '../services/plex';
const router = Router();
-router.get('/auth', plexService.getAuthToken);
+router.get('/token', plexService.getAuthToken);
router.get('/users', plexService.getUsers);
diff --git a/server/db/migrations/20190224043920-create-user.js b/server/db/migrations/20190224043920-create-user.js
index 7d84440..0fa9d07 100644
--- a/server/db/migrations/20190224043920-create-user.js
+++ b/server/db/migrations/20190224043920-create-user.js
@@ -20,7 +20,7 @@ module.exports = {
type: Sequelize.STRING,
unique: true,
},
- plexServerUrl: {
+ plexUrl: {
type: Sequelize.STRING,
},
plexToken: {
diff --git a/server/db/models/user.js b/server/db/models/user.js
index 1b9ea2c..f72a17a 100644
--- a/server/db/models/user.js
+++ b/server/db/models/user.js
@@ -6,7 +6,7 @@ module.exports = (sequelize, DataTypes) => {
lastName: DataTypes.STRING,
googleId: DataTypes.STRING,
email: {type: DataTypes.STRING, unique: true},
- plexServerUrl: DataTypes.STRING,
+ plexUrl: DataTypes.STRING,
plexToken: DataTypes.STRING,
},
{},
diff --git a/server/services/plex/auth.js b/server/services/plex/auth.js
index a5a1cff..d3b6023 100644
--- a/server/services/plex/auth.js
+++ b/server/services/plex/auth.js
@@ -18,9 +18,13 @@ const encryptUserCreds = (username, password) => {
};
const fetchToken = async (username, password) => {
- const res = await request.post(urlParams(username, password));
- const token = res.match(rxAuthToken)[1];
- return token;
+ try {
+ const res = await request.post(urlParams(username, password));
+ const token = res.match(rxAuthToken)[1];
+ return token;
+ } catch (error) {
+ return error.message;
+ }
};
export default fetchToken;
diff --git a/server/services/plex/index.js b/server/services/plex/index.js
index 9dd9573..9b82666 100644
--- a/server/services/plex/index.js
+++ b/server/services/plex/index.js
@@ -1,16 +1,25 @@
import plexApi from './plexApi';
import importData from './importData';
import auth from './auth';
+import models from '../../db/models';
import helpers from '../helpers';
const getAuthToken = async (req, res) => {
- const {username} = req.query;
- const {password} = req.query;
- console.log('Mikes stuff', username, password);
- const token = await auth(username, password);
- // req.user.plexToken = token;
- // const user = await req.user.save();
- return res.json(token);
+ try {
+ const {email, password, plexUrl} = req.query;
+ const plexToken = await auth(email, password);
+ const [rowsUpdate, updatedUser] = await models.User.update(
+ {plexUrl, plexToken},
+ {returning: true, where: {googleId: req.user.googleId}},
+ );
+ console.log('updatedUser', updatedUser);
+ console.log('token', plexToken);
+
+ return res.json(updatedUser);
+ } catch (error) {
+ console.log(error.message);
+ return res.status(201).json(error.message);
+ }
};
const getUsers = (req, res) => {
diff --git a/server/services/plex/plexApi.js b/server/services/plex/plexApi.js
index 3828d44..7319966 100644
--- a/server/services/plex/plexApi.js
+++ b/server/services/plex/plexApi.js
@@ -13,7 +13,7 @@ const getUsersUrlParams = function(token) {
const getSectionsUrlParams = function() {
return {
- host: config.plex.plexServerUrl,
+ host: config.plex.plexUrl,
path: '/library/sections',
queryParams: {
'X-Plex-Token': config.plex.token,
@@ -23,7 +23,7 @@ const getSectionsUrlParams = function() {
const mostWatchedUrlParams = function(accountId, sectionKey, limit = 10) {
return {
- host: config.plex.plexServerUrl,
+ host: config.plex.plexUrl,
path: '/library/all/top',
queryParams: {
...(accountId && {accountId}),
@@ -36,7 +36,7 @@ const mostWatchedUrlParams = function(accountId, sectionKey, limit = 10) {
const getLibraryDataBySectionUrlParams = function(sectionId) {
return {
- host: config.plex.plexServerUrl,
+ host: config.plex.plexUrl,
path: `/library/sections/${sectionId}/all`,
queryParams: {
'X-Plex-Token': config.plex.token,