# getUserId

Learn how to get the ID of the currently identified user.

This method returns the ID of the currently identified user, or `null` if the user is anonymous.

The user ID is the subject of the [token](/explanation/application/signed-tokens) used to authenticate the user, more specifically, the subject (`sub`) claim of the [JSON Web Token (JWT)](https://jwt.io/).

If you just want to check whether the user is anonymous, consider using the [`isAnonymous`](/reference/sdk/javascript/api/plug/is-anonymous) method instead.

## Signature

The `getUserId` method has the following signature:

```ts
croct.getUserId(): string | null
```

This method returns the ID that identifies the user or `null` if the user is anonymous.

## Example

Here is a basic example of how to use this method:

```ts
import croct from '@croct/plug';

console.log(croct.getUserId()); // null

croct.identify('00000000-0000-0000-0000-000000000000');

console.log(croct.getUserId()); // 00000000-0000-0000-0000-000000000000
```
