How to import many users to firebase auth using flutter - firebase

I want to import 30 users using flutter to firebase, I couldn't find any sources to do so, the only thing I found out was this : https://firebase.google.com/docs/auth/admin/import-users ,
But I don't no how to implement this in my app
I wanted to store user data in a google docs and convert it into a ".csv" format and upload this from the flutter app to firebase ' Gmail password' authentication

The document you found uses the Firebase CLI. Unfortunately, you can't do this in dart/flutter. But if you want to implement it in flutter you can loop through a list of user objects.
Example:
List list = [{"email":"user1#example.com","Password":"strong password"},{"email":"use2r#example.com","Password":"strong password"},{"email":"user3#example.com","Password":"strong password"}];
final _auth = FirebaseAuth.instance;
list.forEach((element) async{
await _auth.createUserWithEmailAndPassword(email: element.email, password: element.password);
});

You can send a list of users to the firebase function or your backend service and perform an import like in the document you found.

Related

How to add Firebase authentication for email/pass, phone, and google to an existing UI in flutter

So basically, I have already made the UI for the sign in, sign up, etc screens and now I want to implement firebase into it, does anyone know how to do this? Anything could be useful
Here's a quick recap on how to do this, although i really recommend reading firebase's official tutorial on this,
first you need to add the firebase plugin:
go to the firbase_auth pub page, and follow the "installing" instructions there
open a firebase account, add a project using the firebase console, and follow the tutorial to connect you firebase project you created on the website to your app
now lets say you have some textfields and a button to register/log in, you want to add a "controller" to the text field:
final controller = TextEditingController();
and then in the onPressed of the button, you want to provider a function that calls:
String resultText = controller.text
now you can use the resultText string and send it to firebase (do the same with 2 controllers, one for email and one for password)
first initialize the firebase instance:
import 'package:firebase_auth/firebase_auth.dart';
FirebaseAuth auth = FirebaseAuth.instance;
then anywhere in your app your can call (for example with the string variables you got from the controllers of the text fields):
UserCredential result = await auth.createUserWithEmailAndPassword(
email: email, password: password);
User user = result.user;
and then you can check if the user is received successfully, and condition moving on to the next screen accordingly
this is just an example for registering, you will need different code to check if the user exists on login, but its all through the auth api, which you can read on in the first link I supplied
this is just to give you an example of the steps required to get this done, and i'm over simplifying stuff, but should get you started :)

FIREBASE WARNING: Firebase Error. Please ensure that you spelled the name of your Firebase correctly

as you can see by the question, I am having trouble using Firebase in my app. I initialized the Firebase object and used the configuration from my Firebase account. Additionally, I have been able to authenticate users (I have a semi-functional login system going). So far, users can login to existing accounts and create new accounts. However, I am trying to store data with my user (during registration) by taking the uid from the user and using that in my Cloud Firestore. After they register, I am trying to store the other fields (firstName, lastName, school, etc.) into the Cloud Firestore under the uid.
this.props.firebase
.auth()
.createUserWithEmailAndPassword(this.state.email, this.state.password)
.then((auth) => {
this.props.firebase
.database()
.ref("users/" + auth.user.uid)
.set({data})...
It successfully creates the user but doesn't let me store the information in the Cloud Firestore and throws the error I displayed above. Can anyone help? Thank you!
Note: this.props.firebase is the reference to the firebase object instantiated with firebase.initializeApp()
Hahahaha, I suppose that I needed to actually create a real-time database in order for it to work. I had set up the Cloud Firestore while using the Realtime Database methods. Sorry to all for your troubles.

How do you read the userInfo of another user with Firebase's cloud functions?

I had in mind to create a cloud function that let a user read some of the user infos of another user under certaine conditions.
For example:
const user1 = ??? // user1 is the current user
const user1Data = await firestore().collection('Users').doc('user1.uid').get()
const user2 = ??? // user2 is the user whith user2.uid == user1Data.partnerUid
const user2Data = await firestore().collection('Users').doc('user2.uid').get()
if (user1Data.partnerEmail == user2.email && user1Data.partnerEmail == user2.email) {
// ...
// the endpoint deliver some of the user2 data to user1.
// ...
}
I have seen the documentation of Cloud functions:
https://firebase.google.com/docs/reference/functions/providers_auth_
I have seen that with the admin API we can call getUser:
admin.auth().getUser(uid)
The difference between functions.auth() and admin.auth() is not clear for me. Can we call admin within cloud functions ?
The difference between functions.auth() and admin.auth() is not clear for me.
When you import functions from firebase-functions, all that gets you is an SDK used for building the definition of functions for deployment. It doesn't do anything else. You can't access user data using functions.
When you import admin from firebase-admin, that gives you access to the Firebase Admin SDK that can actually manage user data in Firebase Authentication. You will want to use this to look up and modify users as needed, and it works just fine when running code in Cloud Functions.
The difference between functions.auth() and admin.auth() is not clear for me. Can we call admin within cloud functions ?
Basically functions.auth(), will let you trigger Cloud Functions in response to the creation and deletion of Firebase user accounts. For example, you could send a welcome email to a user who has just created an account in your app:
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
// ...
});
functions.auth() is from the cloud function package:
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
Using the above package you can preform firestore, database or auth triggers that will run in response to creating data in the database or creating a new user...
// The Firebase Admin SDK to access Cloud Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
The firebase admin sdk is used to access the database from privileged environments example inside cloud functions.
Check the following links:
https://firebase.google.com/docs/functions/use-cases
https://firebase.google.com/docs/functions/auth-events
https://firebase.google.com/docs/admin/setup
https://firebase.google.com/docs/functions/auth-events

