Skip to content

Conversation

@datamweb
Copy link
Collaborator

@datamweb datamweb commented Oct 19, 2023

Description
The duty of session is to protect URLs. I think devs should know that there is no reason to protect logout. That's why I think we don't need to change the code.
I have already added this topic #642 .

fix #920

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@datamweb datamweb added the documentation Improvements or additions to documentation label Oct 19, 2023
@datamweb
Copy link
Collaborator Author

Also, there is no reason for a user who is not logged in to have access to /logout.
This issue must be resolved.

/**
* Logs the current user out.
*/
public function logoutAction(): RedirectResponse
{
+// block route logout if see beforlogin
+if (!auth()->loggedIn()) {
+throw PageNotFoundException::forPageNotFound();
+}
// Capture logout redirect URL before auth logout,
// otherwise you cannot check the user in `logoutRedirect()`.
$url = config('Auth')->logoutRedirect();

auth()->logout();

return redirect()->to($url)->with('message', lang('Auth.successLogout'));
}

public function logoutAction(): RedirectResponse
{
// Capture logout redirect URL before auth logout,
// otherwise you cannot check the user in `logoutRedirect()`.
$url = config('Auth')->logoutRedirect();
auth()->logout();
return redirect()->to($url)->with('message', lang('Auth.successLogout'));
}

@datamweb datamweb requested a review from kenjis October 20, 2023 00:25
@datamweb datamweb merged commit 2d7cd7c into codeigniter4:develop Oct 21, 2023
@datamweb datamweb deleted the docs-add-logout-to-except branch October 21, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: cannot login after logging out from url

2 participants