mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
d49ac1e4ac
Co-authored-by: crazywoola <li.zheng@dentsplysirona.com> Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
19 lines
610 B
TypeScript
19 lines
610 B
TypeScript
import { fetchAccessToken } from '@/service/share'
|
|
|
|
export const checkOrSetAccessToken = async () => {
|
|
const sharedToken = globalThis.location.pathname.split('/').slice(-1)[0]
|
|
const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' })
|
|
let accessTokenJson = { [sharedToken]: '' }
|
|
try {
|
|
accessTokenJson = JSON.parse(accessToken)
|
|
}
|
|
catch (e) {
|
|
|
|
}
|
|
if (!accessTokenJson[sharedToken]) {
|
|
const res = await fetchAccessToken(sharedToken)
|
|
accessTokenJson[sharedToken] = res.access_token
|
|
localStorage.setItem('token', JSON.stringify(accessTokenJson))
|
|
}
|
|
}
|