Skip to main content

From 5 to 6

Compatibility

  • Browser support: We support Safari mobile and desktop 16, Chrome 109 and Firefox 106. Browsers older than this may still be able to use our SDK, but may require additional transpile and polyfills.
  • No polyfills are included since all APIs used are also supported in the versions supported.
  • Custom themes require support for color-mix CSS function. A compatibility helper is available if you are targeting older browsers.

Step by step guide

1

Upgrade @stytch/vanilla-js

Run npm, yarn or pnpm to install the new version.
package.json
"@stytch/vanilla-js": "^5.0.0", 
"@stytch/vanilla-js": "^6.0.0", 
2

Update to use custom element

The library now exports a custom element, and StytchUIClient is deprecated in favor of StytchClient. Instead of calling stytch.mount(), register the custom element and call render() on the element to pass in the client and config.
import {
  StytchUIClient, 
  StytchUI, 
  createStytchClient,
} from '@stytch/vanilla-js';

const stytch = new StytchUIClient($YOUR_PUBLIC_KEY); 
const stytch = createStytchClient($YOUR_PUBLIC_KEY); 

stytch.mount({ 
  elementId: "#stytch-ui",
  config,
});
customElements.define('stytch-ui', StytchUI); 
document.getElementById('stytch-ui').render({
  client: stytch,
  config,
})
3

Update products configuration

If config.products are specified as strings, update them to use Products instead:
import { Products } from '@stytch/vanilla-js'; 

const config = {
  products: ['oauth', 'eml'], 
  products: [Products.oauth, Products.emailMagicLinks], 
};
4

Update styles to presentation

The new presentation property now controls theming and styling options. This differs from the previous style property in that it configures tokens affecting many elements rather than properties on specific elements.We have provided a migration helper function. In development mode this function will also print out warnings about properties that could not be migrated.
import { styleToTheme } from '@stytch/vanilla-js/compat'; 

const config = {
  style: { ... }, 
  // This will also print out the recommended migrated config
  // which should replace this in production
  theme: styleToTheme({ ... }),
};
For a full list of supported properties, see reference documentation for presentation.

presentation.theme

Controls CSS styling. Each token corresponds to some CSS properties, so each value should be a CSS value. You can also provide an array of [lightTheme, darkTheme] which will automatically switch between the two depending on the user's OS color scheme.

presentation.options

Controls non-styling options such as the logo to display.

More styling changes

These changes are unlikely to cause issues.
5

Update customized strings

If you use string customization, check if you need to update these strings:You may also wish to customize these new strings:
6

Update deprecated imports

The following are deprecated and should be updated.
  • createStytchUIClientcreateStytchClient
  • createStytchHeadlessClientcreateStytchClient
  • StytchUIClientStytchClient
  • StytchHeadlessClientStytchClient
7

Test your changes

We recommend running through every auth method used to make sure the new theme looks correct in context. You should also take note of errors or warnings in the browser console.