Refactor Neon authentication logic

This commit is contained in:
Aman Varshney
2025-06-07 10:30:02 +05:30
parent c69e7222fd
commit ded8f89f3d
3 changed files with 6 additions and 40 deletions

View File

@@ -58,32 +58,6 @@ async function executeNeonCommand(
}
}
async function isNeonAuthenticated(packageManager: PackageManager) {
try {
const commandArgsString = "neonctl projects list";
const result = await executeNeonCommand(packageManager, commandArgsString);
return (
!result.stdout.includes("not authenticated") &&
!result.stdout.includes("error")
);
} catch {
return false;
}
}
async function authenticateWithNeon(packageManager: PackageManager) {
try {
await executeNeonCommand(
packageManager,
"neonctl auth",
"Authenticating with Neon...",
);
return true;
} catch (_error) {
consola.error(pc.red("Failed to authenticate with Neon"));
}
}
async function createNeonProject(
projectName: string,
regionId: string,
@@ -153,19 +127,8 @@ DATABASE_URL="your_connection_string"`);
export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
const { packageManager, projectDir } = config;
const setupSpinner = spinner();
setupSpinner.start("Checking Neon authentication...");
try {
const isAuthenticated = await isNeonAuthenticated(packageManager);
setupSpinner.stop("Neon authentication checked");
if (!isAuthenticated) {
log.info("Please authenticate with Neon to continue:");
await authenticateWithNeon(packageManager);
}
const suggestedProjectName = path.basename(projectDir);
const projectName = await text({
message: "Enter a name for your Neon project:",
@@ -204,8 +167,6 @@ export async function setupNeonPostgres(config: ProjectConfig): Promise<void> {
finalSpinner.stop("Neon database configured!");
} catch (error) {
setupSpinner.stop(pc.red("Neon authentication check failed"));
if (error instanceof Error) {
consola.error(pc.red(error.message));
}

View File

@@ -3,7 +3,7 @@ import Loader from "@/components/loader";
import { ThemeProvider } from "@/components/theme-provider";
import { Toaster } from "@/components/ui/sonner";
{{#if (eq api "orpc")}}
import { link, orpc, ORPCContext } from "@/utils/orpc";
import { link, orpc } from "@/utils/orpc";
import type { QueryClient } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { useState } from "react";