hookehuyr

feat(auth): 添加静默授权处理逻辑作为授权重定向的优先方案

当用户未授权时,优先尝试静默授权,仅在失败或异常时跳转授权页面
/*
* @Date: 2025-01-25 10:00:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-12 12:24:03
* @LastEditTime: 2025-09-12 21:32:12
* @FilePath: /lls_program/src/utils/authRedirect.js
* @Description: 授权重定向处理工具函数
*/
......@@ -171,17 +171,37 @@ export const handleSharePageAuth = async (options, callback) => {
const sessionid = wx.getStorageSync('sessionid')
if (!sessionid) {
// 没有授权,需要先授权
// 没有授权,使用静默授权
if (isFromShare(options)) {
// 来自分享,保存当前页面路径用于授权后返回
saveCurrentPagePath()
}
// 跳转到授权页面
Taro.navigateTo({
url: '/pages/auth/index'
})
return false
try {
// 使用静默授权
await silentAuth(
() => {
// 静默授权成功
if (callback && typeof callback === 'function') {
callback()
}
},
() => {
// 静默授权失败时,仍然跳转到授权页面作为备选方案
Taro.navigateTo({
url: '/pages/auth/index'
})
}
)
return true
} catch (error) {
console.error('静默授权异常:', error)
// 发生异常时,跳转到授权页面作为备选方案
Taro.navigateTo({
url: '/pages/auth/index'
})
return false
}
}
// 已授权,执行回调
......