> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rownd.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Javascript API Reference

> API Reference for the Rownd Javascript API

## `requestSignIn(opts)`

Show the Rownd sign-in dialog, or automatically initiate a sign-in.

### Examples

#### Prompt the user to sign in

`requestSignIn()` can be called without any parameters and the user can choose to sign in
with any of your app's configured sign-in methods.

```javascript theme={null}
rownd.requestSignIn()
```

#### Automatically sign in a user using their email

```javascript theme={null}
rownd.requestSignIn({
  identifier: 'john.doe@acme.com',
  auto_sign_in: true
})
```

#### Prompt the user to sign in with Google and save a referral code to their user data

```javascript theme={null}
rownd.requestSignIn({
  method: 'google',
  user_data: {
    referral_code: 'ref_123'
  }
})
```

### Parameters

<ResponseField name="identifier" type="string">
  An email address or phone number (in E164 format) to
  which a verification message may be sent. If the Rownd app is configured to
  allow unverified users, then sign-in will complete without verification if the
  user has not signed in previously.

  This is frequently used in conjunction with
  `auto_sign_in: true` to automatically sign in a specific user.

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Email theme={null}
        rownd.requestSignIn({ identifier: 'john.doe@acme.com' })
      ```

      ```javascript Phone theme={null}
        rownd.requestSignIn({ identifier: '+19199999999' })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="auto_sign_in" type="boolean" default="false">
  When `true`, automatically trigger a sign-in
  attempt *if* `identifier` is included or an email address or phone number has
  already been set in the user data.

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Auto Sign-in theme={null}
      rownd.requestSignIn({
        identifier: 'john.doe@acme.com'.
        auto_sign_in: true
      });
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="method" type="SignInMethod">
  If set, Rownd will initiate a sign-in with the specified method. Must be one of
  `'email'`, `'phone'`, `'google'`, `'one_tap'`, `'passkeys'`, `'crypto_wallet'`, or `'anonymous'`

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Email theme={null}
        rownd.requestSignIn({ method: 'email' });
      ```

      ```javascript Phone theme={null}
        rownd.requestSignIn({ method: 'phone' });
      ```

      ```javascript Google theme={null}
        rownd.requestSignIn({ method: 'google' });
      ```

      ```javascript One Tap theme={null}
        rownd.requestSignIn({
          method: 'one_tap',
          method_options: {
            // This is optional. Let's you anchor the One Tap dialog to a specific
            // spot on the page.
            prompt_parent_id: '#one-tap-anchor-selector'
          }
        });
      ```

      ```javascript Passkeys theme={null}
        rownd.requestSignIn({ method: 'passkeys' });
      ```

      ```javascript Crypto Wallet theme={null}
        rownd.requestSignIn({ method: 'crypto_wallet' });
      ```

      ```javascript Anonymous theme={null}
        rownd.requestSignIn({ method: 'anonymous' });
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="redirect" type="boolean" default="true">
  After the sign-in completes, Rownd will redirect to the configured `postLoginRedirectUrl`
  or `postRegistrationUrl`. If `false`, the user will stay on the verification page. This
  can be helpful if your site or application cannnot be reached via a traditional redirect,
  such as if it's running in an iframe.

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Disable Redirect theme={null}
      rownd.requestSignIn({
        method: 'email',
        redirect: false,
      })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="post_login_redirect" type="string">
  An absolute or relative URL for which to redirect the user after the sign-in completes.

  <Info>This overrides `postLoginRedirectUrl` and `postRegistrationUrl` if they are set.</Info>

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Absolute URL theme={null}
      rownd.requestSignIn({ post_login_redirect: 'https:/my.site/signed_in' })
      ```

      ```javascript Relative Path theme={null}
      rownd.requestSignIn({ post_login_redirect: '/some/path?signed_in=true' })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="user_data" type="object">
  Extra user data to append to the user record when sign-in completes.

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Referral Code theme={null}
      rownd.requestSignIn({
        user_data: {
          referral_code: 'ref_123'
        }
      })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="include_user_data" type="boolean" default="true">
  When `true`, user data that was previously set using `rownd.user.set()` will be added to
  the user record after sign-in.

  <Accordion title="Example">
    <CodeGroup>
      ```javascript No User Data theme={null}
      rownd.user.set({ nick_name: 'Joey' })

      ...

      // { 'nick_name': 'joey' } will not be added to the user's data
      rownd.user.requestSignIn({
        include_user_data: false
      })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="intent" type="string">
  This option applies only when you have opted to split the sign-up/sign-in flow via the Rownd dashboard. Valid values are `"sign_in"` or `"sign_up"`. If you don't set this value, the user will be presented with the unified sign-in/sign-up flow.

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Sign Up theme={null}
      rownd.requestSignIn({ intent: 'sign_up' })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

<ResponseField name="login_step" type="LoginStep">
  The step in the sign-in dialog to display. Must be one of [LoginStep](#loginstep)

  <warn>This is an advanced option and rarely necessary for most use-cases</warn>

  <Accordion title="Example">
    <CodeGroup>
      ```javascript Success theme={null}
      rownd.requestSignIn({
        login_step: rownd.LoginStep.Success
      })
      ```
    </CodeGroup>
  </Accordion>
</ResponseField>

## `signOut()`

Signs out the user, clearing their access token and user data

```javascript theme={null}
rownd.signOut()
```

## `getAccessToken()`

Get the access token for the signed-in user.

### Parameters

<ResponseField name="waitForToken" type="boolean" default="false">
  When `true`, if no access token is present or if
  it's expired, the promise will not be resolved until a valid token is
  available. While unlikely, this could result in waiting forever.

  <Accordion title="Example">
    ```javascript theme={null}
    const token = await rownd.getAccessToken({ waitForToken: true });
    ```
  </Accordion>
</ResponseField>

## `user`

<ResponseField name="get()" type="Function">
  Gets the data associated with the current user

  <Accordion title="Example">
    ```javascript theme={null}
    // data = { user_id: "user_1235, email: "john.doe@acme.com", referral_code: "ref_123" }
    const data = await rownd.user.get();
    ```
  </Accordion>
</ResponseField>

<ResponseField name="set(user_data)" type="Function">
  Replaces all of the user data for the current user.

  <Tip>You can call `set()` prior to a user signing in. This can be useful to construct user data if your app
  supports an unauthenticated state.</Tip>

  <Accordion title="Example">
    ```javascript theme={null}
    rownd.user.set({ email: "john.doe@acme.com", referral_code: "ref_123"})
    ```
  </Accordion>
</ResponseField>

<ResponseField name="setValue(field_name, value)" type="Function">
  Sets a specific field in current user's data.

  <Accordion title="Example">
    ```javascript theme={null}
    rownd.user.setValue('referral_code', 'ref_123')
    ```
  </Accordion>
</ResponseField>

<ResponseField name="uploadFile(field_name, file)" type="Function">
  Upload a file for a specific field

  <Info>The file parameter must be a javascript File. If the field name corresponds to
  an image field, the mime type of the file must have an "image/" prefix (e.g.
  "image/png")</Info>

  <Accordion title="Example">
    ```javascript theme={null}
    rownd.user.uploadFile("profile_picture", file);
    ```
  </Accordion>
</ResponseField>

<ResponseField name="manageAccount()" type="Function">
  Show the user profile dialog

  <Accordion title="Example">
    ```javascript theme={null}
    rownd.user.manageAccount()
    ```
  </Accordion>

  <Tabs>
    <Tab title="Mobile">
      <Frame>
        <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/mobile/profile.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=847ac8afdcbe788496decb280ac485c1" width="1570" height="2932" data-path="images/hub/mobile/profile.png" />
      </Frame>
    </Tab>

    <Tab title="Desktop">
      <Frame>
        <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/desktop/profile.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=d6894be5635ad23ab5986f88b3176210" width="1101" height="1048" data-path="images/hub/desktop/profile.png" />
      </Frame>
    </Tab>
  </Tabs>
</ResponseField>

## `auth`

<ResponseField name="isVerifiedUser()" type="Function -> boolean">
  Returns `true` if the current user is a verified user. In practice, this means that they have at least
  one piece of verified data (email, phone, etc).

  <Accordion title="Example">
    ```javascript theme={null}
    if (rownd.auth.isVerifiedUser()) {
      console.log('verified!')
    }
    ```
  </Accordion>
</ResponseField>

## `requestFields()`

Prompt the user to enter values to save in their data. You can specify the fields, submit button content, and the
queustion/prompt.

### Examples

#### Prompt the user to enter their first and last name

```javascript theme={null}
rownd.requestFields({
  fields: ['first_name', 'last_name'],
  buttonText: 'Save name',
  questionText: 'What\'s your name?'
});
```

<Tabs>
  <Tab title="Mobile">
    <Frame>
      <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/mobile/request-fields.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=831e53337136f719fa77d638b21764f1" width="1570" height="2932" data-path="images/hub/mobile/request-fields.png" />
    </Frame>
  </Tab>

  <Tab title="Desktop">
    <Frame>
      <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/desktop/request-fields.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=f9ceea2ed08ef96e787fd10cd334488b" width="1101" height="991" data-path="images/hub/desktop/request-fields.png" />
    </Frame>
  </Tab>
</Tabs>

### Parameters

<ResponseField name="fields" type="string[]">
  List of the field names for which to prompt the user.

  <Info>The fields must exist in your application's Data Types in order to save the data to the user's profile</Info>
</ResponseField>

<ResponseField name="bottonText" type="string">
  The text to show on the submit button
</ResponseField>

<ResponseField name="questionText" type="string">
  The prompt or question displayed on the dialog
</ResponseField>

## `near`

<ResponseField name="near" type="object">
  The `near` API allows you to interact with the Rownd's [NEAR integration](../configuration/web3/near-overview.mdx).

  <ResponseField name="ensureImplicitAccount()" type="function">
    Creates an implicit NEAR account for the current user if one doesn't already exist

    <Accordion title="Example">
      ```javascript theme={null}
      const accountId = rownd.near.ensureImplicitAccount()
      ```
    </Accordion>
  </ResponseField>

  <ResponseField name="createNamedAccount()" type="function">
    Prompts the user to create a named NEAR account

    <Accordion title="Example">
      ```javascript theme={null}
      const accountId = rownd.near.createNamedAccount()
      ```
    </Accordion>

    <Tabs>
      <Tab title="Mobile">
        <Frame>
          <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/mobile/near-create-named-account.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=31546ecfe0c47e38dc0ee7b627273fe2" width="1570" height="2932" data-path="images/hub/mobile/near-create-named-account.png" />
        </Frame>
      </Tab>

      <Tab title="Desktop">
        <Frame>
          <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/desktop/near-create-named-account.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=bd1e842ad01703bdaec285832794371f" width="1101" height="991" data-path="images/hub/desktop/near-create-named-account.png" />
        </Frame>
      </Tab>
    </Tabs>
  </ResponseField>

  <ResponseField name="connectAccount()" type="function">
    Prompts the user to connect a NEAR accuont

    <Accordion title="Example">
      ```javascript theme={null}
      rownd.near.connectAccount()
      ```
    </Accordion>

    <Tabs>
      <Tab title="Mobile">
        <Frame>
          <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/mobile/near-connect-account.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=4ae60bb22e0a99f94ca92cb0d7831339" width="1570" height="2932" data-path="images/hub/mobile/near-connect-account.png" />
        </Frame>
      </Tab>

      <Tab title="Desktop">
        <Frame>
          <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/desktop/near-connect-account.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=f7ac7b63600bbe6604bc5217211c494a" width="2200" height="1982" data-path="images/hub/desktop/near-connect-account.png" />
        </Frame>
      </Tab>
    </Tabs>
  </ResponseField>

  <ResponseField name="walletDetails()" type="function">
    Opens a dialog showing the details of the user's implicit NEAR account

    <Accordion title="Example">
      ```javascript theme={null}
      const accountId = rownd.near.walletDetails()
      ```
    </Accordion>

    <Tabs>
      <Tab title="Mobile">
        <Frame>
          <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/mobile/near-wallet-details.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=342e0b36c39fc4d623b8621b9bd78901" width="1570" height="2932" data-path="images/hub/mobile/near-wallet-details.png" />
        </Frame>
      </Tab>

      <Tab title="Desktop">
        <Frame>
          <img style={{height:'400px'}} src="https://mintcdn.com/rownd/FjlVKOm-SL8QlAMa/images/hub/desktop/near-wallet-details.png?fit=max&auto=format&n=FjlVKOm-SL8QlAMa&q=85&s=3a8d6b2f37944389cbc3842dbb583a08" width="1101" height="1048" data-path="images/hub/desktop/near-wallet-details.png" />
        </Frame>
      </Tab>
    </Tabs>
  </ResponseField>
</ResponseField>

## `LoginStep`

A step in the Rownd sign-in dialog. Used when calling [requestSignIn](#requestsignin) to show
a specific step.

<ResponseField name="INIT" type="enum" />

<ResponseField name="NoAccount" type="enum" />

<ResponseField name="Success" type="enum" />

<ResponseField name="Error" type="enum" />

<ResponseField name="Completing" type="enum" />
