Embedded authentication
@polytomic/connect-react renders the configuration form inside your React app,
so users connect their systems without leaving your product. For non-React
frontends, or to let Polytomic host the flow, see
Hosted authentication.
Install
Requires react and react-dom 18 or 19.
Add two backend routes
Set up a proxy on your backend to mint Connect sessions and forward requests to Polytomic.
The embedded form shows one connection type, so send exactly one entry in
whitelist. List the available types with
GET /api/connection_types, and send a
type’s id. Each type also has a logo_url and logo_dark_url for rendering
your own picker. name is how the connection will appear in the organization,
and must be unique per connection type. To reconnect an existing connection,
send connection with its ID instead of whitelist. The other fields are in
the API reference.
Render the form
Validation errors, such as a missing field or failed credentials, display in the
form and don’t call onError.
OAuth opens in a popup. If the browser blocks it, the form shows a button to open it.
If the user leaves before finishing, an incomplete connection can remain in the
organization. Check a connection’s status before using it, and delete unused
ones.
To restart the flow, remount the form with a new key.
Style it
Import the package stylesheet before your own CSS so your rules take precedence.
Polytomic styles are scoped to the form’s root element, .ptc-root.
Theme
Theme elements like color and border radius are styled using CSS variables.
Override them on .ptc-root, and set dark values under
[data-color-scheme='dark']. Colors are HSL channels without the hsl()
wrapper:
Set font-family on .ptc-root to change the font, which defaults to Inter.
Set --ptc-form-max-width to change the maximum width, which defaults to
36rem.
Elements
Elements are styled by data-slot, with state exposed through data and ARIA
attributes. Scope rules under .ptc-root and include the state you’re
targeting:
Only data-slot values and state attributes are stable. Other markup can change
between versions.
Common states:
data-invalid,data-disabledanddata-requiredon a fieldaria-invalidon an inputdata-state="open"on menusdata-checkedon a selected menu optiondata-selectedon selected tree and file rows
Tooltips and dialogs are portalled to a separate .ptc-root container appended
to the body, so rules scoped to .ptc-root apply to them too.
