final class Auth

Static entry point to the application's auth guard. Lazily constructs a single SessionGuard so every caller shares one resolved user per request, and forwards the common guard operations (check, user, id) to it. A guard may also be injected via setGuard() to support testing.

Properties

static private Guard|null $guard

The shared guard instance for the current request, or null until first constructed.

Methods

static bool
check()

Determines whether a user is currently authenticated.

static Guard
guard()

Returns the shared guard, constructing it on first use.

static mixed
id()

Gets the identifier of the currently authenticated user.

static void
setGuard(Guard|null $guard)

Sets the shared guard instance, replacing any existing one. Intended primarily for testing, where a guard backed by a fake provider or session can be injected. Passing null resets the guard so the next call to guard() constructs a fresh default instance.

static Principal|null
user()

Gets the currently authenticated user.

Details

at line 29
static bool check()

Determines whether a user is currently authenticated.

Return Value

bool

True if a user is authenticated, otherwise false.

at line 36
static Guard guard()

Returns the shared guard, constructing it on first use.

Return Value

Guard

at line 51
static mixed id()

Gets the identifier of the currently authenticated user.

Return Value

mixed

The authenticated user's identifier, or null if no user is authenticated.

at line 65
static void setGuard(Guard|null $guard)

Sets the shared guard instance, replacing any existing one. Intended primarily for testing, where a guard backed by a fake provider or session can be injected. Passing null resets the guard so the next call to guard() constructs a fresh default instance.

Parameters

Guard|null $guard

The guard to use, or null to reset.

Return Value

void

at line 75
static Principal|null user()

Gets the currently authenticated user.

Return Value

Principal|null

The authenticated user, or null if no user is authenticated.