Home > Mobile >  how to change the status code in Codeigniter 4 To push pages in ReactJS
how to change the status code in Codeigniter 4 To push pages in ReactJS

Time:03-12

I am using CI4 as backend and react Js as front end and I am doing authentication so after the authentication I want to push the user to other pages if the credentials are correct if not then go just refresh the same page

I understood how to change the pages but now the problem is that this code gives the status 200 for everything even if the credentials are not correct so what should I do to make the status change from true to false as I am using if the response is true push to another page

public function loginAuth()
    {
        $session = session();
        $userModel = new UserModel();
        $email = $this->request->getVar('email');
        $password = $this->request->getVar('password');
        
        $data = $userModel->where('email', $email)->first();
        
        if($data){
            $pass = $data['password'];
            $authenticatePassword = password_verify($password, $pass);
            if($authenticatePassword){
                $ses_data = [
                    'id' => $data['id'],
                    'name' => $data['name'],
                    'email' => $data['email'],
                    'isLoggedIn' => TRUE
                ];
                $session->set($ses_data);
                return redirect()->to('/');
            
            }else{
                $session->setFlashdata('msg', 'Password is incorrect.');
                // return redirect()->to('/signin');
            }
        }else{
            $session->setFlashdata('msg', 'Email does not exist.');
            // return redirect()->to('/signin');
        }
    }

this is the code and now I want that after the success it should push to a different page but the problem is that it gives true to all the conditions and I can not do anything if all of the conditions get statusCode=200

CodePudding user response:

I have found a way to do this first just use react-router to push to another page if your validation function is true then change the status for the other conditions to

        $model = new UserModel();
        $user  = $model->save($this->request->getPost());

        // Respond with 201 status code
        return $$this->fail($errors, 400);

and I think it will work for you

CodePudding user response:

i'm also still looking for the solution

  • Related