mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
Fix create workspace without token (#4932)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
62f0ec45a9
commit
322a14443b
@ -23,6 +23,7 @@
|
||||
import { workbenchId } from '@hcengineering/workbench'
|
||||
import presentation from '@hcengineering/presentation'
|
||||
import { onMount } from 'svelte'
|
||||
import { LoginInfo } from '@hcengineering/login'
|
||||
|
||||
const fields = [
|
||||
{
|
||||
@ -39,8 +40,10 @@
|
||||
|
||||
let status: Status<any> = OK
|
||||
|
||||
let account: LoginInfo | undefined = undefined
|
||||
|
||||
onMount(async () => {
|
||||
const account = await getAccount()
|
||||
account = await getAccount()
|
||||
if (account?.confirmed === false) {
|
||||
const loc = getCurrentLocation()
|
||||
loc.path[1] = 'confirmationSend'
|
||||
@ -77,6 +80,7 @@
|
||||
{fields}
|
||||
{object}
|
||||
{action}
|
||||
subtitle={account?.email}
|
||||
bottomActions={[
|
||||
{
|
||||
caption: login.string.HaveWorkspace,
|
||||
|
@ -62,6 +62,7 @@
|
||||
export let object: any
|
||||
export let ignoreInitialValidation: boolean = false
|
||||
export let withProviders: boolean = false
|
||||
export let subtitle: string | undefined = undefined
|
||||
|
||||
$: $themeStore.language && validate($themeStore.language)
|
||||
|
||||
@ -167,6 +168,11 @@
|
||||
</a>
|
||||
</div>
|
||||
{:else}
|
||||
{#if subtitle !== undefined}
|
||||
<div class="fs-title">
|
||||
{subtitle}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="title"><Label label={caption} /></div>
|
||||
{/if}
|
||||
<div class="status">
|
||||
|
@ -14,18 +14,22 @@
|
||||
// limitations under the License.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { getMetadata } from '@hcengineering/platform'
|
||||
import { getMetadata, setMetadata } from '@hcengineering/platform'
|
||||
import presentation from '@hcengineering/presentation'
|
||||
import {
|
||||
Location,
|
||||
Popup,
|
||||
Scroller,
|
||||
deviceOptionsStore as deviceInfo,
|
||||
fetchMetadataLocalStorage,
|
||||
getCurrentLocation,
|
||||
location,
|
||||
setMetadataLocalStorage,
|
||||
themeStore
|
||||
} from '@hcengineering/ui'
|
||||
import workbench from '@hcengineering/workbench'
|
||||
import { onDestroy } from 'svelte'
|
||||
import { onDestroy, onMount } from 'svelte'
|
||||
import Auth from './Auth.svelte'
|
||||
import Confirmation from './Confirmation.svelte'
|
||||
import ConfirmationSend from './ConfirmationSend.svelte'
|
||||
import CreateWorkspaceForm from './CreateWorkspaceForm.svelte'
|
||||
@ -34,7 +38,6 @@
|
||||
import PasswordRequest from './PasswordRequest.svelte'
|
||||
import PasswordRestore from './PasswordRestore.svelte'
|
||||
import SelectWorkspace from './SelectWorkspace.svelte'
|
||||
import Auth from './Auth.svelte'
|
||||
import SignupForm from './SignupForm.svelte'
|
||||
import LoginIcon from './icons/LoginIcon.svelte'
|
||||
|
||||
@ -44,7 +47,7 @@
|
||||
import loginBackAvif from '../../img/login_back.avif'
|
||||
import loginBack2xAvif from '../../img/login_back_2x.avif'
|
||||
|
||||
import { Pages, pages } from '..'
|
||||
import { Pages, getAccount, pages } from '..'
|
||||
import loginBackWebp from '../../img/login_back.webp'
|
||||
import loginBack2xWebp from '../../img/login_back_2x.webp'
|
||||
import login from '../plugin'
|
||||
@ -53,18 +56,50 @@
|
||||
|
||||
let navigateUrl: string | undefined
|
||||
|
||||
onDestroy(
|
||||
location.subscribe((loc) => {
|
||||
const token = getMetadata(presentation.metadata.Token)
|
||||
page = (loc.path[1] as Pages) ?? (token != null ? 'selectWorkspace' : 'login')
|
||||
if (!pages.includes(page)) {
|
||||
const tokens = fetchMetadataLocalStorage(login.metadata.LoginTokens)
|
||||
page = tokens != null ? 'login' : 'signup'
|
||||
}
|
||||
onDestroy(location.subscribe(updatePageLoc))
|
||||
|
||||
navigateUrl = loc.query?.navigateUrl ?? undefined
|
||||
})
|
||||
)
|
||||
function updatePageLoc (loc: Location): void {
|
||||
const token = getMetadata(presentation.metadata.Token)
|
||||
page = (loc.path[1] as Pages) ?? (token != null ? 'selectWorkspace' : 'login')
|
||||
const allowedUnauthPages: Pages[] = [
|
||||
'login',
|
||||
'signup',
|
||||
'password',
|
||||
'recovery',
|
||||
'join',
|
||||
'confirm',
|
||||
'confirmationSend',
|
||||
'auth'
|
||||
]
|
||||
if (token === undefined ? !allowedUnauthPages.includes(page) : !pages.includes(page)) {
|
||||
const tokens = fetchMetadataLocalStorage(login.metadata.LoginTokens)
|
||||
page = tokens != null ? 'login' : 'signup'
|
||||
}
|
||||
|
||||
navigateUrl = loc.query?.navigateUrl ?? undefined
|
||||
}
|
||||
|
||||
async function chooseToken (): Promise<void> {
|
||||
if (getMetadata(presentation.metadata.Token) == null) {
|
||||
const lastToken = fetchMetadataLocalStorage(login.metadata.LastToken)
|
||||
if (lastToken != null) {
|
||||
try {
|
||||
const info = await getAccount(false)
|
||||
if (info !== undefined) {
|
||||
setMetadata(presentation.metadata.Token, info.token)
|
||||
setMetadataLocalStorage(login.metadata.LastToken, info.token)
|
||||
setMetadataLocalStorage(login.metadata.LoginEndpoint, info.endpoint)
|
||||
setMetadataLocalStorage(login.metadata.LoginEmail, info.email)
|
||||
updatePageLoc(getCurrentLocation())
|
||||
}
|
||||
} catch (err: any) {
|
||||
setMetadataLocalStorage(login.metadata.LastToken, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMount(chooseToken)
|
||||
</script>
|
||||
|
||||
<div class="theme-dark w-full h-full backd" class:paneld={$deviceInfo.docWidth <= 768} class:white={!$themeStore.dark}>
|
||||
|
@ -14,22 +14,14 @@
|
||||
// limitations under the License.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { getMetadata, OK, setMetadata, Severity, Status } from '@hcengineering/platform'
|
||||
import { OK, setMetadata, Severity, Status } from '@hcengineering/platform'
|
||||
import presentation from '@hcengineering/presentation'
|
||||
import {
|
||||
fetchMetadataLocalStorage,
|
||||
getCurrentLocation,
|
||||
Loading,
|
||||
Location,
|
||||
navigate,
|
||||
setMetadataLocalStorage
|
||||
} from '@hcengineering/ui'
|
||||
import { getCurrentLocation, Location, navigate, setMetadataLocalStorage } from '@hcengineering/ui'
|
||||
|
||||
import { doLogin, getAccount, getWorkspaces, navigateToWorkspace, selectWorkspace } from '../utils'
|
||||
import { doLogin, getWorkspaces, navigateToWorkspace, selectWorkspace } from '../utils'
|
||||
import Form from './Form.svelte'
|
||||
|
||||
import { LoginInfo } from '@hcengineering/login'
|
||||
import { onMount } from 'svelte'
|
||||
import { recoveryAction } from '../actions'
|
||||
import login from '../plugin'
|
||||
|
||||
@ -102,47 +94,15 @@
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let loading = true
|
||||
|
||||
async function chooseToken (): Promise<void> {
|
||||
if (getMetadata(presentation.metadata.Token) == null) {
|
||||
const lastToken = fetchMetadataLocalStorage(login.metadata.LastToken)
|
||||
if (lastToken != null) {
|
||||
try {
|
||||
const info = await getAccount(false)
|
||||
if (info !== undefined) {
|
||||
await doLoginNavigate(info, (st) => {
|
||||
status = st
|
||||
})
|
||||
}
|
||||
} catch (err: any) {
|
||||
setMetadataLocalStorage(login.metadata.LastToken, null)
|
||||
}
|
||||
}
|
||||
if (loading) {
|
||||
loading = false
|
||||
}
|
||||
} else if (loading) {
|
||||
loading = false
|
||||
}
|
||||
setTimeout(chooseToken, 1000)
|
||||
}
|
||||
|
||||
onMount(() => chooseToken())
|
||||
</script>
|
||||
|
||||
{#if loading}
|
||||
<Loading />
|
||||
{:else}
|
||||
<Form
|
||||
caption={login.string.LogIn}
|
||||
{status}
|
||||
{fields}
|
||||
{object}
|
||||
{action}
|
||||
bottomActions={[recoveryAction]}
|
||||
ignoreInitialValidation
|
||||
withProviders
|
||||
/>
|
||||
{/if}
|
||||
<Form
|
||||
caption={login.string.LogIn}
|
||||
{status}
|
||||
{fields}
|
||||
{object}
|
||||
{action}
|
||||
bottomActions={[recoveryAction]}
|
||||
ignoreInitialValidation
|
||||
withProviders
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user