Skip to content

Conversation

Aschen
Copy link
Contributor

@Aschen Aschen commented Apr 27, 2020

What does this PR do?

Since we use the error code it's better to rely on the error id instead of the message.
The error message when the token has expired has changed and so the corresponding event was not trigger anymore.

This PR fix this by using the error id instead.

How should this be manually tested?

const {
  Kuzzle,
  Http
} = require('./index')

const kuzzle = new Kuzzle(new Http('localhost'))

kuzzle.on('networkError', console.error);

kuzzle.on('tokenExpired', () => {
  console.log('Expired')
});
(async () => {
  await kuzzle.connect()

  await kuzzle.security.createUser('admin', {
    content: { profileIds: [ 'default' ] },
    credentials: { local: { username: 'admin', password: 'admin' } }
  });
  await kuzzle.auth.login('local', { username: 'admin', password: 'admin' }, '2s')

  setTimeout(async () => {
    try {
      await kuzzle.server.now()

    }
    catch (error) {
      console.log(error)
    }
  }, 3000)
})();

Other changes

  • use tokenExpired event in Realtime and Auth controller instead of directly calling the methods from Kuzzle object

@Aschen Aschen self-assigned this Apr 27, 2020
@Aschen Aschen changed the base branch from master to 7-dev April 27, 2020 10:47
@codecov
Copy link

codecov bot commented Apr 27, 2020

Codecov Report

Merging #512 into 7-dev will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##            7-dev     #512   +/-   ##
=======================================
  Coverage   95.81%   95.82%           
=======================================
  Files          32       32           
  Lines        1315     1316    +1     
=======================================
+ Hits         1260     1261    +1     
  Misses         55       55           
Impacted Files Coverage Δ
src/Kuzzle.js 93.91% <ø> (-0.06%) ⬇️
src/controllers/Auth.js 93.75% <100.00%> (+0.20%) ⬆️
src/controllers/Realtime.js 97.82% <100.00%> (+0.04%) ⬆️
src/protocols/abstract/Base.js 94.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65b526e...46e4379. Read the comment docs.

@Aschen Aschen merged commit 0f8d1ed into 7-dev Apr 28, 2020
@Aschen Aschen deleted the fix-token-expired branch April 28, 2020 11:53
@Aschen Aschen mentioned this pull request Apr 28, 2020
Aschen added a commit that referenced this pull request Apr 28, 2020
# [7.2.0](https://github.com/kuzzleio/sdk-javascript/releases/tag/7.2.0) (2020-04-28)


#### Bug fixes

- [ [#508](#508) ] Fix SearchResult.next with sort/size   ([Aschen](https://github.com/Aschen))
- [ [#512](#512) ] Fix token expired   ([Aschen](https://github.com/Aschen))
- [ [#511](#511) ] Avoid to mutate user options   ([Aschen](https://github.com/Aschen))
- [ [#507](#507) ] Fix collection getMapping   ([Aschen](https://github.com/Aschen))

#### New features

- [ [#510](#510) ] Add security:refresh   ([Yoann-Abbes](https://github.com/Yoann-Abbes))

#### Enhancements

- [ [#509](#509) ] Add the rate limit property to Profile objects   ([scottinet](https://github.com/scottinet))
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants