fix(auth): resolve local/password authentication issues (#2677)

* fix(auth): only add Plex ID to user after verifying server access

* fix(auth): do not fail local auth if fetching Plex users is unsuccessful
pull/2686/head
TheCatLady 3 years ago committed by GitHub
parent 341e3b8f06
commit b75fc7b238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -210,30 +210,43 @@ authRoutes.post('/local', async (req, res, next) => {
const mainPlexTv = new PlexTvAPI(mainUser.plexToken ?? ''); const mainPlexTv = new PlexTvAPI(mainUser.plexToken ?? '');
if (!user.plexId) { if (!user.plexId) {
const plexUsersResponse = await mainPlexTv.getUsers(); try {
const account = plexUsersResponse.MediaContainer.User.find( const plexUsersResponse = await mainPlexTv.getUsers();
(account) => const account = plexUsersResponse.MediaContainer.User.find(
account.$.email && (account) =>
account.$.email.toLowerCase() === user.email.toLowerCase() account.$.email &&
)?.$; account.$.email.toLowerCase() === user.email.toLowerCase()
)?.$;
if (account) {
logger.info('Found matching Plex user; updating user with Plex data', { if (
label: 'API', account &&
ip: req.ip, (await mainPlexTv.checkUserAccess(parseInt(account.id)))
email: body.email, ) {
userId: user.id, logger.info(
plexId: account.id, 'Found matching Plex user; updating user with Plex data',
plexUsername: account.username, {
}); label: 'API',
ip: req.ip,
email: body.email,
userId: user.id,
plexId: account.id,
plexUsername: account.username,
}
);
user.plexId = parseInt(account.id); user.plexId = parseInt(account.id);
user.avatar = account.thumb; user.avatar = account.thumb;
user.email = account.email; user.email = account.email;
user.plexUsername = account.username; user.plexUsername = account.username;
user.userType = UserType.PLEX; user.userType = UserType.PLEX;
await userRepository.save(user); await userRepository.save(user);
}
} catch (e) {
logger.error('Something went wrong fetching Plex users', {
label: 'API',
errorMessage: e.message,
});
} }
} }

Loading…
Cancel
Save