Jump to content

Users hook not firing


DrQuincy
 Share

Recommended Posts

I have a default front-end user field call approved that is a true|false switch. I want to redirect them to a URL is not yet manually approved. I have this hook in $config->prependTemplateFile file.

wire()->addHookBefore('Users::login', function($event) {

    $user = $event->arguments[0];

	$user->of(true);

    if($user->approved === false) {

		// Prevent login
        $event->return = false; 

		wire('session')->redirect('/account/?approved=0');

    }
	
});

But it does not fire. Do I have the hook wrong or is it in the wrong place? The file itself is definitely being included and if I replace the contents of the hook to a simple exit statement, still nothing happens.

EDIT: I am using LoginRegisterPro, are the hooks different?

Edited by DrQuincy
Link to comment
Share on other sites

That's great, thanks, I'm definitely going to try that. 🙂

I do want to know why the User hooks aren't firing but in case anyone is using LRP and wondering the same, I have made what I need to do work with the following hooks:

  1. LoginRegisterPro::createdUser: use this to send an admin email to let the site owner know that a new user has registered
  2. LoginRegisterProLogin::success: used to set approved=0 on $user

More info here: https://processwire.com/store/login-register-pro/docs/#hooks

Edited by DrQuincy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...