Codeigniter 4 Rest API Session based Authentication

Published

While accessing codeigniter api via Angular am not getting session variables which already set during login.

 $routes->add('test', 'Users::test',["filter" => "basicAuth"]);

Also filters were used..

if(!$session->get('isLoggedIn')){ 
    $data = [
        'status'    => 401,
        'success'   => false,
        'message'   => session()->get('isLoggedIn'),
    ];
    return Services::response()
    ->setStatusCode(ResponseInterface::HTTP_UNAUTHORIZED)
    ->setContentType('application/json')
    ->setJSON($data);
}

if i use browser it’s working as expected,
but via angular it’s not working, if i print Session()->get() not getting any results.

Source: Angular Questions

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq