Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { StyleSheet, View, TextInput } from 'react-native';
- import db from '../Database.js';
- class LoginForm extends React.Component {
- constructor(props) {
- super(props);
- }
- render() {
- return (
- <View style={styles.container}>
- <TextInput
- placeholder="Access Code"
- returnKeyType="go"
- onSubmitEditing={text => {db.checkCode(text.nativeEvent.text)}}
- />
- </View>
- );
- }
- }
- const styles = StyleSheet.create({ // stylesheet
- // yay styles :)
- });
- export default LoginForm;
- //import * as firebase from "firebase";
- var firebase = require('firebase');
- if (!firebase.apps.length) {
- firebase.initializeApp({
- apiKey: "key",
- authDomain: "domain",
- databaseURL: "url",
- storageBucket: "bucket",
- });
- }
- class Database {
- codesRef = firebase.database().ref('codes');
- static checkCode(text) {
- let codeIsFound = false;
- this.codesRef.once('value', (db_snapshot) => { // this won't work
- db_snapshot.forEach((code_snapshot) => {
- if (text == code_snapshot.val().value) {
- codeIsFound = true;
- identifier = code_snapshot.key;
- }
- });
- });
- if (codeIsFound) {
- //this.deleteCode(identifier);
- console.log("code found");
- this.props.navigation.navigate('Create'); // side-question => how can i get this working in Database.js? Do i need to use withNavigation?
- } else {
- console.log("code not found");
- );
- }
- };
- }
- module.exports = Database;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement