I’ve installed a trigger in my Neo4j database (version 4.4.36) to automatically add the creation date to every newly created node. However, when I submit a form from my Next.js app, the app freezes, and the creation_date property is not being added to the newly created node.
Here’s the trigger I’ve installed:
CALL apoc.trigger.install('db_bale', 'add_creation_date', 'UNWIND $createdNodes AS n SET n.creation_date = $commitTime', {phase:'after'});
and here is the relevant part of my register action in nextJS app
"use server";
import * as z from "zod";
import { RegisterSchema } from "@/schemas";
import driver from "@/app/utils/noe4j";
import { DBLabels, UserPrivileges } from "@/globals/types";
export const register = async (values: z.infer<typeof RegisterSchema>) => {
// ...
const session = driver.session({ database: "qalam" });
const query = `
MERGE (counter: ${DBLabels.ID_COUNTER} {label: '${DBLabels.USER}'})
ON CREATE SET counter.last_id = 0
WITH counter
CREATE (user: ${DBLabels.USER} {
user_name: $user_name,
first_name: $first_name,
last_name: $last_name,
email: $email,
password: $password,
privileges: $privileges
})
WITH user, counter
CALL apoc.atomic.add(counter, 'last_id', 1) YIELD newValue
SET user.user_id = newValue
RETURN user
`;
const results = await session.executeWrite(async (tx) => {
return tx.run(query, { ...new_user });
});
// ...
};
I’ve also checked the /etc/neo4j/apoc.conf file, and it contains the following configuration which I copied from the documentation of apoc triggers:
apoc.trigger.enabled=true
apoc.trigger.refresh=60000
also in `neo4j.conf’, I added this two lines
dbms.security.procedures.allowlist=apoc.*
dbms.security.procedures.unrestricted=apoc.*
When I execute the MATCH (n) RETURN n query in the Neo4j browser, I can see that a new user is created, but the creation_date property is missing.
Can you please help me understand why the trigger is not working as expected and the Next.js app is freezing?
I tried to change the default refresh time to 1000, but the same problem happens