Fix guest links (#6172)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-07-29 20:50:47 +05:00 committed by GitHub
parent 8b44249cec
commit abc5c2979d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 6 additions and 38 deletions

View File

@ -132,6 +132,7 @@ export default plugin(presentationId, {
CollaboratorUrl: '' as Metadata<string>,
CollaboratorApiUrl: '' as Metadata<string>,
Token: '' as Metadata<string>,
Endpoint: '' as Metadata<string>,
FrontUrl: '' as Asset,
PreviewConfig: '' as Metadata<PreviewConfig | undefined>,
ClientHook: '' as Metadata<ClientHook>

View File

@ -46,6 +46,7 @@ export async function connect (title: string): Promise<Client | undefined> {
}
setMetadata(presentation.metadata.Token, token)
setMetadata(presentation.metadata.Endpoint, workspaceLoginInfo.endpoint)
if (_token !== token && _client !== undefined) {
await _client.close()

View File

@ -1,7 +1,7 @@
import client from '@hcengineering/client'
import { type Doc } from '@hcengineering/core'
import login from '@hcengineering/login'
import { getResource, setMetadata } from '@hcengineering/platform'
import { getMetadata, getResource, setMetadata } from '@hcengineering/platform'
import presentation from '@hcengineering/presentation'
import { fetchMetadataLocalStorage, getCurrentLocation, navigate } from '@hcengineering/ui'
import view from '@hcengineering/view'
@ -13,9 +13,8 @@ export async function checkAccess (doc: Doc): Promise<void> {
const ws = loc.path[1]
const tokens: Record<string, string> = fetchMetadataLocalStorage(login.metadata.LoginTokens) ?? {}
const token = tokens[ws]
if (token === undefined) return
const getEndpoint = await getResource(login.function.GetEndpoint)
const endpoint = await getEndpoint()
const endpoint = getMetadata(presentation.metadata.Endpoint)
if (token === undefined || endpoint === undefined) return
const clientFactory = await getResource(client.function.GetClient)
const _client = await clientFactory(token, endpoint)

View File

@ -23,7 +23,6 @@ import {
leaveWorkspace,
selectWorkspace,
sendInvite,
getEnpoint,
fetchWorkspace,
createMissingEmployee,
getInviteLink
@ -48,7 +47,6 @@ export default async () => ({
CreateEmployee: createMissingEmployee,
GetWorkspaces: getWorkspaces,
SendInvite: sendInvite,
GetEndpoint: getEnpoint,
GetInviteLink: getInviteLink
}
})

View File

@ -824,36 +824,6 @@ export async function afterConfirm (): Promise<void> {
}
}
export async function getEnpoint (): Promise<string | undefined> {
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
if (accountsUrl === undefined) {
throw new Error('accounts url not specified')
}
const params: [] = []
const request = {
method: 'getEndpoint',
params
}
try {
const response = await fetch(accountsUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
})
const result = await response.json()
return result.result
} catch (err: any) {
console.error('get endpoint error', err)
Analytics.handleError(err)
}
}
export async function getSessionLoginInfo (): Promise<LoginInfo | WorkspaceLoginInfo | undefined> {
const accountsUrl = getMetadata(login.metadata.AccountsUrl)

View File

@ -95,7 +95,6 @@ export default plugin(loginId, {
>,
FetchWorkspace: '' as Resource<(workspace: string) => Promise<[Status, WorkspaceLoginInfo | undefined]>>,
CreateEmployee: '' as Resource<(workspace: string) => Promise<[Status]>>,
GetWorkspaces: '' as Resource<() => Promise<Workspace[]>>,
GetEndpoint: '' as Resource<() => Promise<string>>
GetWorkspaces: '' as Resource<() => Promise<Workspace[]>>
}
})