Skip to content
Merged
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
4 changes: 1 addition & 3 deletions src/services/auth/login.emulator.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {green, red} from 'kleur';
import ora from 'ora';
import {saveCliConfig} from '../../configs/cli.config';
import {readEmulatorConfig} from '../../configs/emulator.config';
import {readJunoConfig} from '../../configs/juno.config';
import {ENV} from '../../env';
import {generateToken} from '../../utils/auth.utils';
import {assertConfigAndReadSatelliteId} from '../../utils/satellite.utils';
Expand Down Expand Up @@ -45,8 +44,7 @@ const loginEmulator = async (): Promise<
> => {
// We read directly the Juno config because we cannot load an actor at this point as we are login in.
// i.e. we cannot use assertConfigAndLoadSatelliteContext
const {satellite: satelliteConfig} = await readJunoConfig(ENV);
const {satelliteId} = assertConfigAndReadSatelliteId({satellite: satelliteConfig, env: ENV});
const {satelliteId} = await assertConfigAndReadSatelliteId();

const parsedResult = await readEmulatorConfig();

Expand Down
31 changes: 22 additions & 9 deletions src/utils/satellite.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {assertNonNullish, isNullish} from '@dfinity/utils';
import type {PrincipalText} from '@dfinity/zod-schemas';
import type {SatelliteConfig} from '@junobuild/config';
import type {JunoConfig, SatelliteConfig} from '@junobuild/config';
import {red} from 'kleur';
import {actorParameters} from '../api/actor.api';
import {getCliOrbiters, getCliSatellites} from '../configs/cli.config';
Expand All @@ -14,12 +14,7 @@ export const assertConfigAndLoadSatelliteContext = async (): Promise<{
satellite: SatelliteParametersWithId;
satelliteConfig: SatelliteConfig;
}> => {
if (!(await junoConfigExist())) {
consoleNoConfigFound();
process.exit(1);
}

const {satellite: satelliteConfig} = await readJunoConfig(ENV);
const {satellite: satelliteConfig} = await assertAndReadJunoConfig();

const satellite = await satelliteParameters({satellite: satelliteConfig, env: ENV});

Expand All @@ -30,7 +25,25 @@ export const assertConfigAndLoadSatelliteContext = async (): Promise<{
return {satellite, satelliteConfig};
};

export const assertConfigAndReadSatelliteId = ({
// Useful for reading the configuration without initializing an actor.
// For example, during the authentication flow when no identity is defined yet,
// or in other cases where we want to avoid waiting for the actor initialization timeout.
export const assertConfigAndReadSatelliteId = async (): Promise<{satelliteId: PrincipalText}> => {
const {satellite: satelliteConfig} = await assertAndReadJunoConfig();

return assertAndReadSatelliteId({satellite: satelliteConfig, env: ENV});
};

const assertAndReadJunoConfig = async (): Promise<JunoConfig> => {
if (!(await junoConfigExist())) {
consoleNoConfigFound();
process.exit(1);
}

return await readJunoConfig(ENV);
};

const assertAndReadSatelliteId = ({
satellite,
env: {mode}
}: SatelliteConfigEnv): {satelliteId: PrincipalText} => {
Expand Down Expand Up @@ -58,7 +71,7 @@ export const assertConfigAndReadSatelliteId = ({
const satelliteParameters = async (
params: SatelliteConfigEnv
): Promise<SatelliteParametersWithId> => {
const {satelliteId} = assertConfigAndReadSatelliteId(params);
const {satelliteId} = assertAndReadSatelliteId(params);

return {
satelliteId,
Expand Down