<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "CloudKitJS",
  "identifier" : "/documentation/CloudKitJS/CloudKit.Container/setUpAuth",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "CloudKit JS"
    ],
    "preciseIdentifier" : "instm/CloudKit.Container/setUpAuth"
  },
  "title" : "setUpAuth"
}
-->

# setUpAuth

Determines whether a user is signed in and presents an appropriate sign in or sign out button.

```
Promise<CloudKit.UserIdentity, CloudKit.CKError> setUpAuth();
```

## Return Value

A `Promise` that resolves to a [`CloudKit.UserIdentity`](/documentation/CloudKitJS/CloudKit.UserIdentity) dictionary if an active CloudKit session was found; otherwise, `null`. If an error occurs, a `Promise` object that rejects to a [`CKError`](/documentation/CloudKitJS/CloudKit/CKError) object.

## Discussion

Use the [`setUpAuth`](/documentation/CloudKitJS/CloudKit.Container/setUpAuth) method to determine whether the user is authenticated and to display the appropriate button.

```javascript
var myContainer = CloudKit.getDefaultContainer();
 
myContainer.setUpAuth().then(function(userIdentity) {
    if(userIdentity) {
        // The user is authenticated
    }
});
```

In the function, use the `userRecordName` property to get the user record name from the [`CloudKit.UserIdentity`](/documentation/CloudKitJS/CloudKit.UserIdentity) parameter.

The [`setUpAuth`](/documentation/CloudKitJS/CloudKit.Container/setUpAuth) method displays the appropriate buttons only if the required DOM elements are found. If the user is not signed in, the method displays a sign-in button; otherwise, it displays a sign-out button.

You can call this method multiple times. For example, call this method to determine if a previous CloudKit session is still valid, and call this method later to display the buttons after you add the required DOM elements.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)