Fix login issue (#1112)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-03-09 16:40:20 +07:00 committed by GitHub
parent 16bd4b983a
commit 3ce4ea076c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 13 deletions

View File

@ -17,6 +17,7 @@ import { addLocation } from '@anticrm/platform'
import login, { loginId } from '@anticrm/login' import login, { loginId } from '@anticrm/login'
import workbench, { workbenchId } from '@anticrm/workbench' import workbench, { workbenchId } from '@anticrm/workbench'
import uiPlugin from '@anticrm/ui'
import { viewId } from '@anticrm/view' import { viewId } from '@anticrm/view'
import { taskId } from '@anticrm/task' import { taskId } from '@anticrm/task'
import { contactId } from '@anticrm/contact' import { contactId } from '@anticrm/contact'
@ -73,6 +74,8 @@ export async function configurePlatform() {
setMetadata(rekoni.metadata.RekoniUrl, process.env.REKONI_URL) setMetadata(rekoni.metadata.RekoniUrl, process.env.REKONI_URL)
setMetadata(uiPlugin.metadata.DefaultApplication, workbench.component.WorkbenchApp )
addLocation(clientId, () => import(/* webpackChunkName: "client" */ '@anticrm/client-resources')) addLocation(clientId, () => import(/* webpackChunkName: "client" */ '@anticrm/client-resources'))
addLocation(loginId, () => import(/* webpackChunkName: "login" */ '@anticrm/login-resources')) addLocation(loginId, () => import(/* webpackChunkName: "login" */ '@anticrm/login-resources'))
addLocation(workbenchId, () => import(/* webpackChunkName: "workbench" */ '@anticrm/workbench-resources')) addLocation(workbenchId, () => import(/* webpackChunkName: "workbench" */ '@anticrm/workbench-resources'))

View File

@ -1,10 +1,10 @@
<script lang="ts"> <script lang="ts">
import { onDestroy } from 'svelte' import { onDestroy } from 'svelte'
import { OK } from '@anticrm/platform' import { getMetadata, OK } from '@anticrm/platform'
import { PlatformEvent, addEventListener } from '@anticrm/platform' import { PlatformEvent, addEventListener } from '@anticrm/platform'
import type { AnyComponent } from '../../types' import type { AnyComponent } from '../../types'
// import { applicationShortcutKey } from '../../utils' // import { applicationShortcutKey } from '../../utils'
import { location } from '../../location' import { getCurrentLocation, location, navigate } from '../../location'
import { Theme } from '@anticrm/theme' import { Theme } from '@anticrm/theme'
import Component from '../Component.svelte' import Component from '../Component.svelte'
@ -16,6 +16,7 @@
import ThemeSelector from './ThemeSelector.svelte' import ThemeSelector from './ThemeSelector.svelte'
import FontSizeSelector from './FontSizeSelector.svelte' import FontSizeSelector from './FontSizeSelector.svelte'
import LangSelector from './LangSelector.svelte' import LangSelector from './LangSelector.svelte'
import uiPlugin from '../../plugin'
let application: AnyComponent | undefined let application: AnyComponent | undefined
@ -23,6 +24,15 @@
if (loc.path[0]) { if (loc.path[0]) {
application = loc.path[0] as AnyComponent application = loc.path[0] as AnyComponent
} }
if (application === undefined) {
application = getMetadata(uiPlugin.metadata.DefaultApplication)
if (application !== undefined) {
const loc = getCurrentLocation()
loc.path = [application]
navigate(loc)
}
}
})) }))
let status = OK let status = OK

View File

