Java Script Code to Trigger a Function Call

Site domain:
netlify site name: celebrated-daffodil-98560f

I am informed by the community that I need to trigger a function call when users log in so that they are led to my terms & conditions page after logging into my website. I am only skilled in copying and pasting script. What steps and exact code do I need to establish this function?

@MM6th Someone here might be kind enough to help, in particular if they already have similar code on their own site.

But failing that you might want to try and reach out to a freelancer, or skill up yourself by googling around.

It’s probably going to be a bit hard if you have to constantly source pieces of your code from generous forum contributors.

1 Like

I will second what @nathanmartin has said, as this forum is not intended as a place to find code to build your site, but help troubleshoot the code you have.

There are three event triggers for identity. I don’t believe any are going to do what you want as (from my usage at least) the only likely candidate (the identity-login trigger) still needs to return a response with user metadata in order to succeed. If it didn’t, you could then use the Location header to redirect a user to a specific location. However, I don’t believe this will work.

If you look at the Netlify Identity Widget usage you will see there is a way of executing code on certain events, such as login, e.g.

netlifyIdentity.on('login', user => console.log('login', user));

It is possible to use this to redirect a use to a certain page on successful login.

I do wonder about the redirecting to a T&C page as this is something I would have thought a user would have agreed to prior to signing up and not need to read every time they log in.

You might wish to check out freeCodeCamp to upskill so you don’t need to rely on copy/pasting code.

1 Like

Thanks for the tip Nathan. I do however learn better from copy and pasted because I’m then able to pick apart the code and learn what makes what function by testing in beta mode. People learn differently, like I can ready netlify’s instructions and leave more confused than when I came.

@coelmay I may be fairly new, but I have gotten code from supporters here. You did provide code for me though, so thank you but I can do without the lecture. The T&C page is only for testing purposes, that won’t be how the final flow will go. I see you are big on earning stuff, and I’m no stranger to hard work although I rather work smarter than harder. I will therefore utilize the free code camp link. You’ve made asking for help … different.

I didn’t think I was lecturing anyone.

Not sure what you are inferring here. Care to elaborate?

Are you suggesting I don’t work hard? I don’t believe I was suggesting you don’t.


you are welcome to share your honest opinions about approaches and learning styles, but do take extra care to not belittle or unfairly criticise anyone who disagrees with you. This is not stackoverflow, explicitly not.

For your information, Coel is one of our most cherished and respected volunteers here in the forums, who spends hours per week, unpaid, assisting people from all backgrounds and with all different levels of expertise. He doesn’t have to do it, he isn’t paid to do it, we are lucky he chooses to spend his time this way. Let’s not spoil that by being rude.