fix(api): handle auth for accounts where the plex id may have been set to null (#3125)

also made some changes to hopefully alleviate this issue from happening at all in the future
This commit is contained in:
Ryan Cohen
2022-11-20 19:07:32 +09:00
committed by GitHub
parent 07ec3efbca
commit 15e246929b
2 changed files with 18 additions and 3 deletions

View File

@@ -64,13 +64,28 @@ authRoutes.post('/plex', async (req, res, next) => {
await userRepository.save(user);
} else {
const mainUser = await userRepository.findOneOrFail({
select: { id: true, plexToken: true, plexId: true },
select: { id: true, plexToken: true, plexId: true, email: true },
where: { id: 1 },
});
const mainPlexTv = new PlexTvAPI(mainUser.plexToken ?? '');
if (!account.id) {
logger.error('Plex ID was missing from Plex.tv response', {
label: 'API',
ip: req.ip,
email: account.email,
plexUsername: account.username,
});
return next({
status: 500,
message: 'Something went wrong. Try again.',
});
}
if (
account.id === mainUser.plexId ||
(account.email === mainUser.email && !mainUser.plexId) ||
(await mainPlexTv.checkUserAccess(account.id))
) {
if (user) {