mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-24 17:30:03 +00: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 { workbenchId } from '@hcengineering/workbench'
|
||||||
import presentation from '@hcengineering/presentation'
|
import presentation from '@hcengineering/presentation'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import { LoginInfo } from '@hcengineering/login'
|
||||||
|
|
||||||
const fields = [
|
const fields = [
|
||||||
{
|
{
|
||||||
@ -39,8 +40,10 @@
|
|||||||
|
|
||||||
let status: Status<any> = OK
|
let status: Status<any> = OK
|
||||||
|
|
||||||
|
let account: LoginInfo | undefined = undefined
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const account = await getAccount()
|
account = await getAccount()
|
||||||
if (account?.confirmed === false) {
|
if (account?.confirmed === false) {
|
||||||
const loc = getCurrentLocation()
|
const loc = getCurrentLocation()
|
||||||
loc.path[1] = 'confirmationSend'
|
loc.path[1] = 'confirmationSend'
|
||||||
@ -77,6 +80,7 @@
|
|||||||
{fields}
|
{fields}
|
||||||
{object}
|
{object}
|
||||||
{action}
|
{action}
|
||||||
|
subtitle={account?.email}
|
||||||
bottomActions={[
|
bottomActions={[
|
||||||
{
|
{
|
||||||
caption: login.string.HaveWorkspace,
|
caption: login.string.HaveWorkspace,
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
export let object: any
|
export let object: any
|
||||||
export let ignoreInitialValidation: boolean = false
|
export let ignoreInitialValidation: boolean = false
|
||||||
export let withProviders: boolean = false
|
export let withProviders: boolean = false
|
||||||
|
export let subtitle: string | undefined = undefined
|
||||||
|
|
||||||
$: $themeStore.language && validate($themeStore.language)
|
$: $themeStore.language && validate($themeStore.language)
|
||||||
|
|
||||||
@ -167,6 +168,11 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
{#if subtitle !== undefined}
|
||||||
|
<div class="fs-title">
|
||||||
|
{subtitle}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<div class="title"><Label label={caption} /></div>
|
<div class="title"><Label label={caption} /></div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="status">
|
<div class="status">
|
||||||
|
@ -14,18 +14,22 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getMetadata } from '@hcengineering/platform'
|
import { getMetadata, setMetadata } from '@hcengineering/platform'
|
||||||
import presentation from '@hcengineering/presentation'
|
import presentation from '@hcengineering/presentation'
|
||||||
import {
|
import {
|
||||||
|
Location,
|
||||||
Popup,
|
Popup,
|
||||||
Scroller,
|
Scroller,
|
||||||
deviceOptionsStore as deviceInfo,
|
deviceOptionsStore as deviceInfo,
|
||||||
fetchMetadataLocalStorage,
|
fetchMetadataLocalStorage,
|
||||||
|
getCurrentLocation,
|
||||||
location,
|
location,
|
||||||
|
setMetadataLocalStorage,
|
||||||
themeStore
|
themeStore
|
||||||
} from '@hcengineering/ui'
|
} from '@hcengineering/ui'
|
||||||
import workbench from '@hcengineering/workbench'
|
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 Confirmation from './Confirmation.svelte'
|
||||||
import ConfirmationSend from './ConfirmationSend.svelte'
|
import ConfirmationSend from './ConfirmationSend.svelte'
|
||||||
import CreateWorkspaceForm from './CreateWorkspaceForm.svelte'
|
import CreateWorkspaceForm from './CreateWorkspaceForm.svelte'
|
||||||
@ -34,7 +38,6 @@
|
|||||||
import PasswordRequest from './PasswordRequest.svelte'
|
import PasswordRequest from './PasswordRequest.svelte'
|
||||||
import PasswordRestore from './PasswordRestore.svelte'
|
import PasswordRestore from './PasswordRestore.svelte'
|
||||||
import SelectWorkspace from './SelectWorkspace.svelte'
|
import SelectWorkspace from './SelectWorkspace.svelte'
|
||||||
import Auth from './Auth.svelte'
|
|
||||||
import SignupForm from './SignupForm.svelte'
|
import SignupForm from './SignupForm.svelte'
|
||||||
import LoginIcon from './icons/LoginIcon.svelte'
|
import LoginIcon from './icons/LoginIcon.svelte'
|
||||||
|
|
||||||
@ -44,7 +47,7 @@
|
|||||||
import loginBackAvif from '../../img/login_back.avif'
|
import loginBackAvif from '../../img/login_back.avif'
|
||||||
import loginBack2xAvif from '../../img/login_back_2x.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 loginBackWebp from '../../img/login_back.webp'
|
||||||
import loginBack2xWebp from '../../img/login_back_2x.webp'
|
import loginBack2xWebp from '../../img/login_back_2x.webp'
|
||||||
import login from '../plugin'
|
import login from '../plugin'
|
||||||
@ -53,18 +56,50 @@
|
|||||||
|
|
||||||
let navigateUrl: string | undefined
|
let navigateUrl: string | undefined
|
||||||
|
|
||||||
onDestroy(
|
onDestroy(location.subscribe(updatePageLoc))
|
||||||
location.subscribe((loc) => {
|
|
||||||
|
function updatePageLoc (loc: Location): void {
|
||||||
const token = getMetadata(presentation.metadata.Token)
|
const token = getMetadata(presentation.metadata.Token)
|
||||||
page = (loc.path[1] as Pages) ?? (token != null ? 'selectWorkspace' : 'login')
|
page = (loc.path[1] as Pages) ?? (token != null ? 'selectWorkspace' : 'login')
|
||||||
if (!pages.includes(page)) {
|
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)
|
const tokens = fetchMetadataLocalStorage(login.metadata.LoginTokens)
|
||||||
page = tokens != null ? 'login' : 'signup'
|
page = tokens != null ? 'login' : 'signup'
|
||||||
}
|
}
|
||||||
|
|
||||||
navigateUrl = loc.query?.navigateUrl ?? undefined
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="theme-dark w-full h-full backd" class:paneld={$deviceInfo.docWidth <= 768} class:white={!$themeStore.dark}>
|
<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.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<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 presentation from '@hcengineering/presentation'
|
||||||
import {
|
import { getCurrentLocation, Location, navigate, setMetadataLocalStorage } from '@hcengineering/ui'
|
||||||
fetchMetadataLocalStorage,
|
|
||||||
getCurrentLocation,
|
|
||||||
Loading,
|
|
||||||
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 Form from './Form.svelte'
|
||||||
|
|
||||||
import { LoginInfo } from '@hcengineering/login'
|
import { LoginInfo } from '@hcengineering/login'
|
||||||
import { onMount } from 'svelte'
|
|
||||||
import { recoveryAction } from '../actions'
|
import { recoveryAction } from '../actions'
|
||||||
import login from '../plugin'
|
import login from '../plugin'
|
||||||
|
|
||||||
@ -102,40 +94,9 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
{#if loading}
|
<Form
|
||||||
<Loading />
|
|
||||||
{:else}
|
|
||||||
<Form
|
|
||||||
caption={login.string.LogIn}
|
caption={login.string.LogIn}
|
||||||
{status}
|
{status}
|
||||||
{fields}
|
{fields}
|
||||||
@ -144,5 +105,4 @@
|
|||||||
bottomActions={[recoveryAction]}
|
bottomActions={[recoveryAction]}
|
||||||
ignoreInitialValidation
|
ignoreInitialValidation
|
||||||
withProviders
|
withProviders
|
||||||
/>
|
/>
|
||||||
{/if}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user