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

# Registration

> Learn how to set up the registration form, submit handler, and the OwnId integration

Registration works with your existing user registration form to add new users or enroll new devices for existing users.

## Prerequisites

To get the most out of this guide, make sure to do the following tasks first:

1. Complete the backend integrations (see [Build Server-Side Endpoints](/building-blocks/build-server-endpoints)).
2. Complete the Login integration (see [Login](/building-blocks/boost/build-login)).

<img width="240" src="https://mintcdn.com/ownid/I82uk9jjVUEg_6q6/images/registration.png?fit=max&auto=format&n=I82uk9jjVUEg_6q6&q=85&s=b770c4450012071da9e46294ea364cdb" alt="Widget" data-path="images/registration.png" />

<sup>Figure 1. After integration (example)</sup>

<Note>
  The instructions on this page assume you have already installed and referenced the OwnID SDK at the top of your page as described in Steps 1 and 2 of [Login](/building-blocks/boost/build-login).
</Note>

## Integrating Registration

Implement the event handler, and OwnID registration integration with references to the password and user id fields in your existing form.

### Add the Widget to your Registration Form

The SDK **register** method is used to integrate the registration journey. It references the fields in your existing registration form. It also renders the OwnId widget by automatically referencing your field Ids to calculate its position in the DOM.

The sample registration forms in the snippets below are vanilla examples, shown here only to confirm the implementation pattern of form fields in SDK methods.

#### Implement **register** Method

In the ownid method:

1. Enter "register" for the method name.

2. Assign the form field (as a DOM element) you use as the password to the `passwordField` parameter.

3. Assign the form field (as a DOM element) you use as the login id to the `loginIdField` parameter.

4. Set the `passwordFieldBinding` parameter to `true` if you want to force the OwnID platform to automatically create a random strong password. The value is `false` by default.

5. Assign an error function as desired in the `onError` parameter.

6. Configure the `onRegister` event to copy the `ownIdData` object to a local variable. When submitting the registration form, you must send that object to your backend and store it in the `ownIdData` field you created during Preparation.

Use the code snippets below, and check the embedded comments, to model your implementation of the submit handler and the SDK **register** method.

<CodeGroup>
  ```javascript Javascript theme={null}
  <body>
      <form>
          <div><input placeholder="Email" id="email" type="text"></div>
          <div><input placeholder="Name" id="name" type="text"></div>
          <div><input placeholder="Password" id="pass" type="password"></div>
          <div id="confirm-pass-wrapper"><input placeholder="Confirm Password" id="confirm-pass" type="password"></div>
          <button id="submit" onclick="onSubmit();">Register</button>
      </form>

      <script>
          let ownIdDataObject = null;

          ownid("register", {
              loginIdField: document.getElementById("email"),
              passwordField: document.getElementById("pass"),
              passwordFieldBinding: true, // false by default (if true, OwnID creates a random strong password)
              confirmPasswordContainer: document.querySelector('#confirm-pass-wrapper'), //optional, only if you have a confirm password field (OwnID hides it automatically)
              onError: (error) => console.log(error),
              onRegister: (ownIdData) => {ownIdDataObject = ownIdData.data;}
          });

          function onSubmit() {
              const regParams = {
                  email:  document.querySelector('#email').value,
                  name: document.querySelector('#name').value,
                  password: document.querySelector('#pass').value,
                  ownIdData: ownIdDataObject,
              };
              // this is just an example - Call your existing registration logic in the backend
              registerUser(regParams);
          }
      </script>

  </body>
  ```

  ```jsx React theme={null}
  import { OwnID, WidgetType } from '@ownid/react';

  ...

  function RegisterComponent() {
      const emailField = useRef(null);
      const passwordField = useRef(null);
      const confirmPasswordField = useRef(null); //optional
      
      function onRegister(ownIdData) {
          // store the ownIdDataObject in your app storage.
          // global variable is just an example. It's not recommended using it in that way
          window.ownIdDataObject = ownIdData;
      }

      function onSubmit(formData) { 
          if (window.ownIdDataObject) {
              formData.ownIdData = window.ownIdDataObject;
          }
          
          // this is just an example - Call your existing registration logic in the backend
          return register(formData);
      }

      return (
          <form>
              <input ref={emailField} type="email" name="email" placeholder="Email" />
              <input type="text" name="first-name" placeholder="Name" />
              <input ref={passwordField} type="password" name="password" placeholder="Password" />
              <input ref={confirmPasswordField} type="password" name="confirm-password" placeholder="Confirm Password" />
              <button type="submit" onClick={onSubmit}>Register</button>
              <OwnID type={WidgetType.Register}
                  loginIdField={emailField}
                  passwordField={passwordField}
                  passwordFieldBinding={true} // false by default (if true, OwnID creates a random strong password)
                  confirmPasswordContainer={confirmPasswordField}
                  onError={(error) => console.error(error)}
                  onRegister={onRegister} />
          </form>
      );
  }
  ```

  ```javascript Angular theme={null}
  //template
  <form [formGroup]="userForm" class="registration-form" (ngSubmit)="onSubmit()">
    <input formControlName="name" type="texy" name="name" placeholder="Name" required/>
    <input formControlName="email" type="email" #email name="email" placeholder="Email" required/>
    <input formControlName="password" type="password" #password name="password" placeholder="Password" required/>
    <input formControlName="confirmPassword" type="password" #confirmPassword name="confirmPassword" placeholder="Confirm Password" required/>
    <button type="submit">Register</button>
    <ownid [type]="WidgetType.Register"
           [options]="widgetOptions"
           (onRegister)="onRegister($event)"
           [loginIdField]="email"
           [passwordField]="password"
           [confirmPasswordContainer]="confirmPassword">
    </ownid>
  </form>

  //controller
  import { IPartialConfig, WidgetType } from '@ownid/angular';

  ...

  protected readonly WidgetType = WidgetType;

  widgetOptions: IPartialConfig = {
      passwordFieldBinding: true //false by default (if true, OwnID creates a random strong password)
  };

  onRegister(ownIdData) {
      //store the ownIdDataObject in your app storage.
      //global variable is just an example. It's not recommended using it in that way
      window.ownIdDataObject = ownIdData;
  }

  onSubmit(formData) {
      if (window.ownIdDataObject) {
          formData.ownIdData = window.ownIdDataObject;
      }
      
      // this is just an example - Call your existing registration logic in the backend
      return register(formData);
  }

  ```