@ -14,8 +14,9 @@
// limitations under the License. // limitations under the License.
// //
import type { IntlString, Plugin } from '@anticrm/platform' import type { IntlString, Metadata, Plugin } from '@anticrm/platform'
import { plugin } from '@anticrm/platform' import { plugin } from '@anticrm/platform'
import { AnyComponent } from './types'
/** /**
* @public * @public
@ -38,5 +39,8 @@ export default plugin(uiId, {
None: '' as IntlString, None: '' as IntlString,
English: '' as IntlString, English: '' as IntlString,
Russian: '' as IntlString Russian: '' as IntlString
},
metadata: {
DefaultApplication: '' as Metadata<AnyComponent>
} }
}) })

View File

@ -26,11 +26,15 @@
export let page: string = 'login' export let page: string = 'login'
let navigateUrl: string | undefined
const token = fetchMetadataLocalStorage(login.metadata.LoginToken) const token = fetchMetadataLocalStorage(login.metadata.LoginToken)
onDestroy( onDestroy(
location.subscribe(async (loc) => { location.subscribe(async (loc) => {
page = loc.path[1] ?? (token ? 'selectWorkspace' : 'login') page = loc.path[1] ?? (token ? 'selectWorkspace' : 'login')
navigateUrl = loc.query?.navigateUrl ?? undefined
}) })
) )
</script> </script>
@ -38,13 +42,13 @@
<div class="container"> <div class="container">
<div class="panel"> <div class="panel">
{#if page === 'login'} {#if page === 'login'}
<LoginForm /> <LoginForm {navigateUrl} />
{:else if page === 'signup'} {:else if page === 'signup'}
<SignupForm /> <SignupForm />
{:else if page === 'createWorkspace'} {:else if page === 'createWorkspace'}
<CreateWorkspaceForm /> <CreateWorkspaceForm />
{:else if page === 'selectWorkspace'} {:else if page === 'selectWorkspace'}
<SelectWorkspace /> <SelectWorkspace {navigateUrl} />
{:else if page === 'join'} {:else if page === 'join'}
<Join /> <Join />
{/if} {/if}

View File

@ -22,6 +22,8 @@
import login from '../plugin' import login from '../plugin'
export let navigateUrl: string | undefined = undefined
const fields = [ const fields = [
{ id: 'email', name: 'username', i18n: login.string.Email }, { id: 'email', name: 'username', i18n: login.string.Email },
{ {
@ -54,6 +56,9 @@
const loc = getCurrentLocation() const loc = getCurrentLocation()
loc.path[1] = 'selectWorkspace' loc.path[1] = 'selectWorkspace'
loc.path.length = 2 loc.path.length = 2
if (navigateUrl !== undefined) {
loc.query = { ...loc.query, navigateUrl }
}
navigate(loc) navigate(loc)
} }
} }

View File

@ -14,15 +14,15 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { Status, Severity, OK } from '@anticrm/platform' import { OK, Severity, Status } from '@anticrm/platform'
import { getWorkspaces, selectWorkspace } from '../utils'
import { Button, getCurrentLocation, Label, navigate, setMetadataLocalStorage } from '@anticrm/ui' import { Button, getCurrentLocation, Label, navigate, setMetadataLocalStorage } from '@anticrm/ui'
import workbench from '@anticrm/workbench' import workbench from '@anticrm/workbench'
import login from '../plugin' import login from '../plugin'
import { getWorkspaces, selectWorkspace } from '../utils'
import StatusControl from './StatusControl.svelte' import StatusControl from './StatusControl.svelte'
export let navigateUrl: string | undefined = undefined
let status = OK let status = OK
async function select (workspace: string) { async function select (workspace: string) {
@ -35,7 +35,11 @@
setMetadataLocalStorage(login.metadata.LoginToken, result.token) setMetadataLocalStorage(login.metadata.LoginToken, result.token)
setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint) setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint)
setMetadataLocalStorage(login.metadata.LoginEmail, result.email) setMetadataLocalStorage(login.metadata.LoginEmail, result.email)
navigate({ path: [workbench.component.WorkbenchApp] }) if (navigateUrl !== undefined) {
navigate(JSON.parse(decodeURIComponent(navigateUrl)))
} else {
navigate({ path: [workbench.component.WorkbenchApp] })
}
} }
} }

View File

@ -19,7 +19,7 @@ import { getMetadata, getResource } from '@anticrm/platform'
import type { Client } from '@anticrm/core' import type { Client } from '@anticrm/core'
import core from '@anticrm/core' import core from '@anticrm/core'
import { setCurrentAccount } from '@anticrm/core' import { setCurrentAccount } from '@anticrm/core'
import { navigate, Loading, fetchMetadataLocalStorage, setMetadataLocalStorage } from '@anticrm/ui' import { navigate, Loading, fetchMetadataLocalStorage, setMetadataLocalStorage, getCurrentLocation, locationToUrl } from '@anticrm/ui'
import client from '@anticrm/client' import client from '@anticrm/client'
import login from '@anticrm/login' import login from '@anticrm/login'
@ -36,7 +36,7 @@ async function connect (): Promise<Client | undefined> {
const email = fetchMetadataLocalStorage(login.metadata.LoginEmail) const email = fetchMetadataLocalStorage(login.metadata.LoginEmail)
if (token === null || endpoint === null || email === null) { if (token === null || endpoint === null || email === null) {
navigate({ path: [login.component.LoginApp] }) navigate({ path: [login.component.LoginApp], query: { navigateUrl: encodeURIComponent(JSON.stringify(getCurrentLocation())) } })
return return
} }
@ -53,7 +53,7 @@ async function connect (): Promise<Client | undefined> {
setMetadataLocalStorage(login.metadata.LoginToken, null) setMetadataLocalStorage(login.metadata.LoginToken, null)
setMetadataLocalStorage(login.metadata.LoginEndpoint, null) setMetadataLocalStorage(login.metadata.LoginEndpoint, null)
setMetadataLocalStorage(login.metadata.LoginEmail, null) setMetadataLocalStorage(login.metadata.LoginEmail, null)
navigate({ path: [login.component.LoginApp] }) navigate({ path: [login.component.LoginApp], query: { navigateUrl: encodeURIComponent(JSON.stringify(getCurrentLocation())) } })
return return
} }