Skip to content

feat: prevent logged-in users from trying to log in again #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jun 8, 2022

Basically, a logged-in user is not supposed to log in again without logging out,
and should be protected so that he/she cannot do so with filters and/or controllers.

But a developer may misconfigure and if a logged-in user logs in with a different user account,
the session data of the previous user is carried over.

This PR prevents such behavior by making errors.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only exception I see is "act as" functionality - where an admin impersonates another user to simulate their experience using the website. I incorporate this into all my projects because it is very helpful during development to be able to try different user roles and it helps eventual website owners troubleshoot issues with their users' accounts.

That said, maybe that doesn't count as an actual "login" and needs some other way of changing the underlying active user?

@lonnie-vault
Copy link
Contributor

I wouldn't think of that as a login, per se. In Laravel projects I've used laravel-impersonate and found it very nice. Maybe we need a package like this? Though I'm not sure that's a core component.

Either way - you could probably override the filter to make this work?

@kenjis
Copy link
Member Author

kenjis commented Jun 9, 2022

"act as" functionality is not a normal login. It should not fire login event.
You can't use Session::login() for it.

If a logged-in user logs in with a different user account, the session data of the previous user is carried over.
@kenjis kenjis force-pushed the prevent-logged-in-user-login-again branch from 92156a7 to ec5fe81 Compare June 11, 2022 01:11
@kenjis
Copy link
Member Author

kenjis commented Jun 11, 2022

Fixed a rector error. Merging.

@kenjis kenjis merged commit 00023ee into codeigniter4:develop Jun 11, 2022
@kenjis kenjis deleted the prevent-logged-in-user-login-again branch June 11, 2022 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants