Is this Mini Program login and authorization process feasible?

when developing Mini Program for the first time, Wechat did not notice that Wechat canceled the pop-up window prompt for wx.getUserInfo, resulting in a change in the logic of user authorization (user profile picture, nickname and other information, non-login) in the project. I see that the current mainstream practice is to add an authorization page specially for , and log in < / button > with < button open-type= "getUserInfo" bindgetuserinfo= "bindGetUserInfo" > authorization . But this kind of experience is very bad. You need to jump to this authorization page and then pop up the window to re-authorize. You do not want to add this authorization page in the project. but directly prompt the user to authorize when authorization is needed. So I would like to use the following logic. is mainly sent out to ask you if you can pass the audit if you do so?

my general idea is this:

in the onLaunch of app.js, wx.login first obtains the openid, backend to query whether it has been authorized according to openid, and returns information such as flag (used to determine whether it has been authorized in subsequent wxml) and token. For example, if there is a button, in wxml that needs to be authorized according to authorization, the different button, operations are as follows:

<button wx:if="{{flag}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo"></button>
<button wx:else bindtap="buy"></button >

is to display different buttons according to flag. In this way, you can use open-type= "getUserInfo" pop-up window to authorize if you are not authorized. There is no need to add a new authorization page. When the user agrees to authorize, update the corresponding openid profile picture, nickname and other information and foreground data information in the background, such as updating flag

.

-end of thought-

searching on the Internet, including experiencing several well-known Mini Program, is the practice of adding new authorization pages. I wonder if I can pass the examination if I do so?

Jul.08,2021

Yes. When I do this, I add a check to the backend to determine whether to get the basic information of the user. The token check in app.js for the first time will be executed, and the user's code will be passed to the backend to obtain the user's openid (this is the core information of the user without the user id), but the backend already has it.

Menu