Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var firebase = require('firebase');
- if (!firebase.apps.length) {
- firebase.initializeApp({
- apiKey: "key",
- authDomain: "domain",
- databaseURL: "url",
- storageBucket: "bucket",
- });
- }
- class Database {
- constructor() {
- this.codesRef = firebase.database().ref('codes');
- }
- isValidCode(text) {
- let codeIsFound = false;
- let identifier = "";
- this.codesRef.once('value', (db_snapshot) => {
- db_snapshot.forEach((code_snapshot) => {
- //console.log(text, code_snapshot.val().value, text == code_snapshot.val().value);
- if (text == code_snapshot.val().value) {
- codeIsFound = true;
- identifier = code_snapshot.key;
- }
- });
- //console.log(codeIsFound); // this is correct
- return codeIsFound; // this always returns undefined
- });
- };
- }
- module.exports = Database;
- import React from 'react';
- import {
- StyleSheet,
- View,
- TextInput,
- } from 'react-native';
- import { withNavigation } from 'react-navigation';
- import database from '../Database.js';
- const db = new database();
- class LoginForm extends React.Component {
- constructor(props) {
- super(props);
- }
- render() {
- return (
- <View style={styles.container}>
- <TextInput
- style={styles.input}
- placeholder="Access Code"
- returnKeyType="go"
- onSubmitEditing={text => {console.log(db.validCode(text.nativeEvent.text))}} // "undefined"
- autoCapitalize="none"
- autoCorrect={false}
- />
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- // yay styles :)
- });
- export default withNavigation(LoginForm);
- isValidCode(text) {
- let codeIsFound = false;
- let identifier = "";
- this.codesRef.once('value', (db_snapshot) => {
- db_snapshot.forEach((code_snapshot) => {
- //console.log(text, code_snapshot.val().value, text == code_snapshot.val().value);
- if (text == code_snapshot.val().value) {
- codeIsFound = true;
- identifier = code_snapshot.key;
- takeValue(codeIsFound);
- }
- });
- });
- };
- takeValue(value){
- console.log(value) //true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement