Skip to content

Does user relationship work with firebase auth? #609

Answered by charlesfries
ELepolt asked this question in Q&A
Discussion options

You must be logged in to vote

I always end up keeping my own collection of users, indexed by the userID provided by Firebase. Emberfire does include authentication functions, but you need to keep your own collection of users, especially if you need to save custom attributes on your users (as far as I know).

Model hook of my authenticated route:

async model() {
  let { uid: id } = this.session.data.authenticated.user;

  let user;
  try {
    user = await this.store.findRecord('user', id);
  } catch(err) {
    if (err.message === 'The adapter could not find the resource') {
      this.store.recordForId('user', id).unloadRecord();
      user = this.store.createRecord('user', { id });
    }
  }

  if (!user) throw 'User …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jamesdaniels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #609 on December 10, 2020 07:17.