0

I have a custom login, in which I have 2 apis: The first to post a user phone, and the second to post the user pin to verify the phone.

The main issues is that these 2 apis, which has the following url (domain.com/api/user/verify_phone) are not working because they are redirected to the /login page.

When I call the same url after the user is authenticated it works... but I need it before the login of course. How can I do that? Please help!

I may found that the bug in the functions.php on the theme, there I have created a function to handle all the redirections of the login, this is the code:

function login_redirect(){
global $pagenow;
     if( 'wp-admin' != preg_split('/\//',$_SERVER['REQUEST_URI'])[1] ){
        if(preg_split('/\//',$_SERVER['REQUEST_URI'])[1] == '/api/'){
            exit();
        }else if( $_SERVER['REQUEST_URI'] != '/login/') {
            if (!checkUserStatus()){
                wp_redirect('https://learn.fractalup.com/login/');
                exit();
            }
        }
 }
add_action('parse_request','login_redirect');

So with these I try to redirect all call to make sure users log in and I tried to make the apis call go through but there are still giving a 302 redirection error. PLEASE HELP!

  • 2
    How are those APIs implemented? There's no code in your question – Tom J Nowell Jan 6 at 2:33
1

I think this is just a slight mistake on your "if" condition

$result = preg_split('/\//','domain.com/api/user/verify_phone');
var_dump($result);

Results in:

array(4) {
  [0]=>
  string(10) "domain.com"
  [1]=>
  string(3) "api"
  [2]=>
  string(4) "user"
  [3]=>
  string(12) "verify_phone"
}

So the result at [1] is "api", but you are checking for "/api/" on the fourth line of your code sample.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.