error query nativescript plugin firebase | passing result value to out function
See original GitHub issuehey 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
sorry @EddyVerbruggen . this is my first post. thanks.
wow. thank you very much. i dont understand well about promise. i will keep learn about it