crisp-im / crisp-sdk-web

:package: Include the Crisp chat widget from using frameworks such as React, VueJS, Angular...
https://www.npmjs.com/package/crisp-sdk-web
MIT License
40 stars 15 forks source link

Session reset and tokenId set not consistent #32

Open ryancrunchi opened 8 months ago

ryancrunchi commented 8 months ago

Hello,

Here are some tests related to issues I faced mostly with session reset, session loading and token id setting. The result seem not logical to me but maybe I use the sdk wrong. The sdk functions called (or onLoaded callback) are given at each steps:

Step 1: anonymous user not connected

Crisp.configure(xxx, { locale: 'fr', autoload: false })
Crisp.load()
=> Crisp.session.onLoaded(session_1)

Step 2: login as userA

Crisp.setTokenId(userA)

Step 3: logout, now anonymous again

Crisp.session.reset()
=> Crisp.session.onLoaded(session_2)

Step 4: page reload, still anonymous

Crisp.configure(xxx, { locale: 'fr', autoload: false })
Crisp.load()
=> Crisp.session.onLoaded(session_2)

Step 5: login as userB

Crisp.setTokenId(userB)

Step 6: page reload as userB

Crisp.configure(xxx, { locale: 'fr', autoload: false })
Crisp.setTokenId(userB)
Crisp.load()
=> Crisp.session.onLoaded(session_3)

Step 7: logout, now anonymous again

Crisp.session.reset()
=> Crisp.session.onLoaded(session_3)

Step 8: page reload as anonymous

Crisp.configure(xxx, { locale: 'fr', autoload: false })
Crisp.load()
=> Crisp.session.onLoaded(session_3)
lebaudantoine commented 2 months ago

According to their documentation, you should run the following to properly reset the session:

function userLogout() {
  // Execute this sequence when your users are logging out
  Crisp.setTokenId(); // 1. Clear the token value
  Crisp.session.reset(); // 2. Unbind the current session
}

It's somewhat misleading that the reset method does not clear the token ID associated with the session. I fell into this trap myself.

reference