Question:

  • When USER A logs in to the APP and browses the embedded H5 page, his account is suddenly logged in by user B.

  • When user A’s mobile phone continues to browse the request interface, the backend displays an invalid login message. Please log in again.

  • Jump to the login page of APP, and return to the page of H5 after successful login without requesting the interface again to obtain data

Solutions:

H5 page and APP are generally connected through jsBridge. After successful login, APP will transfer token to H5 page through jsBridge. So when we receive the token, we decide whether to make the page reload.

Note: the token must be stored in cookie or localStorage to prevent the token from being lost after refreshing and falling into an infinite loop

Code logic:

// The token is sent by jsBridge, and the token is sent by busif(data.tag === LoginTag){
    if(data.data){
      bus.$emit('login'.true// pass token}else{
      bus.$emit('login'.false// No token was passed}} // Then check bus in app. vue create method.$on('login', (login) => {
      if(login) { location.reload(); }})Copy the code

Completion of the ~