Fix redirect url (#2775)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-03-20 20:04:56 +06:00 committed by GitHub
parent d8bfb1c413
commit 2817f40b82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -15,9 +15,9 @@
-->
<script lang="ts">
import { OK, setMetadata, Severity, Status } from '@hcengineering/platform'
import { getCurrentLocation, navigate, setMetadataLocalStorage } from '@hcengineering/ui'
import { getCurrentLocation, navigate, Location, setMetadataLocalStorage } from '@hcengineering/ui'
import { doLogin } from '../utils'
import { doLogin, getWorkspaces, navigateToWorkspace, selectWorkspace } from '../utils'
import Form from './Form.svelte'
import login from '../plugin'
@ -53,6 +53,26 @@
setMetadata(login.metadata.LoginToken, result.token)
setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint)
setMetadataLocalStorage(login.metadata.LoginEmail, result.email)
if (navigateUrl !== undefined) {
try {
const loc = JSON.parse(decodeURIComponent(navigateUrl)) as Location
const workspace = loc.path[1]
if (workspace !== undefined) {
const workspaces = await getWorkspaces()
if (workspaces.find((p) => p.workspace === workspace) !== undefined) {
status = new Status(Severity.INFO, login.status.ConnectingToServer, {})
const [loginStatus, result] = await selectWorkspace(workspace)
status = loginStatus
navigateToWorkspace(workspace, result, navigateUrl)
return
}
}
} catch (err: any) {
// Json parse error could be ignored
}
}
const loc = getCurrentLocation()
loc.path[1] = 'selectWorkspace'
loc.path.length = 2

View File

@ -292,12 +292,10 @@ export function navigateToWorkspace (workspace: string, loginInfo?: WorkspaceLog
setLoginInfo(loginInfo)
if (navigateUrl !== undefined) {
const loc = JSON.parse(decodeURIComponent(navigateUrl)) as Location
try {
const url = JSON.parse(decodeURIComponent(loc.query?.navigateUrl ?? '{}')) as Location
if (url.path[1] === workspace) {
navigate(url)
const loc = JSON.parse(decodeURIComponent(navigateUrl)) as Location
if (loc.path[1] === workspace) {
navigate(loc)
return
}
} catch (err: any) {