Hi,
When I use a provider (in this case google) I would like to createUser automatically using the details available in the auth.
However createUser requires email / password.
If your using the federated oath method why the need for password?
couldn't we simply use email / uid ?
If I manually create a user with key matching auth.uid logging in successfully finds the nominated profile.
If I then go and remove permission to the app in my google account, then login and give permission again the generated uuid remains the same, i.e. the old record for the previous permission still exists in the firebase auth.
So wouldn't it be possible to also create user with: { provider: 'google', uid: 'mLHxB1FGmSg5bIkSB5PnmyWlceo2'} as credentials when using federated oath?
Id like to be able to automatically create a profile via createUser when a user logs in via a provider if no profile for that users uid exists yet.
I don't quite see the point of supporting provider based login if the user still has to do an app specific email / password signup to be able to use the profile feature.
Granted I have only used the google provider but I assume at the firebase auth db level the records are all the same
the email would be taken from the auth record
Sorry i get it now its due to requirement of createUserWithEmailAndPassword and what I am actually describing is auto creating profile
If anyone has already done this some pointer would be nice - I have some ideas but there might be a best practice way to do it
One does not use createUser with oAuth accounts, as Firebase "creates the user" when you login with the external provider.
What you are describing is how things should function if you call
this.props.login({ provider: 'google' })
Which is described in Auth Examples within the docs. Make sure that you pass userProfile: 'users' when calling reactReduxFirebase to enable profile capabilities.
The default profile setup should included what you mentioned, but If you want to change the way that profiles are written, you can also provide a profileFactory parameter to your config.
OK so perhaps something else is going wrong because the only reason I arrived at this was I followed the instructions... my config being:
const config = {
userProfile: 'users', // where profiles are stored in database
updateProfileOnLogin: true,
profileFactory: (userData) => { // how profiles are stored in database
const { user } = userData
return {
email: user.email
// other stuff
}
}
}
But after login with provider the profile does not exist (is still null), neither is there a record in the firebase users db object in my firebase console.
There is a successful record under firebase console auth section for the provider login.
Am I right in expecting the firebase users db to contain an entry matching the user logged in with provider? Because this has not been the case hence my confusion.
react-redux-firebase are you currently using?Use popup for now (the default if you don't pass type). It seems that Firebase has changed their API slightly in recent updates, which has caused redirect to not work correctly. I have been in contact with someone at Firebase talking over the best way to address this issue (apparently due to not using a script tag).
Using popup seems to work
version 1.1.5
Hello again,
I cant see the profileFactory working for this...
reactReduxFirebase(firebaseConfig, {
userProfile: 'users',
updateProfileOnLogin: true,
profileFactory: (userData) => {
console.log('profileFactory')
const { user } = userData
return {
email: user.email,
role: 'user'
// other stuff
}
}
})
(reactReduxFirebase is correctly added to createStore)
In firebase console I delete all records of user in the users db and the auth section.
But when I sign up again I don't see the role key in the users db neither do I see the console log I've placed in the factory.
I see email, but that seems to be populated regardless along with avatarUrl, displayName and providerData keys
Now that you are on v1.1.5 that option is called profileDecorator, where in 1.2.0-alpha and forward it is called profileFactory. Be careful of the breaking changes when switching versions, but there will be backward compatibility for this in 1.2.0-rc.1.
Some users said that it would make the API more clear to use the word "Factory" for functions that change how things are created. This matches also matches with uploadFileDataFactory.
Most helpful comment
Using popup seems to work
version 1.1.5