Hi, I am trying to stop a hook being called after insert, but the supressHooks seems not working well.
let toInsert = {
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
let options = {
"suppressAuth": true,
"suppressHooks": true,
};
wixData.insert("bid", toInsert, options)
//data.js
export function bid_afterInsert(item, context) {
//TODO: write your code here...
console.log("hook fired")
return(item)
}
I tried to switch “supressHooks” to be true and false, but the hook runs anyways, what should I do?
If you are using Wix Data API and it’s Insert function, then it will as the insert() function triggers the beforeInsert() and afterInsert() hooks if they have been defined.
https://www.wix.com/corvid/reference/wix-data.html#insert
Use the options parameter to run insert() from backend code without checking for permissions or without its registered hooks.
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions
The options parameter can only be used in backend code. Permission checks and hooks always run for wix-data functions called from Page, Site and Public code.
import wixData from 'wix-data';
// ...
let options = {
"suppressAuth": true,
"suppressHooks": true
};
// rest of your code.....
Thank you, it works perfectly when I put the code in backend code