</CodeGroup>

## Styling Options

The OwnID register widget can be styled in different ways to match your application's design:

### Default Button

<img width="240" src="https://mintcdn.com/ownid/R0Wddcq9zgBDU03F/images/default-button-variant.png?fit=max&auto=format&n=R0Wddcq9zgBDU03F&q=85&s=8893084c32ec5d8c69415176d06b7849" alt="default button variant" data-path="images/default-button-variant.png" />

<sup>Default button variant (Example for michaelkors.com)</sup>

The default implementation places the OwnID button side by side with the password field. This is the standard configuration and requires no additional parameters.

If you would like to style this button, you can do it in the OwnID Console or utilize the following CSS variables:

```css theme={null}
ownid-fingerprint-button-widget {
    --ownid-button-widget-border-radius;
    --ownid-button-widget-font-size;
    --ownid-button-widget-color;
    --ownid-button-widget-border-color;
    --ownid-button-widget-check-size;
    --ownid-button-widget-check-position-top;
    --ownid-button-widget-check-position-right;
    z-index;
}
```

### Standalone Button

<img width="240" src="https://mintcdn.com/ownid/i3kGqVa3mIaTdz4d/images/standalone-button-variant.png?fit=max&auto=format&n=i3kGqVa3mIaTdz4d&q=85&s=7d4ac47a05f330dc65ba802a953f50cc" alt="default button variant" data-path="images/standalone-button-variant.png" />

<sup>Standalone button variant (Example for nfl.com)</sup>

For cases where you want to position the OwnID button independently from the password field, use the standalone button variant:

```javascript theme={null}
ownid('register', {
  variant: 'standalone-button',
  infoTooltip: false,
  loginIdField: document.querySelector('#email'),
  element: document.getElementById('button-wrapper-div'),
  // other configuration options...
});
```

Note: in the code sample above, `button-wrapper-div` represents the div where the button will be shown. Configure your own.

This creates a separate OwnID button that you can position anywhere in your login form.

<Note> OwnID changes the texts and icon according to the platform to ensure a higher click rate </Note>

If you would like to style this button, you can utilize the following CSS variables:

<Tabs>
  <Tab title="Button">
    ```css theme={null}
    ownid-standalone-button-widget {
        height: 40px;
        --ownid-button-width: 100%;
        width: 100%;
        --ownid-button-widget-border-color;
        --ownid-button-widget-border-radius;
        --ownid-button-widget-font-size;
        --ownid-button-widget-font-weight;
        --ownid-button-widget-color;
        --ownid-button-widget-icon-height;
        --ownid-button-widget-icon-stroke-width;
        --ownid-button-widget-check-size;
        --ownid-button-widget-check-position-top;
        --ownid-button-widget-check-position-right;
    }
    ```
  </Tab>

  <Tab title="Finished State (Register)">
    ```css theme={null}
    ownid-standalone-button-widget[finished=true] {
        --ownid-button-widget-border-color;
        --ownid-button-widget-color;
        --ownid-button-widget-check-color;
    }   
    ```
  </Tab>
</Tabs>

<Check>
  **That's it!**

  Your users can now register for a new account and leverage other user journeys you implement.

  Before going live make sure you check out the following the next steps.
</Check>

## Next Steps

### Ready to deploy?

<CardGroup cols={2}>
  <Card title="YES!" href="/building-blocks/pre-deployment-checklist" icon="rocket-launch">
    Take me to the Deployment Checklist
  </Card>

  <Card title="NOT YET..." href="/building-blocks/build-frontend-integration" icon="screwdriver-wrench">
    I want to build another user journey
  </Card>
</CardGroup>
