Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions apps/http-backend/src/routes/userRoutes/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ router.get(
message: "Incorrect type Input",
});
}
const exec = new GoogleSheetsNodeExecutor()

// Check if credentials exist in database
const credentials = await prismaClient.credential.findMany({
where: {
userId: userId,
type: type,
},
});
// const credentials = await prismaClient.credential.findMany({
// where: {
// userId: userId,
// type: type,
// },
// });
const credentials = await exec.getAllCredentials(userId, type)

// if (credentials.length === 0) {
// // No credentials found - return the correct auth URL
Expand Down Expand Up @@ -522,17 +524,19 @@ router.post(
// Config must be valid JSON (not an empty string)
// const stage = dataSafe.data.Position
console.log("This is from the backend log of positions", dataSafe.data.position)
const { credentialId, ...restConfig } = dataSafe.data.Config;
const createdNode = await prismaClient.node.create({
data: {
name: dataSafe.data.Name,
workflowId: dataSafe.data.WorkflowId,
config: dataSafe.data.Config || {},
config: restConfig || {},
stage: Number(dataSafe.data.stage ?? 0),
position: {
x: dataSafe.data.position.x,
y: dataSafe.data.position.y
},
AvailableNodeID: dataSafe.data.AvailableNodeId,
CredentialsID: credentialId
},
});

Expand Down Expand Up @@ -570,12 +574,13 @@ router.put(
message: "Invalid input",
});
}

const { credentialId, ...restConfig } = dataSafe.data.Config;
const updateNode = await prismaClient.node.update({
where: { id: dataSafe.data.NodeId },
data: {
position: dataSafe.data.position,
config: dataSafe.data.Config,
config: restConfig,
CredentialsID: credentialId
},
});

Expand Down
18 changes: 9 additions & 9 deletions apps/web/app/hooks/useCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ export const useCredentials = (type: string, workflowId?: string): any => {
// Backend should ONLY return stored credentials
if (Array.isArray(response)) {
setCred(response);
} else {
setCred([]);
} else if(typeof response === "string"){
setAuthUrl(response)
}

// Frontend defines where to redirect for OAuth
if (type === "google") {
const baseUrl = `${BACKEND_URL}/oauth/google/initiate`;
const url = workflowId ? `${baseUrl}?workflowId=${workflowId}` : baseUrl;
setAuthUrl(url);
} else {
setAuthUrl(null);
}
// if (type === "google") {
// const baseUrl = `${BACKEND_URL}/oauth/google/initiate`;
// const url = workflowId ? `${baseUrl}?workflowId=${workflowId}` : baseUrl;
// setAuthUrl(url);
// } else {
// setAuthUrl(null);
// }
} catch (e) {
console.log(
e instanceof Error
Expand Down