Log in

From NSB App Studio
Revision as of 22:04, 26 May 2017 by Sarah (talk | contribs) (Instructions for logging in and out)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

After you've initialized, you can use Volt to control who is allowed to use your app. Only users who have registered will be able to log into your app.

Checking if user is logged in

Use the $volt.auth.isLoggedIn() to check if a user is logged in:

  if ($volt.auth.isLoggedIn()) {
    // Ok to do processing
  } else {
    // ask user to log in
  }
  If $volt.auth.isLoggedIn() Then
    'Ok to do processing
  Else
    'ask user to log in
  End If

Logging In

Logging in identifies your user to the Volt server. Here is a typical log in screen:

Once you have have obtained the user's email and password (either from a screen like the above or otherwise), you can call the $volt.auth.login() function to log the user in.

The syntax of the function is:

$volt.auth.login(email, password, appId, callback)

  • email - string, required. The email address of the user.
  • password - string, required. The user's password.
  • appId - string, optional. The Volt ID of the app to sign into. If not supplied, defaults to value set in $volt.init(appId).
  • callback - function(error, data), required. The function in your app to call when the login is complete (or fails).
  butSignOn.onclick = function () {
    $volt.auth.login(inpEmail.value, inpPassword.value, signOnCallback);
  }

  function signOnCallback(error, data) {
    if (error) {
      if (!data) {
        data = { message: 'Network Error' };
      }
      alert(data.message);
    } else {
      alert('User successfully logged in');
    }
  }
  Sub butSignOn.onclick()
    $volt.auth.login(inpEmail.value, inpPassword.value, signOnCallback);
  End Sub

  Function signOnCallback(error, data)
    If error Then
      If (!data) Then data = { message: "Network Error" }
      MsgBox data.message
    Else
      MsgBox "User successfully logged in"
    End If
  End Sub

Logging Out

You can log your user out by using $volt.auth.logout():

  $volt.auth.logout();
  $volt.auth.logout()

AppStudio Users

AppStudio includes a form for handling login duties, called frmSignOn. If you include it in your app, you can call it as follows:

  butSignIn.onclick = function() {
    showSignIn(signInCallback);
  };

  function signInCallback() {
    butSignIn.disabled = true;
    NSB.MsgBox('SignIn successful.');
  }
  Function butSignIn_onclick()
    showSignIn(signInCallback)
  End Function

  Function signInCallback()
    butSignIn.disabled = True
    MsgBox "SignIn successful."
  End Function

Reference