Skip to content

Commit

Permalink
APPS-23: Disallow auth for non dev stores (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
azuradara authored Jan 7, 2025
1 parent 4b356e7 commit 5bfaa00
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
14 changes: 7 additions & 7 deletions packages/app/lib/cli/commands/app/dev.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Env, Http, Services, Path, Session, System, Tasks, UI, Filesystem } from '@youcan/cli-kit';
import { Env, Filesystem, Http, Path, Services, Session, System, Tasks, UI } from '@youcan/cli-kit';
import type { Worker } from '@youcan/cli-kit';
import { bootAppWorker, bootExtensionWorker, bootTunnelWorker, bootWebWorker } from '@/cli/services/dev/workers';
import { AppCommand } from '@/util/app-command';
Expand Down Expand Up @@ -59,8 +59,8 @@ class Dev extends AppCommand {

this.app.network_config = {
app_port: port,
app_url: `http://localhost:${port}`
}
app_url: `http://localhost:${port}`,
};

const worker = await bootTunnelWorker(this, this.app, new Services.Cloudflared());

Expand All @@ -69,13 +69,13 @@ class Dev extends AppCommand {
app_url: worker.getUrl(),
redirect_urls: this.app.config.redirect_urls?.length > 0
? this.app.config.redirect_urls.map(r => new URL(new URL(r).pathname, worker.getUrl()).toString())
: [new URL('/auth/callback', worker.getUrl()).toString()]
}
: [new URL('/auth/callback', worker.getUrl()).toString()],
};

await Filesystem.writeJsonFile(
Path.join(this.app.root, APP_CONFIG_FILENAME),
this.app.config
)
this.app.config,
);

return worker;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/app/lib/cli/services/dev/workers/tunnel-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ export default class TunnelWorker extends Worker.Abstract {
this.app.network_config!.app_url = this.url;
this.logger.write(`tunneled url obtained: \`${url}\``);
}

await System.sleep(0.5)

attempts++;
await System.sleep(0.5);
}

if (!this.url) {
this.logger.write('could not establish a tunnel, using localhost instead')
this.logger.write('could not establish a tunnel, using localhost instead');
}
}

Expand All @@ -60,7 +61,7 @@ export default class TunnelWorker extends Worker.Abstract {

public getUrl(): string {
if (!this.url) {
throw new Error('app url not set')
throw new Error('app url not set');
}

return this.url;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/lib/util/app-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class AppCommand extends Cli.Command {
body: JSON.stringify({
name: this.app.config.name,
app_url: this.app.config.app_url,
redirect_urls: this.app.config.redirect_urls
redirect_urls: this.app.config.redirect_urls,
}),
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/lib/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function setupColorMode(): void {
}

function errorHandler(error: Error): never {
let suggestions: string[] = ['Run the command again'];
let suggestions: string[] = [];
const message: string = error.message;

if (error instanceof CommandError && error.suggestions) {
Expand Down
6 changes: 5 additions & 1 deletion packages/cli-kit/lib/node/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,15 @@ export async function authenticate(command: Cli.Command): Promise<StoreSession>

const accessToken = await exchange(code, verifier);

const store = await Http.get<{ id: string; slug: string }>(
const store = await Http.get<{ id: string; slug: string; is_dev?: boolean }>(
`${Env.apiHostname()}/me`,
{ headers: { Authorization: `Bearer ${accessToken}` } },
);

if (!store.is_dev) {
throw new Error('The CLI can only be used with dev stores, you create one through YouCan Partners.');
}

const session = {
slug: store.slug,
id: store.id,
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/lib/cli/commands/theme/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Dev extends ThemeCommand {
},
{
title: 'Syncing theme files, please wait...',
async task(ctx) {
async task() {
for (const type of THEME_FILE_TYPES) {
const descriptors = theme.metadata![type] as FileDescriptor[] ?? [];
const directory = Path.resolve(theme.root, type);
Expand Down
4 changes: 2 additions & 2 deletions packages/theme/lib/cli/services/dev/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class ThemeWorker extends Worker.Abstract {

private enqueue(op: 'save' | 'delete', type: typeof THEME_FILE_TYPES[number], name: string): void {
this.queue.push(async () => {
await this.execute(op, type, name, true);
await this.execute(op, type, name);

debounce(() => {
this.io.emit('theme:update');
Expand All @@ -105,7 +105,7 @@ export default class ThemeWorker extends Worker.Abstract {
});
}

private async execute(op: 'save' | 'delete', type: typeof THEME_FILE_TYPES[number], name: string, log = false): Promise<void> {
private async execute(op: 'save' | 'delete', type: typeof THEME_FILE_TYPES[number], name: string): Promise<void> {
return execute(this.theme, op, type, name, this.logger);
}
}

0 comments on commit 5bfaa00

Please sign in to comment.