• I know there’s a way to auto-login after register, but when doing this it automatically 302 Redirects me to some other page – I’m doing this all with API requests and I don’t want to be redirected to some HTML page.

    Instead I’d like Register and then auto auth such that I get back a JWT that I can then continue to use on other API requests.

    Alternatively – can there be an option to not redirect, but instead return a JSON response?

    Is there a way to set this up?

    • This topic was modified 4 years, 3 months ago by jamiechong.
    • This topic was modified 4 years, 3 months ago by jamiechong.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author nicu_m

    (@nicu_m)

    Hello @jamiechong,

    Currently the option for not redirecting.

    But, as a workaround, you can make 2 calls:
    1. register user
    2. /auth with the credentials and here you can get the JWT.

    Also, there is a hook that is triggered after the user: simple_jwt_login_redirect_hook.

    You can do something like this:

    
    add_action('simple_jwt_login_redirect_hook', function($url, $request){
    	header('Content-type: application/json');
           //TODO: make a curl to /auth endpoint and get the JWT
    	echo json_encode(['status' => true, 'data' => ['jwt' => 'your generated JWT']);
    	die();
    },10,2 );
    

    PS: don’t forget to enable this hook from plugin settings -> Hooks.

    Let me know if this fits for you.

    Best regards,
    Nicu.

    Plugin Author nicu_m

    (@nicu_m)

    Also, I will add this feature to my todo-list.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Register Auto-Auth (not auto-login)’ is closed to new replies.