Created
August 3, 2023 06:57
-
-
Save d22/852da26fc7fdcbf9a7df86a1fea8967e to your computer and use it in GitHub Desktop.
"Force" Login in Primo VE: Trigger Login modal and remove cancel button if not logged in
This file contains 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
// hook for module: | |
// prm-user-area-expandable-after | |
// | |
export class forceLoginController { | |
constructor(jwtHelper) { | |
this.jwtHelper = jwtHelper | |
} | |
$onInit() { | |
this.parentCtrl = this.afterCtrl.parentCtrl | |
if (this.isGuest()) { | |
this.parentCtrl.handleLogin() | |
} | |
} | |
isGuest() { | |
if (!sessionStorage) { | |
return null | |
} | |
const jwt = sessionStorage.getItem('primoExploreJwt') | |
if (jwt == null) { | |
return true | |
} | |
const decodedToken = this.jwtHelper.decodeToken(jwt) | |
if (decodedToken == null) { | |
return true | |
} | |
const userName = decodedToken.userGroup !== 'GUEST' ? decodedToken.userName : '' | |
if (userName) { | |
return false | |
} | |
else { | |
return true | |
} | |
} | |
} | |
forceLoginController.$inject = ['jwtHelper'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment