I think the Session is generally considered to be unavailable inside Service Provider/Plugin register and boot methods. This is because it fires very early in the life cycle.
Maybe consider using App::before(function() { /* ... */ }); to wrap the logic, the session should be available inside this event.
This is what I did but it doesn’t seems to work. Any ideas ? I have some code that I can’t move inside the controller directly because it’s not my plugins.
The code itself is fine. The advice in that ticket still applies today, using App::before will indeed defer until after the session has been activated.
The session requires cooperation from the browser and the server. If it works for some users and not others, we can reasonably determine it is some browsers not playing ball.
Check to make sure that the session cookie is accepted by the browser. Without this cookie, the getUser method will return null, even if they have signed in successfully.