getUserId

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 used to authenticate the user, more specifically, the subject (sub) claim of the JSON Web Token (JWT) .

If you just want to check whether the user is anonymous, consider using the isAnonymous method instead.

Signature

The getUserId method has the following signature:

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:

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