Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
lls_program
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-09-12 21:33:01 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3ae31444184226c49038c1639952a20e025d433d
3ae31444
1 parent
7ed009f1
feat(auth): 添加静默授权处理逻辑作为授权重定向的优先方案
当用户未授权时,优先尝试静默授权,仅在失败或异常时跳转授权页面
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
7 deletions
src/utils/authRedirect.js
src/utils/authRedirect.js
View file @
3ae3144
/*
* @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
}
}
// 已授权,执行回调
...
...
Please
register
or
login
to post a comment