Skip to content

Commit

Permalink
Refactor LoginChecker component to improve user permission handling a…
Browse files Browse the repository at this point in the history
…nd redirection logic
  • Loading branch information
Adammatthiesen committed Dec 22, 2024
1 parent 2955238 commit b4202fc
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,30 @@ const isAuthorized = await verifyUserPermissionLevel(user, requiredPermission);
style="display: hidden;"
></login-check>

<script>
<script is:inline>
if (!customElements.get('login-check')) {
class LoginCheck extends HTMLElement {
constructor() {
super();
const authorized = this.dataset.authorized!;
const isLoggedIn = this.dataset.is_logged_in!;
const redirectProfile = this.dataset.redirect_profile!;
const redirectLogin = this.dataset.redirect_login!;
const authorized = this.dataset.authorized;
const isLoggedIn = this.dataset.is_logged_in;
const redirectProfile = this.dataset.redirect_profile;
const redirectLogin = this.dataset.redirect_login;

console.log('Checking user permissions and login status');

if (isLoggedIn === 'false') {
console.log('redirecting to login');
window.location.href = redirectLogin;
}

if (window.location.pathname === redirectProfile) {
console.log('User is on profile page');
return;
}

if (authorized === 'false') {
console.log('redirecting to profile');
window.location.href = redirectProfile;
}
}
Expand Down

0 comments on commit b4202fc

Please sign in to comment.