mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 11:26:52 +08:00
Feat/api jwt (#1212)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import { SWRConfig } from 'swr'
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
|
||||
type SwrInitorProps = {
|
||||
children: ReactNode
|
||||
@@ -9,13 +11,32 @@ type SwrInitorProps = {
|
||||
const SwrInitor = ({
|
||||
children,
|
||||
}: SwrInitorProps) => {
|
||||
return (
|
||||
<SWRConfig value={{
|
||||
shouldRetryOnError: false,
|
||||
}}>
|
||||
{children}
|
||||
</SWRConfig>
|
||||
)
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const consoleToken = searchParams.get('console_token')
|
||||
const consoleTokenFromLocalStorage = localStorage?.getItem('console_token')
|
||||
const [init, setInit] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!(consoleToken || consoleTokenFromLocalStorage))
|
||||
router.replace('/signin')
|
||||
|
||||
if (consoleToken) {
|
||||
localStorage?.setItem('console_token', consoleToken!)
|
||||
router.replace('/apps', { forceOptimisticNavigation: false })
|
||||
}
|
||||
setInit(true)
|
||||
}, [])
|
||||
|
||||
return init
|
||||
? (
|
||||
<SWRConfig value={{
|
||||
shouldRetryOnError: false,
|
||||
}}>
|
||||
{children}
|
||||
</SWRConfig>
|
||||
)
|
||||
: null
|
||||
}
|
||||
|
||||
export default SwrInitor
|
||||
|
||||
Reference in New Issue
Block a user