feat(cli): command architecture — agents, missions, gateway-aware prdy (#158)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #158.
This commit is contained in:
29
packages/cli/src/commands/with-auth.ts
Normal file
29
packages/cli/src/commands/with-auth.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { AuthResult } from '../auth.js';
|
||||
|
||||
export interface AuthContext {
|
||||
gateway: string;
|
||||
session: AuthResult;
|
||||
cookie: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and validate the user's auth session.
|
||||
* Exits with an error message if not signed in or session expired.
|
||||
*/
|
||||
export async function withAuth(gateway: string): Promise<AuthContext> {
|
||||
const { loadSession, validateSession } = await import('../auth.js');
|
||||
|
||||
const session = loadSession(gateway);
|
||||
if (!session) {
|
||||
console.error('Not signed in. Run `mosaic login` first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const valid = await validateSession(gateway, session.cookie);
|
||||
if (!valid) {
|
||||
console.error('Session expired. Run `mosaic login` again.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return { gateway, session, cookie: session.cookie };
|
||||
}
|
||||
Reference in New Issue
Block a user