|
| 1 | +## Usage |
| 2 | + |
| 3 | +The SlashID form is available as a custom element: `<slashid-form>`. |
| 4 | + |
| 5 | +There are two files which need to be included in your HTML document: |
| 6 | +1. `main.js` |
| 7 | +2. `style.css` |
| 8 | + |
| 9 | +By nature of being a custom element, props follow the HTML specification so they must be strings. |
| 10 | + |
| 11 | +To work around this limitation: |
| 12 | +- Provide boolean and number props as string, they're later parsed to their respective type. |
| 13 | +- Provide array and object props as stringified JSON, they will be parsed with `JSON.parse()` later. |
| 14 | +- Provide function props by first defining the function on `globalThis`, then providing the function name to the prop as a string. |
| 15 | + |
| 16 | +Props are reactive, but keep in mind that reference checks for array and object types are not possible since they are stringified. Function references are not reactive, redefine the function on `globalThis` and provide the new name to the prop to achieve reactivity. |
| 17 | + |
| 18 | +### Example |
| 19 | +```html |
| 20 | +<!DOCTYPE html> |
| 21 | +<html lang="en"> |
| 22 | + <head> |
| 23 | + <meta charset="UTF-8" /> |
| 24 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 25 | + <link rel="stylesheet" href="style.css"> |
| 26 | + <title>Hello world</title> |
| 27 | + </head> |
| 28 | + <body> |
| 29 | + <script> |
| 30 | + function sidOnSuccess() { |
| 31 | + alert('Success!') |
| 32 | + } |
| 33 | + </script> |
| 34 | + |
| 35 | + <slashid-form |
| 36 | + factors='[{ "method": "email_link" }]' |
| 37 | + oid="YOUR_ORG_ID" |
| 38 | + base-api-url="https://api.slashid.com" |
| 39 | + token-storage="memory" |
| 40 | + on-success="sidOnSuccess" |
| 41 | + analytics-enabled="true" |
| 42 | + ></slashid-form> |
| 43 | + |
| 44 | + <script type="module" src="main.js"></script> |
| 45 | + </body> |
| 46 | +</html> |
| 47 | +``` |
| 48 | + |
| 49 | +## Props |
| 50 | + |
| 51 | +| Name | Type | Default | Description | |
| 52 | +|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 53 | +| oid | `string` | | The organization ID you get when signing up with /id | |
| 54 | +| initialToken? | `string` | | Given a valid initial token, SDK will initialize with a `User` based on that token | |
| 55 | +| tokenStorage? | `"memory" \| "localStorage"` | `"memory"` | Where SlashID user tokens are stored. Set to `"localStorage"` to enable persistence. | |
| 56 | +| baseApiUrl? | `string` | `"https://api.sandbox.slashid.com"` | The base SlashID API endpoint | |
| 57 | +| sdkUrl? | `string` | `"https://cdn.sandbox.slashid.com/sdk.html"` | The location where your organization's custom SDK is served | |
| 58 | +| analyticsEnabled? | `boolean` | `true` | Enable collection of client side analytics events | |
| 59 | +| themeProps? | `{ theme?: Theme, className?: string}` | `{ theme: "auto" }` | Set the UI theme (`auto`, `light` or `dark`) and apply a CSS class name to the theme root | |
| 60 | +| logo? | `string` | Defaults to SlashID logo | The logo shown in the SlashID components, must be URL. | |
| 61 | +| text? | `Record<string, string>` | See [default](https://developer.slashid.dev/docs/access/react-sdk/reference/components/react-sdk-reference-configurationprovider#text-overrides). | Overrides for text shown in the SlashID components. | |
| 62 | +| factors? | [`FactorConfiguration[]`](https://developer.slashid.dev/docs/access/react-sdk/reference/components/react-sdk-reference-configurationprovider#type-factorconfiguration) | `[{ method: "webauthn" }, { method: "email_link" }]` | The [authentication methods](https://developer.slashid.dev/docs/access/sdk/interfaces/Types.Factor) to be used. | |
| 63 | +| storeLastHandle? | `boolean` | `false` | Flag where `true` means the handle type and value used in a successful log in action will be persisted in `window.localStorage`. | |
| 64 | +| defaultCountryCode? | `string` | `US` | Default country code to be used for the phone number input. Accepts an Alpha-2 ISO-3166 country code. | |
| 65 | +| onSuccess? | `(user: User) => void` | | Callback function that gets called with a User object returned from core SDK upon successful log in action. Note: callback functions must be defined in `globalThis`, this prop accepts the function name as `string`. | |
| 66 | +| onError? | `(error: Error, context: ErrorContext) => void` | | Callback function that gets called with a User object returned from core SDK upon log in action failure. Note: callback functions must be defined in `globalThis`, this prop accepts the function name as `string`. | |
| 67 | +| middleware? | [`LoginMiddleware`](https://developer.slashid.dev/docs/access/react-sdk/reference/middleware/react-sdk-reference-login-middleware) | | Effects to be run post-login but before `onSuccess` fires, and before the next render cycle. See [`LoginMiddleware`](https://developer.slashid.dev/docs/access/react-sdk/reference/middleware/react-sdk-reference-login-middleware) for more. | |
| 68 | + |
| 69 | +## How does this work? |
| 70 | + |
| 71 | +We are using [Web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements) as an interopability interface only. |
| 72 | + |
| 73 | +Internally, we mount a React app with three components from `@slashid/react`: |
| 74 | +- `<SlashIDProvider>` |
| 75 | +- `<ConfigurationProvider>` |
| 76 | +- `<Form>` |
| 77 | + |
| 78 | +The available props are a subset of those available in `@slashid/react`. |
0 commit comments