From ce35e86830170b86cdf7600445224ddf530f73d5 Mon Sep 17 00:00:00 2001 From: riccardoperra Date: Sun, 20 Oct 2024 21:28:56 +0200 Subject: [PATCH] fix env variables --- packages/app/src/lib/scratchApi.ts | 23 +++++++++++++++++++---- packages/app/src/lib/server/appwrite.ts | 11 ++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/app/src/lib/scratchApi.ts b/packages/app/src/lib/scratchApi.ts index 602ee6c..4aa5608 100644 --- a/packages/app/src/lib/scratchApi.ts +++ b/packages/app/src/lib/scratchApi.ts @@ -14,14 +14,19 @@ const scratchCollectionId = import.meta.env export const updateScratch = action(async (id: string, newCode: string) => { 'use server'; + const projectId = process.env.VITE_APPWRITE_CLOUD_PROJECT_ID!; + const endpoint = process.env.VITE_APPWRITE_CLOUD_URL!; + const databaseId = process.env.VITE_APPWRITE_CLOUD_DATABASE_ID!; + const scratchCollectionId = + process.env.VITE_APPWRITE_CLOUD_SCRATCH_COLLECTION_ID!; const user = await getLoggedInUser(); if (!user) { return; } const client = new Client() - .setProject('6713d930003dd483eb11') - .setEndpoint('https://cloud.appwrite.io/v1') + .setProject(projectId) + .setEndpoint(endpoint) .setSelfSigned(true) .setSession(user.$id); @@ -34,7 +39,9 @@ export const updateScratch = action(async (id: string, newCode: string) => { export const createScratch = action(async () => { 'use server'; - + const databaseId = process.env.VITE_APPWRITE_CLOUD_DATABASE_ID!; + const scratchCollectionId = + process.env.VITE_APPWRITE_CLOUD_SCRATCH_COLLECTION_ID!; const user = await getLoggedInUser(); if (!user) { @@ -105,7 +112,9 @@ export const createScratchFork = action( initialCode: string, ) => { 'use server'; - + const databaseId = process.env.VITE_APPWRITE_CLOUD_DATABASE_ID!; + const scratchCollectionId = + process.env.VITE_APPWRITE_CLOUD_SCRATCH_COLLECTION_ID!; const user = await getLoggedInUser(); if (!user) { return; @@ -177,6 +186,9 @@ export const getScratch = cache(async (id: string) => { 'use server'; const {database} = await createAdminClient(); + const databaseId = process.env.VITE_APPWRITE_CLOUD_DATABASE_ID!; + const scratchCollectionId = + process.env.VITE_APPWRITE_CLOUD_SCRATCH_COLLECTION_ID!; try { return await database.getDocument(databaseId, scratchCollectionId, id); @@ -191,6 +203,9 @@ export const listUserScratches = cache(async () => { if (!user) { return {documents: [], total: 0}; } + const databaseId = process.env.VITE_APPWRITE_CLOUD_DATABASE_ID!; + const scratchCollectionId = + process.env.VITE_APPWRITE_CLOUD_SCRATCH_COLLECTION_ID!; const {database} = await createSessionClient(); return database.listDocuments(databaseId, scratchCollectionId, [ Query.equal('userId', user.$id), diff --git a/packages/app/src/lib/server/appwrite.ts b/packages/app/src/lib/server/appwrite.ts index 0a288d2..0e06d11 100644 --- a/packages/app/src/lib/server/appwrite.ts +++ b/packages/app/src/lib/server/appwrite.ts @@ -3,11 +3,10 @@ import {getHeaders} from 'vinxi/http'; import {getSession} from './session'; import {action, redirect} from '@solidjs/router'; -const projectId = import.meta.env.VITE_APPWRITE_CLOUD_PROJECT_ID; -const endpoint = import.meta.env.VITE_APPWRITE_CLOUD_URL; - export async function createSessionClient() { 'use server'; + const projectId = process.env.VITE_APPWRITE_CLOUD_PROJECT_ID!; + const endpoint = process.env.VITE_APPWRITE_CLOUD_URL!; const client = new Client().setProject(projectId).setEndpoint(endpoint); const session = await getSession(); if (!session || !session.data.session?.$id) { @@ -42,12 +41,6 @@ export async function createAdminClient() { const projectId = process.env.VITE_APPWRITE_CLOUD_PROJECT_ID!; const endpoint = process.env.VITE_APPWRITE_CLOUD_URL!; - console.log({ - apiKey, - projectId, - endpoint, - }); - const client = new Client() .setProject(projectId) .setEndpoint(endpoint)