> For the complete documentation index, see [llms.txt](https://dev.vulos.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/authentication/user.md).

# User

## Interfaces

### `UserTokens` <a href="#tokens" id="tokens"></a>

```typescript
interface UserTokens {
    accessToken: string, 
    refreshToken: string, 
    idToken: string,
    tokenType: string,
    expiresAt: number
}
```

## Members

### `api :` [`BaseAuth`](/reference/identity-javascript-sdk/the-base-package/authentication/baseauth.md)

The `BaseAuth` implementation that was used to create this object.

### `accessToken : string?`

This user's OpenID access token.

### `refreshToken : string?`

This user's OpenID refresh token.

### `idToken : string?`

This user's OpenID identification token.

### `tokenType : string?`

The type of the access token.

### `expiresAt : number?`

The time when the access token expires.

### `organizationApi :` [`OrganizationApi`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationapi.md)

The `OrganizationApi` object that is associated with this user.

### `profileApi :` [`ProfileApi`](/reference/identity-javascript-sdk/the-base-package/profile/profileapi.md)

The `ProfileApi` object that is associated with this user.

## Methods

### `constructor(api,tokens)`

Create a user object that interacts with the Vulos Identity API on behalf of a user.

* The `api` argument should be a [`BaseAuth`](/reference/identity-javascript-sdk/the-base-package/authentication/baseauth.md) implementation;
* The `tokens` argument should be a token set that implements the [`UserTokens`](#tokens) interface.

```typescript
const user = new User(auth, preservedTokenSet)

// ... or

const user = await auth.processCallback(verifier, req.query)
```

{% hint style="info" %}
See [`BaseAuth`](/reference/identity-javascript-sdk/the-base-package/authentication/baseauth.md) for more information.
{% endhint %}

### `save()`

Save the token set user to a serializable object that implements the [`UserTokens`](#tokens) interface.

{% hint style="info" %}
This function can be used if you want to store the user tokens in a database.
{% endhint %}

{% hint style="warning" %}
The tokens might update on any API call, so make sure you call this if you want to preserve the tokens.
{% endhint %}

```javascript
const tokenSet = user.save()
```

### `async reference()`

Create a [`UserReference`](/reference/identity-javascript-sdk/the-base-package/profile/userreference.md) object that is associated with this user.

```javascript
const ref = await user.reference()
```

### `async info()`

Get the [`UserInfo`](/reference/identity-javascript-sdk/the-base-package/authentication/userinfo.md) object for this user.

```javascript
const userInfo = await user.info()
```

### `async getOrganizationMemberships()`

Get all the [`OrganizationMembership`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationmembership.md) objects for this user's organizations.

```javascript
for (const membership of await user.getOrganizationMemberships()) {
    // do something with the membership object
}
```

### `async createOrganization(details)`

Create a new organization with a `details` object that implements the [`OrganizationCreateDetails`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationapi.md#organizationcreatedetails) interface.

```javascript
const membership = await user.createOrganization({
    name: 'My Organization',
    website: 'https://example.com',
    address: 'Example St. 1234',
    uniqueId: '1234-567-89',
    city: 'Example City',
    countryCode: 'AQ',
    zipCode: '1234',
    // state: 'Optional State'
})
```

### `async organizationSearch(search, amount, offset)`&#x20;

{% hint style="info" %}
This function is an alias to [`User.profileApi.organizationSearch()`](/reference/identity-javascript-sdk/the-base-package/profile/profileapi.md#async-organizationsearch-search-amount-offset).
{% endhint %}

The only difference is that this function doesn't throw, but returns `false` on failure.

### `async getAccessToken()`

Get the access token of the user.

{% hint style="info" %}
This function will automatically attempt to refresh the access token if it is expired.
{% endhint %}

```javascript
const accessToken = await getAccessToken()
```
