N
N
Nurlan2017-10-16 12:50:54
Laravel
Nurlan, 2017-10-16 12:50:54

Am I catching the beginning of the session correctly?

There is a site with a long history, rewritten separately on a new server. It was necessary that after logging in on the old site, authorization would automatically take place on the new one. We decided to do this: when entering a new site, a new session is caught and it is checked if there is a cookie, then get the information and authorize using Laravel.
I implement it like this: I
created a Middleware "StartSession" with inheritance from the parent Illuminate\Session\Middleware\StartSession and rename the startSession method to :

public function startSession(Request $request)
    {
        event(new SiteAuth($session=parent::startSession($request)));
        return $session;
    }

In Kernel, I replaced the original one with my own.
Created:
- Provider (SiteAuthServiceProvider) in which I registered my StartSession
- Event (SiteAuth)
- Listener (SiteAuthListener), Of
course, they are registered where necessary.
In the listener's handle method, I wrote the test code and it works.
Attention to the question, dear experts: did I do everything right? From the point of view of the architecture of Laravel, MVC, etc., is this shit code or a crutch?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-10-16
@Sanasol

event(new SiteAuth($session=parent::startSession($request)));

Some kind of porridge baby.
events are usually processed asynchronously, why is all this here?
Why are there any events at all and this whole chain of incomprehensible actions, despite the fact that in the end you just do this
? Just check the standard session and do authorization in Laravel if it exists. As stated at the beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question