AgonK
auth()->user cannot be read after login in middleware ?
@Dennis Koch yes I tested in
authenticate()
after save sessions, then get it and everything works fine.
I also tested with hardcoded values as from "session" just to check if in the any next request I can get the sessions values but unfortunately they cannot be read on middleware in laravel side(app.php
). I don't know why!
Then, I put this middleware on panel provider in authMiddleware
and works better but crashed on somewhere in AuthenticateSession
in handle
method in this if
statment
I got this error
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'default_db.users' doesn't exist
This code try to access user model in default database that it configured in .env
. But I change the default database connection on the fly on authenticate
method. I cannot understand what is wrong here, while I use same structure of login (change db connection on the fly) in the same project but without filament installed only with API. Dennis is there any bug or Im wrong in somewhere 😅 . Thank you anyway!7 replies
auth()->user cannot be read after login in middleware ?
@Dennis Koch
I use this middleware on
app.php
like this
I don't have any other middleware on the laravel side. I also put in the filament PanelProvider in middleware
section but it has different behavior, it does not reach after login and because of that I put it on app.php
and its reach on every request as I expected!
Additional information:
I customize the login in filament. I extend the \Filament\Pages\Auth\Login
class and modify the authenticate
method.
In this step (after successfully login) I changed the database connection and save it in session to handle on next request. But I cannot read any of these data in middleware like (auth()->user()
, sessions
) and so. I don't know why it's happened. Did I miss something here ? Thank you anyway Dennis7 replies