mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-23 08:17:15 +00:00
1. Put 'secret' into one place, server-token 2. Fix server crash on rare unknown workspaces cases. 3. Upgrade now kick all clients and reload transactions. 4. Fix Front shutdown Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
33 lines
751 B
TypeScript
33 lines
751 B
TypeScript
import { getMetadata } from '@anticrm/platform'
|
|
import serverPlugin from './plugin'
|
|
import { encode, decode } from 'jwt-simple'
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export interface Token {
|
|
email: string
|
|
workspace: string
|
|
extra?: Record<string, string>
|
|
}
|
|
|
|
const getSecret = (): string => {
|
|
return getMetadata(serverPlugin.metadata.Secret) ?? 'secret'
|
|
}
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export function generateToken (email: string, workspace: string, extra?: Record<string, string>): string {
|
|
return encode({ ...(extra ?? {}), email, workspace }, getSecret())
|
|
}
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export function decodeToken (token: string): Token {
|
|
const value = decode(token, getSecret(), false)
|
|
const { email, workspace, ...extra } = value
|
|
return { email, workspace, extra }
|
|
}
|