fix(plex): Check Plex server access on user import (#955)

pull/965/head
TheCatLady 4 years ago committed by GitHub
parent bddea7ab24
commit bdb3cb2025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -212,7 +212,7 @@ class PlexTvAPI {
return parsedXml;
}
public async checkUserAccess(authUser: PlexUser): Promise<boolean> {
public async checkUserAccess(userId: number): Promise<boolean> {
const settings = getSettings();
try {
@ -224,11 +224,11 @@ class PlexTvAPI {
const users = friends.MediaContainer.User;
const user = users.find((u) => Number(u.$.id) === authUser.id);
const user = users.find((u) => Number(u.$.id) === userId);
if (!user) {
throw new Error(
'This user does not exist on the main plex accounts shared list'
"This user does not exist on the main Plex account's shared list"
);
}

@ -87,7 +87,7 @@ authRoutes.post('/login', async (req, res, next) => {
});
const mainPlexTv = new PlexTvAPI(mainUser.plexToken ?? '');
if (await mainPlexTv.checkUserAccess(account)) {
if (await mainPlexTv.checkUserAccess(account.id)) {
user = new User({
email: account.email,
plexUsername: account.username,

@ -333,7 +333,11 @@ router.post(
await userRepository.save(user);
} else {
// Check to make sure it's a real account
if (account.email && account.username) {
if (
account.email &&
account.username &&
(await mainPlexTv.checkUserAccess(Number(account.id)))
) {
const newUser = new User({
plexUsername: account.username,
email: account.email,

Loading…
Cancel
Save