Component visibility based on signed in user

Hi,

I want to selectively show components on the screen based on, if the signed-in user is an existing user or a new user. Just so that you are aware, in my implementation I have a Users sheet that captures email of the user. Therefore, if the user is a new user the email will not be listed there.

I am having a hard time implementing selective visibility of components. Any assistance is appreciated.

Thank you.

If they are signed-in users, and you have enabled user profiles, you should have the email already. Do you have a public app?

Yes, the link to the app is

I see you’re requiring users to sign in here, what I meant to ask what if you don’t require users to sign in to see the app’s content, so it’s not the case here.

In that case, have you enabled user profiles?

I went through this, but couldn’t figure out where to look for to check if user profiles are enabled.

Make sure you are in the Layout view…

Screen Shot 2021-05-14 at 10.02.15 PM

  • then click on the hamburger menu (top left in the phone display)
  • then click on the area at the top where your email address is
  • then you should see this on the right…

2 Likes

Thank you. Yes, I navigated to the screen in your image above and found that “Sheet” was not pointing to my Users sheet. Does this mean I did not have User profiles enabled?

Sounds like it, yes.

It needs to be pointing at a sheet that has at least the following three columns:

  • Email (must be an Email column)
  • Name (must be a Text column)
  • Image (must be an Image column)

The column names are not important, but the column types are.

1 Like

OK. Great! Let me give that a try and revert.

@Darren_Murphy That was easy, thank you. But realized that due to the privacy settings the email id’s are anonymized. My implementation requires the actual email ID for a subsequent interaction. Any idea how do I achieve it without upgrading my account?

Without going pro, the next best method would be to explicitly ask your users to provide their “real” email addresses, and store them in a separate column in your Users sheet.

You could do it as part of an onboarding process, so it doesn’t appear too odd to your users.

Yes, was thinking on similar lines. Thank you for the help @Darren_Murphy !

I was having a thought about using a script to replace all the anonymous emails by the real email once the user inputs it.

Let’s say the flow is like this, assuming you already had the anonymous email.

  • Ask for the user’s real email writing to a user-specific column, then set it to the Sheet column using a button (to avoid triggering the script when the user has not finished the input when you let them write directly to the column).

  • Once the button is clicked, use the script to find the anonymous email associated with the real email that has just been put in, then find that anonymous email across all Sheets and replace it with the real email.

Is this possible?

1 Like

I had a similar idea some months ago (for different reasons), but I ended up not going through with it as I decided it wasn’t really a good idea…

I still have the code that I wrote to do this, you’d be welcome to a copy if you’d like to experiment with it?

2 Likes

Yeah would love to. Thanks in advance.

Here you go. Offered “as is”, with no warranty :stuck_out_tongue:
Just looking through it, I’d probably do it quite differently now.
That’s always the way, you look at code you wrote in the past and think “what on earth was I smoking back then!?” :rofl: :crazy_face:

function check_user_email_updates() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var user_map = build_user_map();
  var sheet = ss.getSheetByName('User Email Updates');
  var row = 3;
  while (row <= sheet.getLastRow()) {
    var data = sheet.getRange(row, 1, 1, 6).getValues();
    var status = data[0][5];
    if (status == 'Pending') {
      var old_email = data[0][1];
      var new_email = data[0][2].trim();
      var username = user_map[old_email];
      console.log(['Updating email address for ', username, old_email, new_email]);
      search_and_replace(data[0], data[1]);
      var d = new Date();
      sheet.getRange(row, 1).setValue(username);
      sheet.getRange(row, 5).setValue(d);
      sheet.getRange(row, 6).setValue('Completed');
    }
    row++;
  }
  sheet.getRange(2, 4, sheet.getLastRow(), 2).setNumberFormat('yyyy-mm-dd hh:mm:ss').setHorizontalAlignment('left');
  format_sheet('User Email Updates');
}

function search_and_replace(from, to, sheets) {
  sheets = [
    'Authorised Emails',
    'Payments',
    'App:Responses',
    'Realtime Pool',
    'Pool',
    'Private Leaderboards',
    'Users',
    'Response Archive',
    'User Picks',
    'Player View Choices',
    'App: Logins',
    'App: Comments'
  ];
  sheets.forEach(function (sheet) {
    process_sheet(sheet, from, to);
  });
}

function process_sheet(sheet, from, to) {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
  var values = sheet.getDataRange().getValues();
  replace_in_sheet(values, from, to);
  sheet.getDataRange().setValues(values);
}

function replace_in_sheet(values, from, to) {
  for (var row in values) {
    var replaced_values = values[row].map(function (original_value) {
      return original_value.toString().replace(from, to);
    });
    values[row] = replaced_values;
  }
}
5 Likes

If I am making the user enter his email, I might as well make him edit the row in the user profile that corresponds to him. Isn’t this possible?

In fact I did not see the recent responses on this thread and initiated a new one here.