Skip to content

Commit

Permalink
Merge pull request #812 from cloud-pi-native/fix/endless-redirect-on-…
Browse files Browse the repository at this point in the history
…login

fix: 🐛 fix endless redirect on login if authenticated
  • Loading branch information
clairenollet authored Nov 12, 2023
2 parents 36235c1 + 461c6bd commit 1f4d94f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/client/cypress/e2e/specs/redirection.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ describe('Redirection', () => {
cy.should('contain', `Le projet courant est : ${project.name} (${organization.label})`)
})
})

it('Should redirect to home if trying to access login page while logged', () => {
cy.intercept('POST', '/realms/cloud-pi-native/protocol/openid-connect/token').as('postToken')
cy.intercept('GET', '/realms/cloud-pi-native/account').as('getAccount')

cy.visit('/login')
cy.url().should('not.contain', '/login')
cy.get('input#username').type('test')
cy.get('input#password').type('test')
cy.get('input#kc-login').click()
cy.wait('@postToken')
cy.url().should('contain', '/')
cy.get('h1').contains(' Cloud π Native ')
.should('exist')
})
})
5 changes: 5 additions & 0 deletions apps/client/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ router.beforeEach(async (to, _from, next) => {
return next('Login')
}

// Redirige sur l'accueil si le path est Login et que l'utilisateur est connecté
if (to.name === 'Login' && userStore.isLoggedIn) {
return next('/')
}

// Redirige sur la page d'accueil si le path est admin et l'utilisateur n'est pas admin
if (to.path.match('^/admin/') && !userStore.isAdmin) {
snackbarStore.setMessage('Vous ne possédez pas les droits administeurs', 'error')
Expand Down

0 comments on commit 1f4d94f

Please sign in to comment.