debug: silenceAuth 增加成功/失败响应日志,验证新用户 openid 获取
This commit is contained in:
12
App.vue
12
App.vue
@@ -108,16 +108,20 @@
|
||||
// #endif
|
||||
// #ifdef MP
|
||||
// 小程序静默授权
|
||||
console.log('[auth-flow] App onLaunch: isLogin=' + this.$store.getters.isLogin + ', expired=' + this.getExpired());
|
||||
if (!this.$store.getters.isLogin) {
|
||||
Routine.getCode().then(code => {
|
||||
console.log('[auth-flow] App onLaunch: wx.login 拿到 code=' + (code ? code.substring(0, 10) + '...' : '(空)'));
|
||||
this.silenceAuth(code);
|
||||
}).catch(res => {
|
||||
console.warn('[auth-flow] App onLaunch: wx.login 失败', res);
|
||||
uni.hideLoading();
|
||||
});
|
||||
}else if(this.$store.getters.isLogin && this.getExpired()){
|
||||
//处理小程序有token情况下但是静默授权失败
|
||||
this.$Cache.clear(LOGIN_STATUS);
|
||||
Routine.getCode().then(code => {
|
||||
console.log('[auth-flow] App onLaunch: token过期,重新静默授权 code=' + (code ? code.substring(0, 10) + '...' : '(空)'));
|
||||
this.silenceAuth(code);
|
||||
})
|
||||
}
|
||||
@@ -222,12 +226,14 @@
|
||||
silenceAuth(code) {
|
||||
let that = this;
|
||||
let spid = that.globalData.spid ? that.globalData.spid : '';
|
||||
console.log('[auth-flow] silenceAuth 发起, code=' + (code ? code.substring(0, 10) + '...' : '(空)'));
|
||||
silenceAuth({
|
||||
code: code,
|
||||
spread_spid: spid,
|
||||
spread_code: that.globalData.code
|
||||
})
|
||||
.then(res => {
|
||||
console.log('[auth-flow] silenceAuth 响应:', JSON.stringify(res.data || res).substring(0, 200));
|
||||
if (res.data.token !== undefined && res.data.token) {
|
||||
uni.hideLoading();
|
||||
let time = res.data.expires_time - this.$Cache.time();
|
||||
@@ -237,10 +243,14 @@
|
||||
});
|
||||
that.$store.commit('SETUID', res.data.userInfo.uid);
|
||||
that.$store.commit('UPDATE_USERINFO', res.data.userInfo);
|
||||
console.log('[auth-flow] ✅ silenceAuth 成功, token 已存 store (含 openid)');
|
||||
} else {
|
||||
console.warn('[auth-flow] ⚠️ silenceAuth 返回无 token:', JSON.stringify(res.data || res).substring(0, 200));
|
||||
}
|
||||
}).catch(err => {
|
||||
console.warn('[auth-flow] ❌ silenceAuth 失败:', JSON.stringify(err).substring(0, 300));
|
||||
return that.$util.Tips({
|
||||
title:err
|
||||
title: err
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user