Flutter Firebase adding other user information such as Address to the database

I am currently working on Flutter Firebase to save the details of the users that are signing up for the app.
What I've done is that the user are able to sign up with their email and password. But what I would like to know is how do I add other user information such as Address to be saved so that the users will be able to see it when I am retrieving it from Firebase to the app.
What I've done :
AuthResult user = await
FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email,password:_password);
This saves the user email and password into the database.
I've tried the solution on : Flutter user registration with Firebase: Add extra user information (age, username)
What I've tried to do :
Firestore.instance.collection('users').document().setData({ 'userid':
user.uid, 'username': _address });
And I seem to get errors on that Firestore is an undefined name along with the uid isn't defined for the class 'AuthResult' . Am I missing some import files?
I've only imported :
import 'package:firebase_auth/firebase_auth.dart';
Also, I know I have to create a table called user to allow the data to be saved in but which one do I use? The Cloud Firestore or the Realtime Database?
Thanks for all the help.
You have a lot of questions hidden in a single question. I'll try to address as many as I can below, but please try to stick to a single question in the future.
Recommending one database over the other is off-topic on Stack Overflow. But I'd recommend reading the Firebase documentation on it here.
Since you started with Cloud Firestore, let's focus on that.
You'll need to import the plugin for Firestore, just like you've done with the plugin with Authentication. So something like:
import 'package:cloud_firestore/cloud_firestore.dart';
As you've discovered, there is no AuthResult.uid property. In such cases, I recommend browsing the reference documentation for the plugin, which makes it fairly easy to see that AuthResult.user is probably the path to go.
So something like:
AuthResult result = await
FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email,password:_password);
User user = result.user;
Not the solution to the question you're asking, but please use document(user.uid) instead of just document(). What you now have generates a document ID, while it's idiomatic (and much easier) to use the UID as the key in a users collection.

How i can make a signup with cloud functions the firebase?

I'm learning to use the cloud functions and may create user with the method admin.auth().createUser, but now i would like make a sign up with account the google
I tried use admin.auth().GoogleAuthProvider() but tells me that propiety GoogleAuthProvider() not exist
It's not always possible use admin sdk. For example, I'm working with Google Actions and I've resolved with firebase dependencies (npm i --save firebase).
https://firebase.google.com/docs/auth/web/google-signin?hl=es-419
async function createUser(token: string) {
// Build Firebase credential with the Google ID token.
const credential = firebase.auth.GoogleAuthProvider.credential(token);
const userCredential = await firebase.auth().signInWithCredential(credential);
}

Resources