Elffuss BraidHub

kikocis/continue public

main · 612 BRawPermalink
1import chalk from "chalk";
2
3import { isAuthenticated, login } from "./workos.js";
4
5/**
6 * Ensures the user is authenticated before proceeding
7 * Returns true if authentication is successful, false otherwise
8 */
9export async function ensureAuthenticated(
10 requireAuth: boolean = true,
11): Promise<boolean> {
12 if (isAuthenticated()) {
13 return true;
14 }
15
16 if (!requireAuth) {
17 return false;
18 }
19
20 console.info(chalk.yellow("Authentication required."));
21
22 try {
23 await login();
24 return true;
25 } catch (error) {
26 console.error(chalk.red("Failed to authenticate."), error);
27 return false;
28 }
29}