Tail SDK can be used to integrate Tail in your own application and manage authenticating your end users and link them with different apps.

Getting started

Install @raccoonai/tail-react package by executing the following command.

npm install @raccoonai/tail-react

Below is an example of how to use the Tail SDK to authenticate and link a user.

TypeScript
import * as React from "react";
import { useTailSDK, LinkAppModal } from "@raccoonai/tail-react";

let RACCOON_SECRET_KEY = "<secret-key>"
let RACCOON_USER_PASSCODE = "<raccoon-passcode>"

export default function TailSDK() {
  const tailInstance = useTailSDK({
    secretKey: RACCOON_SECRET_KEY,
    callbacks: {
      onSuccess: (msg) => alert("Success:" + msg),
      onError: (err) => {
        alert("Error : " + err.message);
        console.error(err);
      },
    },
  });

  const [isOpen, setIsOpen] = React.useState(false);

  return (
    <div>
      <button onClick={() => setIsOpen(true)}>Link Uber</button>
      <button onClick={async () => await tailInstance.unlinkApp('uber', RACCOON_USER_PASSCODE)}>Unlink Uber</button>

      <LinkAppModal
        isModalVisible={isOpen}
        onCancel={() => setIsOpen(false)}
        tailInstance={tailInstance}
        raccoonPasscode={RACCOON_USER_PASSCODE}
        app="uber"
      />
    </div>
  );
}

You’ll need your secret key and user’s raccoon passcode to link apps. You can find them on secrets and users pages on the platform.


Usage

useTailSDK

The useTailSDK hook lets you instantiate and use the Tail SDK in your application.

const tailInstance = useTailSDK({
   secretKey: RACCOON_SECRET_KEY,
   callbacks: {
     onSuccess: (msg) => alert("Success:" + msg),
     onError: (err) => {
       alert("Error : " + err.message);
       console.error(err);
     },
   },
});

LinkAppModal

The modal to display necessary information and start the app linking process.

<LinkAppModal
   isModalVisible={isOpen}
   onCancel={() => setIsOpen(false)}
   tailInstance={tailInstance}
   raccoonPasscode={RACCOON_USER_PASSCODE}
   app="uber"
/>

getApps

This function returns a list of all the apps available for authentication for your organisation.

const availableApps = await tailInstance.getApps()

getLinkedApps

This function returns a list of all the apps that are currently authenticated and linked for a user. You need to pass the raccoonPasscode of the user you want to check the linked apps for.

const apps = await tailInstance.getLinkedApps(RACCOON_PASSCODE);

unlinkApp

The unlinkApp function in tailInstance unlinks the app for the provided Raccoon Passcode. It returns a boolean true if the unlinking is successful and false if it fails.

await tailInstance.unlinkApp(RACCOON_PASSCODE);