question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error query nativescript plugin firebase | passing result value to out function

See original GitHub issue

hey master… please help me out of this error. i dont know anymore. In method checkDuplicateEmail , i just want to pass value from result function query to local variable hasil. i want to pass the value true or false to var hasil and then i passing the value hasil to my controller. i just run on android platforrm

this is my code

import { Injectable } from "@angular/core";
// firebase API
import * as firebase from "nativescript-plugin-firebase";
// Object
import { ReturnMessage } from "../models/returnMessage";
// Observable
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import { colorProperty } from "tns-core-modules/ui/editable-text-base/editable-text-base";


@Injectable()
export class AuthService {
    private loggedInState = new BehaviorSubject<boolean>(false);
    currentLoggedInState = this.loggedInState.asObservable();
    constructor (){
    }
    changeStateLoggedIn(){
        if(firebase.getCurrentUser()==null){
          this.loggedInState.next(false);
        }
        else{
          this.loggedInState.next(true);
        }
    }
    checkDuplicateEmail(email:string):boolean{
       var hasil:boolean = false; 
        firebase.query(
            function(result) {
                    console.log("Event type: " + result.type);
                    console.log("Key: " + result.key);
                    console.log("Value: " + JSON.stringify(result.value));
                        if(result.value==null){
                            hasil = true;
                        }
                        else{
                            hasil = false;
                        }
            },
            "/pengguna", 
            {
                singleEvent: true,
                orderBy: {
                    type: firebase.QueryOrderByType.CHILD,
                    value: 'email'
                },
                range: {
                   type: firebase.QueryRangeType.EQUAL_TO,
                   value: email
                }
            }
        ).catch((error)=>{
            hasil=false;
        });
        console.log("hasilvalue = > "+hasil);
        return hasil;
    } 
    signUp(email:string, password:string):ReturnMessage{
        var status = new ReturnMessage();
        firebase.createUser({
            email: email,
            password: password
          }).then( 
              function (result) {
                status.value = true;
                status.message = "User created";
              },
              function (errorMessage) {
                status.value = false;
                status.message = errorMessage;
              }
          );
        return status;
    }

    signIn(email:string, password:string):ReturnMessage{
        var status = new ReturnMessage();
        firebase.login({
            type: firebase.LoginType.PASSWORD,
            passwordOptions: {
              email: email,
              password: password
            }
          }).then(
              function (result) {
                status.value = true;
                status.message = JSON.stringify(result);
                // JSON.stringify(result);
              },
              function (errorMessage) {
                status.value = false;
                status.message = errorMessage;
              }
          );
        return status;
    }
    
    signOut(){
        firebase.logout();
    }

    sendVerifyEmail():ReturnMessage{
        var status = new ReturnMessage();
        firebase.sendEmailVerification().then(
            function () {
              status.value = true;
              status.message = "email verification was sent";
            },
            function (error) {
                status.value = false;
                status.message = error;
            }
        );
        return status;
    }
    
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
s-triarcommented, Dec 18, 2017

sorry @EddyVerbruggen . this is my first post. thanks.

0reactions
s-triarcommented, Dec 18, 2017

wow. thank you very much. i dont understand well about promise. i will keep learn about it

Read more comments on GitHub >

github_iconTop Results From Across the Web

firebase.query with then promise... · Issue #188 - GitHub
I find it unnecessary having to make an anonymous function that does nothing in order to bypass that parameter: firebase.query(function() {}, " ...
Read more >
Firestore - NativeScript Docs
Cloud Firestore gives you the ability to read the value of a collection or a document. This can be a one-time read, or...
Read more >
Integrate Firebase with NativeScript for cross-platform app ...
To do that, open your project, head to your app. js file, and add the following import: var firebase = require("nativescript-plugin- firebase") ...
Read more >
nativescript-plugin-firebase - UNPKG
The CDN for nativescript-plugin-firebase. ... 143, value: any;. 144, }. 145. 146, /**. 147, * The options object passed into the query function....
Read more >
NativeScript Firebase already initialized - Stack Overflow
init error: Firebase already initialized". This happens when the changes don't trigger a whole application restart (ex. an html file). It ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found