### Custom code prehook setup br Creating a custom prehook can be done in several easy steps: 1. Head over to your prehooks tab [ENVIRONMENT] → Prehooks, and press the **Create Prehook** button to create a new prehook. br ![test](/assets/prehook-dashboard.5085066ae9f0a1fd1267a3bdc077935bc6d4601791eac53b263a7f2b456e7ec5.97d793c5.png) br 1. Define your required settings, e.g., trigger event, prehook type (in our case, it would be a **Custom code** prehook), the prehook's timeout, etc. br ![test](/assets/create-a-prehook.238fa1c391fe4e09be5ed06bb8319b757fca7bbd0ed1806c29ae2d53bec04640.97d793c5.png) br 1. Test your prehook before activation. br ![test](/assets/test-custom-hook.fe0cab2621ce311a922b689594b165d204cea7bde644ee28e9b96fafd4749918.97d793c5.png) ### Custom prehook use case Custom prehooks extend your existing Frontegg flows to allow you to customize your user journey further. The following example demonstrates how to customize a prehook for a user authentication flow with the ability to control the `verdict` (see possible verdicts in the [prehooks](/ciam/guides/integrations/prehooks) topic) of the user after opting to log in. Note that this option has a predefined template that you can use. The following code sample checks if an email address provided during a sign-up event is valid and belongs to an allowed domain. If the email is invalid or not from an allowed domain, it blocks the sign-up process; otherwise, it allows the user to proceed with the flow. ```javascript const ALLOWED_DOMAINS = ['gmail.com']; /** * Handle the event * @param {SignUpEventData} eventData - the event details * @returns {Promise} event handler response */ async function onEvent(eventData) { // ensure user email is present if (!eventData.data.user.email) { // note that userMessage (the second parameter) is displayed in red on the failed sign-up prompt return { continue: false, verdict: "block", error: { status: 400, message: ["Email is invalid"] } } } // ensure a reasonable format for the email const splitEMail = eventData.data.user.email.split('@'); if (splitEMail.length !== 2) { // note that userMessage (the second parameter) is displayed in red on the failed sign-up prompt return { continue: false, verdict: "block", error: { status: 400, message: ["Email is invalid"] } } } // if the email domain is not explicitly in our allow list, deny access const domain = splitEMail[1].toLowerCase(); if (ALLOWED_DOMAINS.indexOf(domain) < 0) { // note that userMessage (the second parameter) is displayed in red on the failed sign-up prompt return { continue: false, verdict: "block", error: { status: 400, message: ["Email is not allowed"] } } } return { continue: true, verdict: "allow", response: {} } } exports.onEvent = onEvent; ``` ### Single prehook view After testing and creating your prehook, you can view/change its settings and monitor its performance. Trigger event change Note that you can't change your hook's trigger event after initiating its connection. br ![test](/assets/hook-settings-view-1.b4faaef849d513e4974b23f43911b60f8971bc3363be31857fc8dc4ae2c3b27e.97d793c5.png) br