From 46420d4f15f4589d6023bf93919c8b22ae9553cf Mon Sep 17 00:00:00 2001 From: kristian Date: Sat, 10 Sep 2022 22:04:17 -0700 Subject: [PATCH] Stop checking users once match is found. --- src/utils/Auth.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/Auth.js b/src/utils/Auth.js index 078fd303..a57290bd 100644 --- a/src/utils/Auth.js +++ b/src/utils/Auth.js @@ -54,20 +54,20 @@ const generateUserToken = (user) => { */ export const isLoggedIn = () => { const users = getUsers(); - let userAuthenticated = false; - document.cookie.split(';').forEach((cookie) => { + let userAuthenticated = document.cookie.split(';').some((cookie) => { if (cookie && cookie.split('=').length > 1) { const cookieKey = cookie.split('=')[0].trim(); const cookieValue = cookie.split('=')[1].trim(); if (cookieKey === cookieKeys.AUTH_TOKEN) { - users.forEach((user) => { + userAuthenticated = users.some((user) => { if (generateUserToken(user) === cookieValue) { - userAuthenticated = true; localStorage.setItem(localStorageKeys.USERNAME, user.user); - } + return true; + } else return false; }); - } - } + return userAuthenticated; + } else return false; + } else return false; }); return userAuthenticated; };