# 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:

```php
public function getUserId(): ?string
```

This 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:

```php
<?php
use 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();
    }
}
```
