User Meta

With swoop, you can send additional user meta information that will be "passed through" and returned when the user successfully authenticates. This allows you to use Swoop to validate forms, registration data, subscriptions, etc...

See the code below for an example of sending firstName and lastName from a form.

/**
 * This function allows you to pass user_meta attributes through the Swoop process.
 * This can be useful when using Swoop to register a user OR add additional attributes
 * such as plan when authenticating.
 * 
 * When this method exists, its returns a JSON object containing the key-values of the
 * user meta.  When the `swoopOnSuccess` function gets called later in the flow, the user
 * will have an additional property called `user_meta`.
 *
 * ```
 *
 **/
function swoopUserMeta() {
  let firstName = document.getElementById("first_name").value;
  let lastName = document.getElementById("last_name").value;
  if (firstName && lastName) {
    return {firstName, lastName};
  }
}

/**
 * Handles successful sign in
 *
 * For this example, the user object will look like this:
 *
 * ```
 * {
 *   "id_token": "ey.....",
 *   "email": "[email protected]",
 *   "uid": "abc123",
 *   "user_meta":
 *   {
 *     "firstName": "Peregrin",
 *     "lastName": "Took"
 *   }
 * }
 *
 * @params user - a Swoop user object
 **/
function swoopOnSuccess(user) {
  console.log("Successfully signed in with Swoop");
  console.log(user);
  // TODO: send user.id_token to the server to validate and create a user session.
}