Skip to content

Commit

Permalink
Fix for logout issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Nov 27, 2024
1 parent 8d13d56 commit 3bb7775
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 6 additions & 5 deletions backend/src/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,28 @@ router.get('/login', passport.authenticate('oidc', {

//removes tokens and destroys session
router.get('/logout', async (req, res, next) => {
let primaryURL = config.get('logoutEndpoint') + '?post_logout_redirect_uri=' + config.get('server:frontend');
let idToken = req?.session?.passport?.user?.idToken;
if (req?.session?.passport?.user) {
if (idToken) {
req.logout(function(err) {
if (err) {
return next(err);
}
req.session.destroy();
let retUrl;
if (req.query && req.query.sessionExpired) {
retUrl = encodeURIComponent(config.get('logoutEndpoint') + '?post_logout_redirect_uri=' + config.get('server:frontend') + '/session-expired' + '&client_id=' + config.get('oidc:clientId'));
retUrl = encodeURIComponent(primaryURL + '/session-expired' + '&id_token_hint=' + idToken);
} else {
retUrl = encodeURIComponent(config.get('logoutEndpoint') + '?post_logout_redirect_uri=' + config.get('server:frontend') + '/logout' + '&id_token_hint=' + idToken);
retUrl = encodeURIComponent(primaryURL + '/logout' + '&id_token_hint=' + idToken);
}
res.redirect(config.get('siteMinder_logout_endpoint') + retUrl);
});
}else {
let retUrl;
if (req.query && req.query.sessionExpired) {
retUrl = encodeURIComponent(config.get('logoutEndpoint') + '?post_logout_redirect_uri=' + config.get('server:frontend') + '/session-expired' + '&client_id=' + config.get('oidc:clientId'));
retUrl = encodeURIComponent(primaryURL + '/session-expired' + '&client_id=' + config.get('oidc:clientId'));
} else {
retUrl = encodeURIComponent(config.get('logoutEndpoint') + '?post_logout_redirect_uri=' + config.get('server:frontend') + '/logout' + '&client_id=' + config.get('oidc:clientId'));
retUrl = encodeURIComponent(primaryURL + '/logout' + '&client_id=' + config.get('oidc:clientId'));
}
res.redirect(config.get('siteMinder_logout_endpoint') + retUrl);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Logout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</template>

<script>
import {Routes} from '../utils/constants';
import {Routes} from '@/utils/constants';
import {authStore} from '@/store/modules/auth';
export default {
Expand All @@ -56,7 +56,7 @@ export default {
},
created() {
const auStore = authStore();
auStore.setJwtToken();
auStore.logoutState();
},
methods: {
clearStorage() {
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/ModalIdle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export default {
},
async mounted() {
await this.checkAndLogoutUserOnSessionExpiry();
},
methods: {
async checkAndLogoutUserOnSessionExpiry() {
if (this.isAuthenticated) {
try {
Expand Down

0 comments on commit 3bb7775

Please sign in to comment.