Random 401 errors

It seems Fauna and Auth0 integration is broken for the last few days.
Also, I got a lot of random errors from the dashboard.
What happening with Fauna? Are you closing the business?

Hi Daniel,

Just to reassure you, no, we are not closing the business. Errors can happen at times, and we’ll work with you to get them resolved. But I promise, we’re not going anywhere.

From the information you provided in the community Slack it looks like this might be a driver version incompatibility between Fauna and Auth0. We’re working with our peers at Auth0 to get this resolved now. I’ll update when we know more.

Cory

OK. But it still does not work, so please downgrade my Team subscription to Individual, thank you.

I think it’s probably related to some changes recently made to driver, because it works randomly. I don’t think Fauna itself is broken. For the record, this is Auth0 rule code:

function saveUser(user, context, callback) {
  const Fauna = require('faunadb@4.1.1');
  const { query } = Fauna;
  const {
    Create,
    Collection,
    Now,
    Exists,
    Match,
    Index,
    If,
    Update,
    Let,
    Var,
    Select,
    Get,
  } = query;

  const _ = require('lodash');

  let userPicture = user.picture;

  if (context.connection === 'facebook') {
    const fbIdentity = _.find(user.identities, { connection: 'facebook' });
    // for more sizes and types of images that can be returned, see:
    // https://developers.facebook.com/docs/graph-api/reference/user/picture/
    const pictureType = 'large';
    userPicture =
      'https://graph.facebook.com/v2.5/' +
      fbIdentity.user_id +
      '/picture?type=' +
      pictureType;
  }

  const client = new Fauna.Client({
    secret: configuration.Fauna_SERVER_KEY,
  });

  client
    .query(
      Let(
        {
          user: Match(Index('usersByAuth0UserId'), user.user_id),
        },
        If(
          Exists(Var('user')),
          Update(Select('ref', Get(Var('user'))), {
            data: {
              email: user.email,
              facebook: {
                picture: userPicture,
                picture_large: user.picture_large,
              },
            },
          }),
          Create(Collection('users'), {
            data: {
              createdAt: Now(),
              auth0UserId: user.user_id,
              email: user.email,
              name: user.name.trim().slice(0, 64),
              facebook: {
                picture: userPicture,
                picture_large: user.picture_large,
              },
            },
          }),
        ),
      ),
    )
    .then(
      () => {
        callback(null, user, context);
      },
      (error) => {
        console.log(error);
        callback(null, user, context);
      },
    );
}

Meanwhile, I decided I don’t want my app to depend on Auth0. The platform, which does not allow me the code I need is a no-go for my use case. Also, the pricing.

Hi Daniel,

Thanks for the code example. We’ll see if we can reproduce the issue. We’re also working with the team at Auth0 to get to a resolution.

Fyi, if you’re on the Team plan, you have access to professional support at support.fauna.com. We’ll keep working with you here but in case anything else were to come up that you needed a quicker response on that’s the way to go.

Cory

1 Like