Updated authentication middleware to handle checks consitenctly
This commit is contained in:
@@ -4,8 +4,8 @@ const establishedDatabase = require("../../database/database");
|
|||||||
const mustBeAdmin = (req, res, next) => {
|
const mustBeAdmin = (req, res, next) => {
|
||||||
const database = establishedDatabase;
|
const database = establishedDatabase;
|
||||||
|
|
||||||
if (req.loggedInUser === undefined) {
|
if (!req.loggedInUser) {
|
||||||
res.status(401).send({
|
return res.status(401).send({
|
||||||
success: false,
|
success: false,
|
||||||
message: "You must be logged in."
|
message: "You must be logged in."
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// eslint-disable-next-line consistent-return
|
// eslint-disable-next-line consistent-return
|
||||||
const mustBeAuthenticated = (req, res, next) => {
|
const mustBeAuthenticated = (req, res, next) => {
|
||||||
if (req.loggedInUser === undefined) {
|
if (!req.loggedInUser) {
|
||||||
return res.status(401).send({
|
return res.status(401).send({
|
||||||
success: false,
|
success: false,
|
||||||
message: "You must be logged in."
|
message: "You must be logged in."
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ const establishedDatabase = require("../../database/database");
|
|||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
const mustHaveAccountLinkedToPlex = (req, res, next) => {
|
const mustHaveAccountLinkedToPlex = (req, res, next) => {
|
||||||
const database = establishedDatabase;
|
const database = establishedDatabase;
|
||||||
const { loggedInUser } = req;
|
|
||||||
|
|
||||||
if (loggedInUser === null) {
|
// TODO use mustByAuthenticated middleware
|
||||||
|
if (!req.loggedInUser) {
|
||||||
return res.status(401).send({
|
return res.status(401).send({
|
||||||
success: false,
|
success: false,
|
||||||
message: "You must have your account linked to a plex account."
|
message: "You must have your account linked to a plex account."
|
||||||
@@ -15,7 +15,7 @@ const mustHaveAccountLinkedToPlex = (req, res, next) => {
|
|||||||
database
|
database
|
||||||
.get(
|
.get(
|
||||||
`SELECT plex_userid FROM settings WHERE user_name IS ?`,
|
`SELECT plex_userid FROM settings WHERE user_name IS ?`,
|
||||||
loggedInUser.username
|
req.loggedInUser.username
|
||||||
)
|
)
|
||||||
.then(row => {
|
.then(row => {
|
||||||
const plexUserId = row.plex_userid;
|
const plexUserId = row.plex_userid;
|
||||||
|
|||||||
Reference in New Issue
Block a user