当前位置:网站首页>Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value

Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value

2022-06-26 13:26:00 woowen!

Problem flow description :

In general , Whenever a user chooses to log out , The code will store the already saved token Values or other data are cleared . When you log in again, you can store the new token value .

But if the code does not include the original token kill , Instead, choose to replace the old value with the new value , There will be a magical bug:

use wx.getStorageSync take token when , Will take the old one token value , Have you ever encountered such a problem ?

Of course, I don't think this is very reasonable , After all, after logging out , You should clean up the old data , The above is just a question for me , Here is the question record


what

Why is that ?

Every time a user logs in, they change token value

But if you log in , Not cleared token, Instead, replace it with a new one token, When you jump to a web page outside the applet , Value token It will be the last time token!!! What's going on here

//  Approval progress 
import api from '../../apis/api'
import config from './../../config/config'
Page({
  data: {
    env: config.env == 'test' ? 'https://test-trading.linkingjz.com/#/mobileBpmn' : 'https://trade.linkingjz.com/#/mobileBpmn',
    url: '',
    paramsToken: '',
    paramsUserId: ''
  },

  onLoad(option) {
    let _this = this
    new Promise((resolve) => {
      _this.setData({
        paramsToken: wx.getStorageSync(config.USER_TOKEN),
        paramsUserId: wx.getStorageSync(config.USER_ID)
      })
      resolve()
    }).then(res => {
      this.handlerInit(option)
    })
  },
  /** ------------------------------------------- Method --------------------------------------------- */
  //  Initialize page data 
  handlerInit(option) {
    console.log(option)
    this.setData({
      url: `${this.data.env}/${option.pid}/${option.businessId}/${option.type}?token=${this.data.paramsToken}&userId=${this.data.paramsUserId}&nickname=''`
    }, function () {
      console.log(this.data.url)
    })
  },
})

If you have any ideas, please leave a message

原网站

版权声明
本文为[woowen!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170514022924.html