mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Refactor Neon authentication logic
This commit is contained in:
5
.changeset/great-trains-cry.md
Normal file
5
.changeset/great-trains-cry.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
Refactor Neon authentication logic
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user