JHipster programatically login using cypress and JWT

The trick is to use quotation marks around token itself. Here is example how you can authenticate when JWT is used in your JHipster application

function login(username: string, password: string): void {
  cy.request('POST', '/api/authenticate', {
    username: username,
    password: password
  })
    .its('body')
    .then((res) => {
      window.sessionStorage.setItem('jhi-authenticationtoken', '"' + res.id_token + '"');
    })
}

You can find live example here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top