mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-02 14:29:03 +02:00
save login token to localstorage
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
@@ -56,6 +56,8 @@ export { default as IconSearch } from './components/icons/Search.svelte'
|
||||
export { default as IconToDo } from './components/icons/ToDo.svelte'
|
||||
export { default as IconComments } from './components/icons/Comments.svelte'
|
||||
|
||||
export * from './utils'
|
||||
|
||||
import type { AnySvelteComponent, AnyComponent } from './types'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
|
||||
@@ -14,7 +14,21 @@
|
||||
//
|
||||
|
||||
// import type { Metadata } from '@anticrm/platform'
|
||||
import type { AnyComponent /*, Location */ } from './types'
|
||||
import { setMetadata } from '@anticrm/platform'
|
||||
import type { Metadata } from '@anticrm/platform'
|
||||
|
||||
export function setMetadataLocalStorage(id: Metadata<string>, value: string): void {
|
||||
localStorage.setItem(id, value)
|
||||
setMetadata(id, value)
|
||||
}
|
||||
|
||||
export function fetchMetadataLocalStorage(id: Metadata<string>): string | null {
|
||||
const value = localStorage.getItem(id)
|
||||
if (value !== null) {
|
||||
setMetadata(id, value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// import { Readable, derived, writable } from 'svelte/store'
|
||||
// import { onDestroy, getContext, setContext } from 'svelte'
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { OK, Status, Severity, setMetadata } from '@anticrm/platform'
|
||||
import { navigate } from '@anticrm/ui'
|
||||
import { OK, Status, Severity } from '@anticrm/platform'
|
||||
import { navigate, setMetadataLocalStorage } from '@anticrm/ui'
|
||||
|
||||
import Form from './Form.svelte'
|
||||
import { doLogin } from '../utils'
|
||||
@@ -54,8 +54,8 @@
|
||||
|
||||
if (result !== undefined) {
|
||||
console.log('token', result.token)
|
||||
setMetadata(login.metadata.LoginToken, result.token)
|
||||
setMetadata(login.metadata.LoginEndpoint, result.endpoint)
|
||||
setMetadataLocalStorage(login.metadata.LoginToken, result.token)
|
||||
setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint)
|
||||
navigate({ path: [workbench.component.WorkbenchApp] })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
|
||||
<script lang="ts">
|
||||
|
||||
import { getResource, getMetadata } from '@anticrm/platform'
|
||||
import { getResource } from '@anticrm/platform'
|
||||
import type { Client } from '@anticrm/core'
|
||||
import { navigate, Loading } from '@anticrm/ui'
|
||||
import { navigate, Loading, fetchMetadataLocalStorage } from '@anticrm/ui'
|
||||
|
||||
import client from '@anticrm/client'
|
||||
import login from '@anticrm/login'
|
||||
@@ -25,10 +25,10 @@ import login from '@anticrm/login'
|
||||
import Workbench from './Workbench.svelte'
|
||||
|
||||
async function connect(): Promise<Client | undefined> {
|
||||
const token = getMetadata(login.metadata.LoginToken)
|
||||
const endpoint = getMetadata(login.metadata.LoginEndpoint)
|
||||
const token = fetchMetadataLocalStorage(login.metadata.LoginToken)
|
||||
const endpoint = fetchMetadataLocalStorage(login.metadata.LoginEndpoint)
|
||||
|
||||
if (token === undefined || endpoint === undefined) {
|
||||
if (token === null || endpoint === null) {
|
||||
navigate({ path: [login.component.LoginApp] })
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user