Lifecycle Functions

Swoop offers additional callback functions for different phases of the authentication flow. Implementing these will all you to enhance your user's experience by appropriately updating the UI.

The following code shows all of the callback functions that are available with comments that hint at their usage.

/**
 * Called when the Swoop popup gets displayed. You could use
 * this function to display a "Signing in" message to the user.
 *
 * @params w: a reference to the Swoop window
 **/
function swoopOnShow(w) {
	console.log("Signing in with Swoop.");
}

/**
 * This function gets called AFTER the user successfully authenticates
 * with Swoop but BEFORE the callback is made to get the user's id_token.
 * 
 * This is another message to display a loading interface to the user while
 * a network opperation occurs.
 **/
function swoopOnLoading(){
	console.log("Authenticated with Swoop, fetching id_token.");
}

/**
 * Gets called when the user closes the Swoop window without authenticating.
 *
 * When this function is called, reset the authentication UI
 **/
function swoopOnClose() {
	console.log("The user closed the Swoop window without authenticating");
}

/**
 * Handles successful sign in
 *
 * @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.
}

/**
 * Handles failed sign in
 *
 * @params error: the error when signing in with Swoop
 **/
function swoopOnError(error) {
  console.log("An error occurred signing in with Swoop.");
  console.log(error);
}