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
pull/3139/head
Ryan Cohen 2 years ago committed by GitHub
parent 07ec3efbca
commit 15e246929b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,7 +39,7 @@ export class User {
return users.map((u) => u.filter(showFiltered)); return users.map((u) => u.filter(showFiltered));
} }
static readonly filteredFields: string[] = ['email']; static readonly filteredFields: string[] = ['email', 'plexId'];
public displayName: string; public displayName: string;
@ -73,7 +73,7 @@ export class User {
@Column({ type: 'integer', default: UserType.PLEX }) @Column({ type: 'integer', default: UserType.PLEX })
public userType: UserType; public userType: UserType;
@Column({ nullable: true, select: false }) @Column({ nullable: true, select: true })
public plexId?: number; public plexId?: number;
@Column({ nullable: true, select: false }) @Column({ nullable: true, select: false })

@ -64,13 +64,28 @@ authRoutes.post('/plex', async (req, res, next) => {
await userRepository.save(user); await userRepository.save(user);
} else { } else {
const mainUser = await userRepository.findOneOrFail({ const mainUser = await userRepository.findOneOrFail({
select: { id: true, plexToken: true, plexId: true }, select: { id: true, plexToken: true, plexId: true, email: true },
where: { id: 1 }, where: { id: 1 },
}); });
const mainPlexTv = new PlexTvAPI(mainUser.plexToken ?? ''); 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 ( if (
account.id === mainUser.plexId || account.id === mainUser.plexId ||
(account.email === mainUser.email && !mainUser.plexId) ||
(await mainPlexTv.checkUserAccess(account.id)) (await mainPlexTv.checkUserAccess(account.id))
) { ) {
if (user) { if (user) {

Loading…
Cancel
Save