Use PFUser on Parse without a Username - ios

I'm building an app where emails are supposed to be the main identifiers. I don't want my users to have a username at all. I'm using Parse for backend and want to use the PFUser class for user signups etc. It seems like PFUser requires a username. Is there anyway to use PFUser without using username?

You can set emailAsUsername to true in signUpView as following:
signUpViewController.signUpView.emailAsUsername = true

I am in the same situation as you, but what I do is just set the email address my user enters for the username field. Now they can just login with their email address :)

Related

Firebase and Swift username case-sensitive

When registering a new user, and when I look in the Firebase user database, if the user exists he does not create the accunt, otherwise the registration is completed. But if there is a user named "Tony" in the database and I try to register with the username "tony", Firebase don't understand that "Tony" and "tony" are the same username. I want to solve this.
I state that I wrote the code in swift.
I think the fastest way with querying is to do this:
Duplicate your username list in a new list where all your usernames are lowercased
Lowercase the new username
Check if that username exist in your duplicated list (where all usernames are lowercased)
When it does not exists, append the real username without lowercase to the list with the usernames where they are case-sensitive and to the lowercased username list.
This duplicates data, but it is not that bad since it are only usernames.

How can I use user input to name a child in Firebase?

I'm trying to create a simple user database on Firebase for iOS. I have two textfields, one that takes the user's email address, and the other that takes the user's password. I want the email to be the user's uid. I try to accomplish this by creating a variable called "email" which I set equal to emailTextField.text! Then I implement the code that generates child(s) in Firebase, like so:
ref = Database.database().reference()
ref.child("users").child(email).setValue(true)
Here's my problem: creating a child and naming it using a variable, doesn't work. I can do the following just fine:
ref.child("users").child("email")
but once I take away the quotation marks around "email" so that it becomes the variable, the program crashes.
How can I use user input to name a child in Firebase?
Firebase node / document names do not support the same character set which email addresses support, for example, the . symbol in an email address would make the child name invalid.
If you tried setting a child as
ref.child("users").child("xyz#xyz.xyz")
you should see the same error.
If you absolutely need to use the email address as the node name, I recommend encoding the email in a way which is compatible with the firebase node name rules.
Link to the rules
Edit: If you are using firebase auth, the normal pattern is too use the UID returned by the authenticated user object as the node name, not the email address entered from the textfield.
A quick example:
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if let user = user {
ref.child("users").child(user.uid).setValue(true)
}
}

How do I signup users using PFObject instead of PFUsers()

I have created a PFObject called UserDataTable which stores information like username, password, Name, emailID, age, city, state, etc. of the user.
I am not sure how to authenticate the user to server using PFObject but can do so using PFUsers(). I know that PFUsers is a sub-class of PFObject so there must be a way to access those properties using my PFObject.
Can anyone help me out with the same. I am using SWIFT for coding.
let UserDataBase = PFObject(className: "UserDataBase")
UserDataBase["userId"] = "aamirdbx"
UserDataBase["userName"] = "Aamir Bilal"
UserDataBase["userPassword"] = "pass"
UserDataBase["userEmailId"] = "aamirdbx#gmail.com"
I would like to Sign In using information in this UserDataBase which is a PFObject.
I know how we can do the same using PFUser() but I want to avoid using a bunch of different Objects.
You should be using PFUser for this no matter what. PFUser already has all the built in authentication protocols, session tokens, security and ACL built in for you, which as someone who is just getting started is not something you want to try and manage yourself. You can add extra information to your Parse User class if you need to store additional information, or you can create another table, and have a pointer in your user class to the data in the other table, but for your sake and your user's sake, please don't try to handle this yourself.
After that chunk of code you should call userDataBase.saveInBackground() or saveInBackgroundWithBlock but then you would have to do a lot more coding every time they log in to authenticate and sync objects with the user etc. The included PFUser subclass does a lot of the heavy lifting for you, plus you can add properties to the user subclass so that would probably be a better option.

How would I anonymous push username information to Parse

I've tried a few things, but nothing seems to work properly. I'm utilizing anonymous users and I have the User class in parse working fine, as it creates an autogenerated username for the current device utilizing the app.
I'd just like to attach the currentuser to my "createdBy" column alongside all the data in parse and I'm quite stumped as most things I've tried have failed.
Could you try this in viewDidLoad?
if let user = PFUser.currentUser() {
user["createdBy"] = user.username
user.saveInBackground()
}
It will push username to parse.com

Change PFUser username, Parse Integration with Facebook

I am writing an IOS Parse supported application where you can log in with facebook. I've gotten parse to create linked accounts with facebook, but the problem is the username of the parse user is this massive long random string. I'd like to make the username their email (which I can get from facebook's API). But I can't seem to set the username property of [PFUser currentUser].
The reason I need their username to be their email is so their friends can be like, "Oh, I think I'll friend djk#s.edu" instead of, "Oh, hey I should friend SKDJSDFLSHDFBSLDKFjbdh".
Thanks in advance
The easiest solution here is to use the email field on [PFUser currentUser]. It's a default field you can call just like userName and will save you some headaches.
I wouldn't mess with the username - I think Parse uses it as part of the facebook login/auth process.
If the facebook login for Parse doesn't automatically set this field, you can set it manually by pulling the email address from facebook and setting it for the current user:
//facebookEmail = string from facebook with email address
[[PFUser currentUser] setObject:facebookEmail forKey:#"email"];
[[PFUser currentUser] saveInBackground];
You could also use a new field to the User object for user name that might be more friendly, such as "friendlyName" or "humanReadableName" that includes the first and last name of the person.

Resources