Account Kit SDK for Javascript - Reference

The Account Kit JS SDK has the following methods.

Method Description

.init(options: InitOptions)

Used to initialize Account Kit. InitOptions is a Javascript object with the following properties:

  • appId: A string containing the Facebook App ID of your application.
  • debug: A Boolean specifying whether to display a descriptive error message when an error occurs. If true, an explicit error message is displayed. If false, only a generic error is displayed.
  • version: A string specifying the Graph API version. This should match the version of Graph API endpoints used in server-to-server communication.
  • state: CSRF protection. A string, 36 or fewer characters long, containing a non-guessable value which should originate on the server. It is bundled with requests and is returned back to the app client unchanged, and the app client can pass it back to server to verify the match with the original value.
  • fbAppEventsEnabled: A boolean that determines whether Facebook app events logging is enabled. If true, event logging is enabled.

.login(method: string, params: LoginParams, callback: Function)

method: A string specifying the login method. This must be either "PHONE" or "EMAIL"

params: A LoginParams object, which has the following properties:

  • countryCode: For use with the PHONE login method. A string which should be in the form "+<number>", e.g. "+91".
  • phoneNumber: For use with the PHONE login method. A string containing 1 to 20 numeric characters.
  • emailAddress: For use with the EMAIL login method. A string containing a valid email address.

callback is a Function that takes a single Javascript object as its argument. The object will have the following properties:

  • status: A string indicating the status of the request - see below for the values this string can have.
  • code: When status is "PARTIALLY_AUTHENTICATED", this string contains an authorization code, which your server may exchange for a user access token.
  • state: When status is "PARTIALLY_AUTHENTICATED", this string should match the value of the state param passed to AccountKit.init().

Valid values for the status field above are:

  • "PARTIALLY_AUTHENTICATED": This indicates that the login was successful, and that you may pass the code to your server for token exchange to complete authentication.
  • "NOT_AUTHENTICATED": Failure, for any reason.
  • "BAD_PARAMS": One or more of the parameters in the login() request were invalid.

window.AccountKit_OnInteractive()

This is a callback function defined by the developer that is called when the SDK loads asynchronously and is interactive. This is the preferred place to initialize the SDK by calling AccountKit.init().