eny.space Landingpage
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(api): use correct env vars instead of testing stuff

+51 -29
+9
.env.local.example
··· 1 1 NEXT_PUBLIC_APP_URL=http://localhost:3000 2 2 3 + # PDS management API 4 + PDS_API_BASE_URL=https://your-backend.url/ 5 + PDS_API_TOKEN=your_token_here 6 + PDS_TEST_SERVICE_ID= 7 + # Set to "true" to force all users to PDS_TEST_SERVICE_ID (dev only) 8 + PDS_FORCE_SERVICE_ID=false 9 + # Set to "true" to use mock PDS data instead of the real API 10 + PDS_USE_MOCK=false 11 + 3 12 # Prelaunch feature flag. 4 13 # When `true`, hide elements intended to ship only after launch. 5 14 NEXT_PUBLIC_PRELAUNCH=false
+20 -18
app/api/pds/atproto/create-account/route.ts
··· 19 19 if (!body?.handle || !body?.password || !body?.inviteCode) { 20 20 return NextResponse.json( 21 21 { message: "Missing required fields: handle, password, inviteCode" }, 22 - { status: 400 }, 22 + { status: 400 } 23 23 ); 24 24 } 25 25 26 26 const { service, pdsServiceId } = await getPdsServiceForCurrentUser(); 27 27 28 - const requiredServiceIdRaw = process.env.NEXT_PUBLIC_PDS_TEST_SERVICE_ID; 28 + const requiredServiceIdRaw = process.env.PDS_TEST_SERVICE_ID; 29 29 if (requiredServiceIdRaw) { 30 30 const requiredServiceId = Number(requiredServiceIdRaw); 31 31 if (pdsServiceId !== requiredServiceId) { ··· 33 33 { 34 34 message: `PDS service id mismatch: expected ${requiredServiceId}, got ${pdsServiceId}`, 35 35 }, 36 - { status: 409 }, 36 + { status: 409 } 37 37 ); 38 38 } 39 39 } ··· 52 52 53 53 if (!user?.email) { 54 54 return NextResponse.json( 55 - { message: "Missing email (neither request body nor Supabase user email found)" }, 56 - { status: 400 }, 55 + { 56 + message: 57 + "Missing email (neither request body nor Supabase user email found)", 58 + }, 59 + { status: 400 } 57 60 ); 58 61 } 59 62 ··· 66 69 const res = await fetch( 67 70 `${pdsBaseUrl}/xrpc/com.atproto.server.createAccount`, 68 71 { 69 - method: "POST", 70 - headers: { 71 - "Content-Type": "application/json", 72 - }, 73 - body: JSON.stringify({ 74 - email: emailToUse, 75 - handle: body.handle, 76 - password: body.password, 77 - inviteCode: body.inviteCode, 78 - }), 79 - }, 72 + method: "POST", 73 + headers: { 74 + "Content-Type": "application/json", 75 + }, 76 + body: JSON.stringify({ 77 + email: emailToUse, 78 + handle: body.handle, 79 + password: body.password, 80 + inviteCode: body.inviteCode, 81 + }), 82 + } 80 83 ); 81 84 82 85 const contentType = res.headers.get("content-type") || ""; ··· 87 90 if (!res.ok) { 88 91 return NextResponse.json( 89 92 { message: "Failed to create account", status: res.status, payload }, 90 - { status: 502 }, 93 + { status: 502 } 91 94 ); 92 95 } 93 96 ··· 103 106 return NextResponse.json({ message }, { status }); 104 107 } 105 108 } 106 -
+1 -1
app/api/pds/atproto/create-session/route.ts
··· 21 21 22 22 const { service, pdsServiceId } = await getPdsServiceForCurrentUser(); 23 23 24 - const requiredServiceIdRaw = process.env.NEXT_PUBLIC_PDS_TEST_SERVICE_ID; 24 + const requiredServiceIdRaw = process.env.PDS_TEST_SERVICE_ID; 25 25 if (requiredServiceIdRaw) { 26 26 const requiredServiceId = Number(requiredServiceIdRaw); 27 27 if (pdsServiceId !== requiredServiceId) {
+7 -1
app/api/pds/atproto/helpers.ts
··· 1 1 import { createClient } from "@/lib/supabase/server"; 2 2 3 - const PDS_API_BASE_URL = "https://k8s-pds.frx.pub/api/v1"; 3 + const PDS_API_BASE_URL = process.env.PDS_API_BASE_URL; 4 4 5 5 function parseMaybeDoubleEncodedJson(input: unknown) { 6 6 if (typeof input === "string") { ··· 45 45 if (!pdsServiceId) { 46 46 return Promise.reject( 47 47 Object.assign(new Error("No provisioned PDS found for this user"), { status: 404 }), 48 + ); 49 + } 50 + 51 + if (!PDS_API_BASE_URL) { 52 + return Promise.reject( 53 + Object.assign(new Error("Missing PDS_API_BASE_URL env var"), { status: 500 }), 48 54 ); 49 55 } 50 56
+1 -7
app/api/pds/atproto/invite/route.ts
··· 1 1 import { NextResponse } from "next/server"; 2 2 3 - import { createHash } from "crypto"; 4 - 5 3 import { getPdsBaseUrlFromService, getPdsServiceForCurrentUser } from "../helpers"; 6 4 7 5 function toBasicAuth(user: string, pass: string) { ··· 13 11 const { useCount } = (await req.json()) as { useCount?: number }; 14 12 15 13 const { service, pdsServiceId } = await getPdsServiceForCurrentUser(); 16 - const requiredServiceIdRaw = process.env.NEXT_PUBLIC_PDS_TEST_SERVICE_ID; 14 + const requiredServiceIdRaw = process.env.PDS_TEST_SERVICE_ID; 17 15 if (requiredServiceIdRaw) { 18 16 const requiredServiceId = Number(requiredServiceIdRaw); 19 17 if (pdsServiceId !== requiredServiceId) { ··· 38 36 } 39 37 40 38 const trimmedAdminPassword = String(adminPassword).trim(); 41 - const adminPasswordHashPrefix = createHash("sha256") 42 - .update(trimmedAdminPassword) 43 - .digest("hex") 44 - .slice(0, 10); 45 39 46 40 // PDS scripts use `admin:${PDS_ADMIN_PASSWORD}` 47 41 const authHeader = toBasicAuth("admin", trimmedAdminPassword);
+8 -1
app/api/pds/service/route.ts
··· 2 2 3 3 import { createClient } from "@/lib/supabase/server"; 4 4 5 - const PDS_API_BASE_URL = "https://k8s-pds.frx.pub/api/v1"; 5 + const PDS_API_BASE_URL = process.env.PDS_API_BASE_URL; 6 6 7 7 function getMockService() { 8 8 const now = new Date(); ··· 92 92 const useMock = process.env.PDS_USE_MOCK === "true"; 93 93 if (useMock) { 94 94 return NextResponse.json(getMockService()); 95 + } 96 + 97 + if (!PDS_API_BASE_URL) { 98 + return NextResponse.json( 99 + { error: "Missing PDS_API_BASE_URL env variable" }, 100 + { status: 500 } 101 + ); 95 102 } 96 103 97 104 const apiToken = process.env.PDS_API_TOKEN;
+5 -1
app/api/webhooks/route.ts
··· 7 7 import { stripe } from "@/lib/stripe"; 8 8 import { createAdminClient } from "@/lib/supabase/admin"; 9 9 10 - const PDS_API_BASE_URL = "https://k8s-pds.frx.pub/api/v1"; 10 + const PDS_API_BASE_URL = process.env.PDS_API_BASE_URL; 11 11 12 12 function normalizeSlug(value: string) { 13 13 return value ··· 51 51 pdsHostnameBase: string; 52 52 disksizeGb: string; 53 53 }) { 54 + if (!PDS_API_BASE_URL) { 55 + throw new Error("Missing PDS_API_BASE_URL env var"); 56 + } 57 + 54 58 const apiToken = process.env.PDS_API_TOKEN; 55 59 if (!apiToken) { 56 60 throw new Error("Missing PDS_API_TOKEN env var");