Log in

From NSB App Studio
Jump to navigation Jump to search

After you've initialized, you can use VoltServer 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
    'ask user to log in
  End If

Logging In

Logging in identifies your user to the VoltServer 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 VoltServer 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' };
    } 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
      MsgBox "User successfully logged in"
    End If
  End Sub

Once the user is logged in, he stays logged in. The info is save to localStorage so the next time the app is run, the user does not have to log in again.

Logging Out

You can log your user out by using $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() {

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

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