Applet authorized user personal information flow

Questions from the applet community

Quickly switching tabs causes wx.getSetting to not get the authorized information

Business scene

Our authorization process is: let the user authorize the user's basic information when the user enters the applet. Although the mini program official recommends that you need to authorize the user when you need the user's nickname, avatar and other information.

Authorization changes

Since the applet changed the basic information of authorized users to be called only by buttons, in the development of this applet, we customized an authorization box (Figure 1), through the [click authorization] button on the box Go to the WeChat authorization box (Figure 2).

Custom authorization bullet box:

clipboard.png

WeChat authorization box:

clipboard.png

achieve

Option 1 : Call wx.getSetting in the onShow of the tabbar page and the page with sharing function to determine whether it has been authorized. If it has been authorized, hide the custom authorization bullet box; otherwise, display the custom authorization bullet box. code show as below:

Mini program fragment 1 : wechatide: // minicode / a1GSyHmP7o10

Existing problem : when the user information is already authorized, quickly switching tabs will cause res.authSetting ['scope.userInfo'] returned by wx.getSetting to be empty, resulting in the display of a custom authorization popup. But at this time, clicking the [click authorization] button in the custom authorization cannot call up the WeChat authorization dialog box, because it has been authorized before. The guess is because of frequent calls to wx.getSetting.

Option 2 : Call wx.getSetting in the onLoad of the tabbar page, which avoids frequent calls to wx.getSetting when switching tabbars. Then, whether the authorized information (authInfoDlg) exists globally, in the onShow of the tabbar page, determine whether to display the custom authorization bullet box according to authInfoDlg. code show as below:

Mini program fragment 2 : wechatide: // minicode / N4Yz4WmK7W43

Guess you like

Origin www.cnblogs.com/jlfw/p/12707043.html