Skip to content

How to use Auth

o5faruk edited this page May 2, 2021 · 20 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/auth/

⚠️⚠️⚠️

Auth (Authentication)

Some plugins require the user to be authenticated before continuing on to a particular feature. Auth is used to login and to register on the BuildFire auth server. This article goes through the steps for using Auth.

Login


How to use Auth

Methods:

buildfire.auth.login([options], callback);

This method will check if the current user is logged in or not. If not, buildfire.js will open the login UI.

arguments

  • options: {allowCancel: true|false , showMenu: true|false }.
    • allowCancel: a flag to show or hide the cancel link on the login screen. default: true
    • showMenu: a flag to show or hide the menu link on the login screen. default: true
  • callback(err, user): is a function that is called when the data is retrieved from the datastore. The callback function is called after login or registration is successful.

buildfire.auth.logout();

This method is seen when you logout from auth.

arguments

  • This method does not accept any arguments.

buildfire.auth.getCurrentUser(callback);

This method gives the current logged in user in the callback function.

arguments

  • callback(err,user): is a function that is called with the current logged in user if exists.
    • err: if there was an error when attempting to retrieve the user
    • user: the user object containing public user properties

buildfire.auth.onLogin(callback, [allowMultipleHandlers]);

This method allows you to pass a callback function that is called whenever the user is logged in.

arguments

  • callback: the callback function contains the current loggedin user.
  • allowMultipleHandlers: optional bool param that tells the method to override all other handlers. Default false

buildfire.auth.onLogout(callback, [allowMultipleHandlers]);

This method allows you to pass a callback function that is called whenever the user is logged out.

arguments

  • callback Callback executed when logout is complete.
  • allowMultipleHandlers: optional bool param that tells the method to override all other handlers. Default false

buildfire.auth. getUserProfile(options,callback);

This method will pull a public profile for a user if you have the userId.

arguments

  • options: {userId: 'XXX' }
  • callback (err, profile) it’s a callback function contains the profile user.

buildfire.auth.openProfile(userId);

This method will redirect the app to view user profile page.

arguments

  • userId: 'XXX'

buildfire.auth.getUserPictureUrl(params);

This method will return user picture url by userId or email.

arguments

buildfire.auth.assignUserTags (tags <required>, options, callback);

This function is used to assign a user tag to the current logged-in user on the app side. (this function only works on widget side)

arguments

  • tag: A required string array to be assigned to the current logged in user. tags must match the following cirteria:

    • Begin with $$
    • At least 5 character in length including $$
    • May not contain commas
    • Should not contain spaces, spaces will be converted to '-'
  • options: reserved for future usage. can be passed as null.

  • callback: a function that is called when the tag is assigned. function(err,data){}

example

buildfire.auth.assignUserTags(['$$vip'],null, function(err, result) {
  if (!err) {
    console.log('added tag successfully');
  } else {
    console.error('error adding tags', err);
  }
});

buildfire.auth.keepSessionAlive([options], callback);

This method resets counting idle time for user sessions. to be used when Session Expiration is enabled on Control Panel side and the plugin needs to keep the session alive even if there are no clicks applied to the plugin widget. A good example would be if the user is listening to an audio or watching a video.

arguments

  • options: reserved for future usage. can be passed as null.
  • callback(err, user): a function that is called when the request is received by the app from plugin.

Clone this wiki locally