无法使用firebase创建用户 无法使用firebase创建用户
请参阅以下示例firebase代码
state={email:'',password:'',error:''};
//Firebase configuration
componentWillMount(){
firebase.initializeApp({
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: ''
});
}
//Button handler to create user
onPressHandler(){
firebase.auth().createUserWithEmailAndPassword(
this.state.email,this.state.password)
.then(() => this.setState({error:'Created'}))
.catch(() => {this.setState({error: 'Authentication Failed'})});
}
答案 0 :(得分:0)
在app.component文件中
import firebase = require("nativescript-plugin-firebase");
ngOnInit(): void {
firebase.init({
persist: true,
storageBucket: 'gs://*********.******.com/',
onAuthStateChanged: (data: any) => {
console.log(JSON.stringify(data))
if (data.loggedIn) {
BackendService.token = data.user.uid;
}
else {
BackendService.token = "";
}
}
}).then(
function (instance) {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
在服务档案
中import firebase = require("nativescript-plugin-firebase");
register(user: User) {
return new Observable((observer: any) => {
firebase.createUser(user).then( (result) => {
observer.next(JSON.stringify(result));
}).catch((error) => {
observer.error(error);
});
});
}
答案 1 :(得分:0)
import * as firebase from 'firebase'
import React from 'react';
import { Text, View } from 'react-native';
// Initialize Firebase
var config = {
apiKey: "someApiKey",
authDomain: "some.auth.domain",
databaseURL: "dbUrl",
projectId: "myProjectId",
storageBucket: "storage",
messagingSenderId: "8734652304"
}
const myFirebase = firebase.initializeApp(config);
const insert= () => ({
firebase
.database()
.ref(`value`)
.set({
id: data.id,
});
});
export default class App extends React.Component {
render() {
return (
<View style={{flex:1}}>
<Button onPress={this.insert.bind(this)}>My App</Text>
</View>
);
}
}