Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeekLearnMathWeapp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
frontend
GeekLearnMathWeapp
Commits
a239337e
Commit
a239337e
authored
Apr 28, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: refresh token
parent
fa590a85
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
1 deletion
+22
-1
index.js
config/index.js
+1
-0
config-env.js
scripts/config-env.js
+7
-0
silent-login.ts
src/utils/silent-login.ts
+8
-0
storage.ts
src/utils/storage.ts
+6
-1
No files found.
config/index.js
View file @
a239337e
...
@@ -63,6 +63,7 @@ const config = {
...
@@ -63,6 +63,7 @@ const config = {
'process.env.DEV_SERVER'
:
JSON
.
stringify
(
process
.
env
.
DEV_SERVER
||
''
),
'process.env.DEV_SERVER'
:
JSON
.
stringify
(
process
.
env
.
DEV_SERVER
||
''
),
'process.env.SERVER_ENDPOINT'
:
JSON
.
stringify
(
process
.
env
.
SERVER_ENDPOINT
||
''
),
'process.env.SERVER_ENDPOINT'
:
JSON
.
stringify
(
process
.
env
.
SERVER_ENDPOINT
||
''
),
'process.env.TARO_STORAGE_KEY'
:
JSON
.
stringify
(
process
.
env
.
TARO_STORAGE_KEY
||
''
),
'process.env.TARO_STORAGE_KEY'
:
JSON
.
stringify
(
process
.
env
.
TARO_STORAGE_KEY
||
''
),
'process.env.TARO_REFRESH_TOKEN'
:
JSON
.
stringify
(
process
.
env
.
TARO_REFRESH_TOKEN
||
''
),
...
envMap
...
envMap
},
},
copy
:
{
copy
:
{
...
...
scripts/config-env.js
View file @
a239337e
...
@@ -25,6 +25,13 @@ module.exports = function configEnv () {
...
@@ -25,6 +25,13 @@ module.exports = function configEnv () {
process
.
env
.
NODE_ENV
=
process
.
env
.
BUILD_MODE
process
.
env
.
NODE_ENV
=
process
.
env
.
BUILD_MODE
}
}
/** 更新后强制刷新走静默登录接口 */
const
refreshHash
=
crypto
.
createHash
(
'md5'
)
refreshHash
.
update
(
'GEEK-PK-MATH-token-1.0'
)
refreshHash
.
update
(
`refresh-token-
${
env
}
`
)
refreshHash
.
update
(
`refresh-token-
${
process
.
env
.
SERVER_ENDPOINT
||
''
}
`
)
process
.
env
.
TARO_REFRESH_TOKEN
=
refreshHash
.
digest
(
'base64'
).
substring
(
0
,
12
)
const
hash
=
crypto
.
createHash
(
'md5'
)
const
hash
=
crypto
.
createHash
(
'md5'
)
hash
.
update
(
'GEEK-PK-MATH-WEAPP-V1.9'
)
hash
.
update
(
'GEEK-PK-MATH-WEAPP-V1.9'
)
hash
.
update
(
`build-
${
env
}
`
)
hash
.
update
(
`build-
${
env
}
`
)
...
...
src/utils/silent-login.ts
View file @
a239337e
...
@@ -10,16 +10,24 @@ import {
...
@@ -10,16 +10,24 @@ import {
const
silentLoginDeferred
=
new
Deferred
<
null
>
()
const
silentLoginDeferred
=
new
Deferred
<
null
>
()
async
function
silentLogin
()
{
async
function
silentLogin
()
{
const
currentVersionRefreshToken
=
process
.
env
.
TARO_REFRESH_TOKEN
try
{
try
{
await
Taro
.
checkSession
()
await
Taro
.
checkSession
()
// const token = getStorage(StorageKeys.token)
// const token = getStorage(StorageKeys.token)
const
openId
=
getStorage
(
StorageKeys
.
openid
)
const
openId
=
getStorage
(
StorageKeys
.
openid
)
const
userInfo
=
getStorage
(
StorageKeys
.
userInfo
)
const
userInfo
=
getStorage
(
StorageKeys
.
userInfo
)
const
refreshToken
=
getStorage
(
StorageKeys
.
refreshToken
)
if
(
refreshToken
!==
currentVersionRefreshToken
)
{
throw
new
Error
(
'force silent login'
)
}
if
(
!
openId
)
{
// 未登录
if
(
!
openId
)
{
// 未登录
throw
new
Error
(
'unlogin'
)
throw
new
Error
(
'unlogin'
)
}
}
setProfile
(
openId
,
`
${
userInfo
?.
userId
}
`)
setProfile
(
openId
,
`
${
userInfo
?.
userId
}
`)
} catch (error) {
} catch (error) {
updateStorage(StorageKeys.refreshToken, currentVersionRefreshToken)
console.log('check session', error)
console.log('check session', error)
try {
try {
...
...
src/utils/storage.ts
View file @
a239337e
...
@@ -27,6 +27,9 @@ export enum StorageKeys {
...
@@ -27,6 +27,9 @@ export enum StorageKeys {
/** 学分小店引导 */
/** 学分小店引导 */
isStoreGuideComplete
,
isStoreGuideComplete
,
/** 用于强制用户走静默登录接口 */
refreshToken
=
100
,
}
}
type
Storage
=
{
type
Storage
=
{
...
@@ -40,6 +43,7 @@ type Storage = {
...
@@ -40,6 +43,7 @@ type Storage = {
[
StorageKeys
.
isErrQuestionGuideComplete
]:
boolean
|
null
;
[
StorageKeys
.
isErrQuestionGuideComplete
]:
boolean
|
null
;
[
StorageKeys
.
isGroupGuideComplete
]:
boolean
|
null
;
[
StorageKeys
.
isGroupGuideComplete
]:
boolean
|
null
;
[
StorageKeys
.
isStoreGuideComplete
]:
boolean
|
null
;
[
StorageKeys
.
isStoreGuideComplete
]:
boolean
|
null
;
[
StorageKeys
.
refreshToken
]:
string
|
undefined
;
}
}
const
store
:
Storage
=
{}
as
Storage
const
store
:
Storage
=
{}
as
Storage
...
@@ -61,7 +65,8 @@ export function reloadStore () {
...
@@ -61,7 +65,8 @@ export function reloadStore () {
StorageKeys
.
isMainGuideComplete
,
StorageKeys
.
isMainGuideComplete
,
StorageKeys
.
isErrQuestionGuideComplete
,
StorageKeys
.
isErrQuestionGuideComplete
,
StorageKeys
.
isGroupGuideComplete
,
StorageKeys
.
isGroupGuideComplete
,
StorageKeys
.
isStoreGuideComplete
StorageKeys
.
isStoreGuideComplete
,
StorageKeys
.
refreshToken
,
].
forEach
((
element
)
=>
{
].
forEach
((
element
)
=>
{
updateStorage
(
element
,
Taro
.
getStorageSync
(
`
${
storagePrefix
}${
element
}
`
)
??
null
)
updateStorage
(
element
,
Taro
.
getStorageSync
(
`
${
storagePrefix
}${
element
}
`
)
??
null
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment