Skip to content

Commit

Permalink
fix(auth): fix admin check in case of non-home users (#213)
Browse files Browse the repository at this point in the history
resolves #212
  • Loading branch information
RaunoT authored Aug 6, 2024
1 parent 49f566c commit 7a23a64
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ export const authOptions: AuthOptions = {
const xmlData = await res.text()
const jsonData = await parseStringPromise(xmlData)
const data = jsonData.user.$
const { title, id, thumb, email, homeAdmin, homeSize } = data
const { title, id, thumb, email } = data
const userData = {
id: id,
name: title,
email: email,
image: thumb,
isAdmin: homeAdmin === '1' || homeSize === '1',
isAdmin: false,
}
console.log('[AUTH] - User logged in with data:', userData)

if (res.ok && userData) {
const checkUserRes = await fetchTautulli<TautulliUser>('get_user', {
Expand All @@ -74,8 +73,12 @@ export const authOptions: AuthOptions = {
const checkUser = checkUserRes?.response?.data
const userValid =
checkUser?.email === userData.email && checkUser?.is_active
const userAdmin = checkUser?.is_admin === 1

if (userValid) {
userData.isAdmin = userAdmin
console.log('[AUTH] - User logged in with data:', userData)

return userData
} else {
console.error('[AUTH] - User does not belong to this server!')
Expand Down

0 comments on commit 7a23a64

Please sign in to comment.