mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-27 00:48:43 +00:00 
			
		
		
		
	
		
			
	
	
		
			18 lines
		
	
	
		
			609 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
		
		
			
		
	
	
			18 lines
		
	
	
		
			609 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)) | ||
|  |   } | ||
|  | } |