Created
May 26, 2022 15:07
-
-
Save swahaniroy/43c33d391e7aec9e744e4119355699ad to your computer and use it in GitHub Desktop.
The Auth File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', function() { | |
function shouldRedirectToHomePage(user, isLoginPage) { | |
return user && isLoginPage; | |
} | |
function shouldRedirectToLoginPage(user, isLoginPage) { | |
return !user && !isLoginPage; | |
} | |
CometChatWidget.init({ | |
"appID": `${config.CometChatAppId}`, | |
"appRegion": `${config.CometChatRegion}`, | |
"authKey": `${config.CometChatAuthKey}` | |
}).then(response => { | |
CometChatWidget.CometChat.getLoggedinUser().then( | |
user => { | |
// check current page is the login page, or not. | |
const isLoginPage = window.location.href.includes('login'); | |
if(shouldRedirectToHomePage(user, isLoginPage)){ | |
window.location.href = '/'; | |
}else if(shouldRedirectToLoginPage(user, isLoginPage)) { | |
window.location.href = '/login.html'; | |
} | |
}, error => { | |
} | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment