Skip to content

Commit

Permalink
fix env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoperra committed Oct 20, 2024
1 parent fc41ef1 commit ce35e86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
23 changes: 19 additions & 4 deletions packages/app/src/lib/scratchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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),
Expand Down
11 changes: 2 additions & 9 deletions packages/app/src/lib/server/appwrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ce35e86

Please sign in to comment.