Skip to content

Commit

Permalink
fix(authentication): return no content if already or just logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Aug 11, 2023
1 parent e64e3ec commit 46bd906
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controllers;

use CodeIgniter\API\ResponseTrait;
// use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\ResponseInterface;
Expand All @@ -11,8 +12,17 @@
use Config\Services;

class LoginController extends BaseLoginController {
use ResponseTrait;

public function customLoginAction(): ResponseInterface {
$session = session();

$current_user_id = $session->get("user.id", null);
if (!is_null($current_user_id)) {
return $this->respondNoContent();
}

log_message("error", "user_id".json_encode(current_user_id));
$_POST = array_merge($_POST, $this->request->getJSON(true));
Services::resetSingle("request");

Expand All @@ -32,7 +42,7 @@ public function customLoginAction(): ResponseInterface {

$raw_error = $session->getFlashdata("error");
if (is_null($raw_error)) {
$new_response = $new_response->setStatusCode(200);
$new_response = $new_response->setStatusCode(204);
} else {
$formalized_errors = [
[
Expand Down

0 comments on commit 46bd906

Please sign in to comment.