Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
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
ai-tech
dify
Commits
6ba806e7
Commit
6ba806e7
authored
Jul 11, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix token in localstorage
parent
5bde4893
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
index.tsx
web/app/components/share/chat/index.tsx
+13
-3
base.ts
web/service/base.ts
+10
-2
No files found.
web/app/components/share/chat/index.tsx
View file @
6ba806e7
...
@@ -312,9 +312,19 @@ const Main: FC<IMainProps> = ({
...
@@ -312,9 +312,19 @@ const Main: FC<IMainProps> = ({
}
}
const
fetchAndSetAccessToken
=
async
()
=>
{
const
fetchAndSetAccessToken
=
async
()
=>
{
const
res
=
await
fetchAccessToken
(
params
.
token
)
const
sharedToken
=
params
.
token
localStorage
.
setItem
(
'accessToken'
,
res
.
access_token
)
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
fetchInitData
()
let
accessTokenJson
=
{
[
sharedToken
]:
''
}
try
{
accessTokenJson
=
JSON
.
parse
(
accessToken
)
}
catch
(
e
)
{
}
const
res
=
await
fetchAccessToken
(
sharedToken
)
accessTokenJson
[
sharedToken
]
=
res
.
access_token
localStorage
.
setItem
(
'token'
,
JSON
.
stringify
(
accessTokenJson
))
location
.
reload
()
}
}
const
fetchInitData
=
async
()
=>
{
const
fetchInitData
=
async
()
=>
{
...
...
web/service/base.ts
View file @
6ba806e7
...
@@ -141,8 +141,16 @@ const baseFetch = (
...
@@ -141,8 +141,16 @@ const baseFetch = (
)
=>
{
)
=>
{
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
if
(
isPublicAPI
)
{
if
(
isPublicAPI
)
{
const
sharedToken
=
localStorage
.
getItem
(
'accessToken'
)
||
''
const
sharedToken
=
globalThis
.
location
.
pathname
.
split
(
'/'
).
slice
(
-
1
)[
0
]
options
.
headers
.
set
(
'Authorization'
,
`Bearer
${
sharedToken
}
`
)
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
let
accessTokenJson
=
{
[
sharedToken
]:
''
}
try
{
accessTokenJson
=
JSON
.
parse
(
accessToken
)
}
catch
(
e
)
{
}
options
.
headers
.
set
(
'Authorization'
,
`Bearer
${
accessTokenJson
[
sharedToken
]}
`
)
}
}
if
(
deleteContentType
)
{
if
(
deleteContentType
)
{
...
...
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