Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEFAULT_LOGIN_METHOD env for when mail otp isn't available (self-hosted) #7092

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions desktop/src/ui/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ import github, { githubId } from '@hcengineering/github'
import { uiId } from '@hcengineering/ui/src/plugin'
import { preferenceId } from '@hcengineering/preference'

function configureI18n (): void {
function configureI18n(): void {
// Add localization
addStringsLoader(platformId, async (lang: string) => await import(`@hcengineering/platform/lang/${lang}.json`))
addStringsLoader(coreId, async (lang: string) => await import(`@hcengineering/core/lang/${lang}.json`))
Expand Down Expand Up @@ -187,7 +187,7 @@ function configureI18n (): void {
addStringsLoader(analyticsCollectorId, async (lang: string) => await import(`@hcengineering/analytics-collector-assets/lang/${lang}.json`))
}

export async function configurePlatform (): Promise<void> {
export async function configurePlatform(): Promise<void> {
configureI18n()

const ipcMain = (window as any).electron as IPCMainExposed
Expand All @@ -202,6 +202,7 @@ export async function configurePlatform (): Promise<void> {

setMetadata(login.metadata.AccountsUrl, config.ACCOUNTS_URL)
setMetadata(login.metadata.DisableSignUp, config.DISABLE_SIGNUP === 'true')
setMetadata(login.metadata.DefaultLoginMethod, config.DEFAULT_LOGIN_METHOD)
setMetadata(presentation.metadata.UploadURL, config.UPLOAD_URL)
setMetadata(presentation.metadata.FilesURL, config.FILES_URL)
setMetadata(presentation.metadata.CollaboratorUrl, config.COLLABORATOR_URL)
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export interface Config {
PRINT_URL?: string
PUSH_PUBLIC_KEY: string
ANALYTICS_COLLECTOR_URL?: string
AI_URL?:string
AI_URL?: string
DISABLE_SIGNUP?: string
DEFAULT_LOGIN_METHOD?: 'otp' | 'password'
BRANDING_URL?: string
PREVIEW_CONFIG: string
UPLOAD_CONFIG: string
Expand Down
2 changes: 2 additions & 0 deletions dev/prod/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface Config {
TELEGRAM_BOT_URL?: string
AI_URL?:string
DISABLE_SIGNUP?: string
DEFAULT_LOGIN_METHOD?: 'otp'|'password'
// Could be defined for dev environment
FRONT_URL?: string
PREVIEW_CONFIG?: string
Expand Down Expand Up @@ -294,6 +295,7 @@ export async function configurePlatform() {

setMetadata(login.metadata.AccountsUrl, config.ACCOUNTS_URL)
setMetadata(login.metadata.DisableSignUp, config.DISABLE_SIGNUP === 'true')
setMetadata(login.metadata.DefaultLoginMethod, config.DEFAULT_LOGIN_METHOD)
setMetadata(presentation.metadata.FilesURL, config.FILES_URL)
setMetadata(presentation.metadata.UploadURL, config.UPLOAD_URL)
setMetadata(presentation.metadata.CollaboratorUrl, config.COLLABORATOR_URL)
Expand Down
4 changes: 2 additions & 2 deletions plugins/login-resources/src/components/LoginApp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

onDestroy(location.subscribe(updatePageLoc))

function updatePageLoc (loc: Location): void {
function updatePageLoc(loc: Location): void {
const token = getMetadata(presentation.metadata.Token)
page = (loc.path[1] as Pages) ?? (token != null ? 'selectWorkspace' : 'login')
const allowedUnauthPages: Pages[] = [
Expand All @@ -80,7 +80,7 @@
navigateUrl = loc.query?.navigateUrl ?? undefined
}

async function chooseToken (): Promise<void> {
async function chooseToken(): Promise<void> {
if (page === 'auth') {
// token handled by auth page
return
Expand Down
8 changes: 7 additions & 1 deletion plugins/login-resources/src/components/LoginForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
import LoginPasswordForm from './LoginPasswordForm.svelte'
import LoginOtpForm from './LoginOtpForm.svelte'
import BottomActionComponent from './BottomAction.svelte'
import { getMetadata } from '@hcengineering/platform'
import login from '../plugin'

export let navigateUrl: string | undefined = undefined
export let signUpDisabled = false
const defaultLoginMethod = getMetadata(login.metadata.DefaultLoginMethod) ?? 'otp'

let method: LoginMethods = LoginMethods.Otp
gptlang marked this conversation as resolved.
Show resolved Hide resolved

function changeMethod (event: CustomEvent<LoginMethods>): void {
if (defaultLoginMethod === 'password') {
method = LoginMethods.Password
}

function changeMethod(event: CustomEvent<LoginMethods>): void {
method = event.detail
}

Expand Down
1 change: 1 addition & 0 deletions plugins/login/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default plugin(loginId, {
LastToken: '' as Metadata<string>,
LoginEndpoint: '' as Metadata<string>,
LoginEmail: '' as Metadata<string>,
DefaultLoginMethod: '' as Metadata<'otp' | 'password'>,
DisableSignUp: '' as Metadata<boolean>
},
component: {
Expand Down
5 changes: 4 additions & 1 deletion server/front/src/starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export function startFront (ctx: MeasureContext, extraConfig?: Record<string, st

const disableSignUp = process.env.DISABLE_SIGNUP

const defaultLoginMethod = process.env.DEFAULT_LOGIN_METHOD

const config = {
elasticUrl,
storageAdapter,
Expand All @@ -137,7 +139,8 @@ export function startFront (ctx: MeasureContext, extraConfig?: Record<string, st
previewConfig,
uploadConfig,
pushPublicKey,
disableSignUp
disableSignUp,
defaultLoginMethod
}
console.log('Starting Front service with', config)
const shutdown = start(ctx, config, SERVER_PORT, extraConfig)
Expand Down
Loading