getUserId
Learn how to provide the authenticated user ID.
An implementation must return the identifier of the currently authenticated user, or null when the visitor is anonymous.
Signature
This method has the following signature:
public function getUserId(): ?stringThis method returns the ID of the authenticated user, or null when the visitor is anonymous.
Example
This example resolves the current user from an authentication service:
1234567891011121314151617
<?phpuse Croct\Plug\IdentityResolver;
final class AuthIdentityResolver implements IdentityResolver{ private Auth $auth;
public function __construct(Auth $auth) { $this->auth = $auth; }
public function getUserId(): ?string { return $this->auth->getUser()?->getId(); }}