mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 23:32:14 +00:00
Create new client when token has been changed
Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
parent
e848480ef3
commit
437170c203
@ -27,17 +27,23 @@ export { connect }
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||||
export default async () => {
|
export default async () => {
|
||||||
|
let _token: string | undefined = undefined
|
||||||
let client: Client | undefined
|
let client: Client | undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
function: {
|
function: {
|
||||||
GetClient: async (token: string, endpoint: string): Promise<Client> => {
|
GetClient: async (token: string, endpoint: string): Promise<Client> => {
|
||||||
|
if (token !== _token && client !== undefined) {
|
||||||
|
client.close()
|
||||||
|
client = undefined
|
||||||
|
}
|
||||||
if (client === undefined) {
|
if (client === undefined) {
|
||||||
client = await createClient((handler: TxHander) => {
|
client = await createClient((handler: TxHander) => {
|
||||||
const url = new URL(`/${token}`, endpoint)
|
const url = new URL(`/${token}`, endpoint)
|
||||||
console.log('connecting to', url.href)
|
console.log('connecting to', url.href)
|
||||||
return connect(url.href, handler)
|
return connect(url.href, handler)
|
||||||
})
|
})
|
||||||
|
_token = token
|
||||||
|
|
||||||
// Check if we had dev hook for client.
|
// Check if we had dev hook for client.
|
||||||
const hook = getMetadata(clientPlugin.metadata.ClientHook)
|
const hook = getMetadata(clientPlugin.metadata.ClientHook)
|
||||||
|
Loading…
Reference in New Issue
Block a user