Throw event when changing session id#3377
Throw event when changing session id#3377carakas merged 3 commits intoforkcms:masterfrom wouterverstuyf:ProfilesChangedSessionIdEvent
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3377 +/- ##
============================================
+ Coverage 27.74% 27.76% +0.01%
- Complexity 8028 8031 +3
============================================
Files 568 569 +1
Lines 30624 30647 +23
============================================
+ Hits 8497 8508 +11
- Misses 22127 22139 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
Question : when you login/logout in the backend section, the Session ID also changes. Should this be event be triggered from the backend login/logout function also? Is it ok to trigger a frontend event from within the backend section? |
|
@wouterverstuyf I would add it in the Common namespace, not in the profiles one. It is tied to the session, not a profile, and then you can throw the event in the backend as well |
| public static function logout(): void | ||
| { | ||
| $session = FrontendModel::getSession(); | ||
| $oldSession = FrontendModel::getSession()->getId(); |
There was a problem hiding this comment.
you can use $session->getId() here
Yes, got the same feeling this morning, I check it ;) |
| public function __construct(string $oldSessionId) | ||
| { | ||
| $this->oldSessionId = $oldSessionId; | ||
| $this->sessionId = FrontendModel::getSession()->getId(); |
There was a problem hiding this comment.
Pass this one in the constructor as well.
Type
Resolves the following issues
When a public profile login/logout the session id changes.
Could be handy for other modules to hook in through an event, to get the new Session ID.
Pull request description
You can create a listener in your own module that detects the login/logout action. In the listener you can get the new session ID and do your stuff
/Frontend/Modules/MyModule/EventListener/ProfilesSessionIdChangedListener.php
namespace Frontend\Modules\MyModule\EventListener; use Common\Events\ForkSessionIdChangedEvent; class ForkSessionIdChangedListener { public function onForkSessionIdChanged(ForkSessionIdChangedEvent $event): void { // do your stuff // $event->getSessionId() // $event->getOldSessionId() } }