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 ce35e86 commit d71723c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
39 changes: 14 additions & 25 deletions packages/app/src/lib/scratchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import {
import {adjectives, colors, uniqueNamesGenerator} from 'unique-names-generator';
import type {EditorParsedRepository} from '../components/Editor/editor.context';

const databaseId = import.meta.env.VITE_APPWRITE_CLOUD_DATABASE_ID;
const scratchCollectionId = import.meta.env
.VITE_APPWRITE_CLOUD_SCRATCH_COLLECTION_ID;
function getScratchAppwriteVars() {
'use server';
return {
databaseId: process.env.APPWRITE_CLOUD_DATABASE_ID!,
scratchCollectionId: process.env.APPWRITE_CLOUD_SCRATCH_COLLECTION_ID!,
};
}

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 {databaseId, scratchCollectionId} = getScratchAppwriteVars();
const user = await getLoggedInUser();
if (!user) {
return;
Expand All @@ -39,9 +41,7 @@ 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 {databaseId, scratchCollectionId} = getScratchAppwriteVars();
const user = await getLoggedInUser();

if (!user) {
Expand Down Expand Up @@ -112,9 +112,7 @@ 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 {databaseId, scratchCollectionId} = getScratchAppwriteVars();
const user = await getLoggedInUser();
if (!user) {
return;
Expand Down Expand Up @@ -168,13 +166,8 @@ export const deleteScratch = action(async scratchId => {
return;
}

const client = new Client()
.setProject('6713d930003dd483eb11')
.setEndpoint('https://cloud.appwrite.io/v1')
.setSelfSigned(true)
.setSession(user.$id);

const database = new Databases(client);
const {database} = await createSessionClient();
const {databaseId, scratchCollectionId} = getScratchAppwriteVars();

return json(
await database.deleteDocument(databaseId, scratchCollectionId, scratchId),
Expand All @@ -186,9 +179,7 @@ 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!;
const {databaseId, scratchCollectionId} = getScratchAppwriteVars();

try {
return await database.getDocument(databaseId, scratchCollectionId, id);
Expand All @@ -203,9 +194,7 @@ 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 {databaseId, scratchCollectionId} = getScratchAppwriteVars();
const {database} = await createSessionClient();
return database.listDocuments(databaseId, scratchCollectionId, [
Query.equal('userId', user.$id),
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/lib/server/appwrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export const signupWithGithub = action(async () => {
const {account} = await createAdminClient();

const origin = getHeaders().origin;
const successUrl = `https://pipelineui.dev/api/oauth`;
const failureUrl = `https://pipelineui.dev/`;
const successUrl = `${origin}/api/oauth`;
const failureUrl = `${origin}/`;

try {
const redirectUrl = await account.createOAuth2Token(
Expand Down

0 comments on commit d71723c

Please sign in to comment.