SessionGuard
final class SessionGuard implements Guard
Session-backed guard. Owns "who is logged in right now" and delegates all storage to a UserProvider. Resolves the current user from the session once per request and caches the result, writes the session on login, and clears it on logout. Remember-me persistence is delegated to a RememberMeStore.
Properties
| private UserProvider | $provider | Retrieves and validates users on the guard's behalf. |
|
| private string | $sessionKey | The session key under which the authenticated user's identifier is stored. |
|
| private Principal|null | $user | The resolved user for the current request, or null if none is authenticated or resolution has not yet occurred. |
|
| private bool | $resolved | Whether the current user has been resolved from the session yet. |
|
| private RememberMeStore|null | $remember | Handles persistence and teardown of remember-me tokens. |
Methods
No description
Determines whether a user is currently authenticated.
Gets the identifier of the currently authenticated user.
Resolves a user by identifier and logs them in.
Logs the current user out, clearing the session, the cached user, and any persisted remember-me token.
Resolves the current user from the session once, then caches it.
Checks credentials WITHOUT logging anyone in.
Details
at line 65
__construct(UserProvider $provider, string|null $sessionKey = null, RememberMeStore|null $remember = null)
No description
at line 81
bool
check()
Determines whether a user is currently authenticated.
at line 91
mixed
id()
Gets the identifier of the currently authenticated user.
at line 106
void
login(Principal $user, bool $remember = false)
Logs the given user in, storing their identifier in the session and caching them for the current request. When $remember is true, a remember-me token is also persisted.
at line 120
Principal|null
loginUsingId(mixed $id)
Resolves a user by identifier and logs them in.
at line 132
void
logout()
Logs the current user out, clearing the session, the cached user, and any persisted remember-me token.
at line 145
Principal|null
user()
Resolves the current user from the session once, then caches it.
at line 161
bool
validate(array $credentials)
Checks credentials WITHOUT logging anyone in.