Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why can you login with provider but not create user with provider? #33

Closed
rhysburnie opened this issue Jan 18, 2017 · 8 comments
Closed
Assignees
Labels

Comments

@rhysburnie
Copy link

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

@rhysburnie
Copy link
Author

the email would be taken from the auth record

@rhysburnie
Copy link
Author

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

@prescottprue prescottprue self-assigned this Jan 18, 2017
@prescottprue
Copy link
Owner

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.

@rhysburnie
Copy link
Author

rhysburnie commented Jan 18, 2017

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.

@prescottprue
Copy link
Owner

  1. Are you using redirect or popup?
  2. What version of react-redux-firebase are you currently using?
  3. Can you Provide a repo where the issue is reproducible? I'm not seeing an issue when using the example

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).

@rhysburnie
Copy link
Author

Using popup seems to work
version 1.1.5

@rhysburnie
Copy link
Author

rhysburnie commented Jan 20, 2017

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

@prescottprue
Copy link
Owner

prescottprue commented Jan 20, 2017

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.

prescottprue added a commit that referenced this issue Jan 23, 2017
## Breaking Changes
- Data gathered during population is now normalized in redux [following defined redux practice of normalizing](http://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html) (instead of placed directly into nested object). **THIS BREAKS v1.1.5 AND EARLIER IMPLEMENTATIONS OF POPULATE**. Now population will require the usage of `populatedDataToJS`.
- `populatedDataToJS` function added to helpers (returns data populated from normalized state)
- `profileDecorator` config option renamed to `profileFactory` for clarity (`profileDecorator` still supported, but will throw deprecation warning)
- default file metadata written to database includes `downloadURL` instead of `downloadURLs` array
- Meta values (`timestamp`, `requesting`, `requested`) are now stored by string key (keeps invalid keyPath error from showing up)
- `enableRedirectHandling` config param added to enable/disable auth redirect handling (enabled by default, which can cause breakage in none HTTP/HTTPS environments)

## Enhancements
- `once` queries no longer cause `off` error due to unmounting non existent listener (fixes #36)
- login with auth redirect no longer returns null  and other redirect handling improvements (#33)
- deep set `invalid keyPath` error fixed in data section of reducer (deep list is null first then has value)
- `fileMetadataFactory` config option added to allow control of metadata written to database when using `uploadFile` and `uploadFiles`
- Profile Params Populate now working for both object and string notation
- Config params type validation
- Roadmap updated with `v2.0.0` plans
- `profileDecorator` backwards compatibility is included (with a deprecation warning)
- `CODE_OF_CONDUCT.md` and `PATRONS.md` added
- Docs + Tests updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants