How do you open a specific link (URL) for a logged-in user

Hello, I hope you'll do good.
I am on a project that makes users to register and login and all the credentials are stored in a Google spreadsheet using an app script.

What am I looking for is how can I make each user open its link when he is logged-in that also stored in google sheet.
Thank you.

Return the link when the user signs in, and open it in a webviewer.

I am new to this, can you please provide more help, thank you.

function doPost(e) {

var ss = SpreadsheetApp.openById('1K3zIwnKB9IjjNqS7HWZowy5aQcmyoOjo2ILJy6Feytqg');
var sh = ss.getSheetByName("Sheet1");
var msg;

if (e.parameter.fn == "getusers" ) {
   var loginData = sh.getDataRange().getValues();
   var users = [];
   for ( var i = 1; i < loginData.length; i++ ) {
   users.push(loginData[i][0]);
   }
     msg = JSON.stringify(users);
 }
else if ( e.parameter.fn == "register" ) {
    sh.appendRow([e.parameter.email,e.parameter.pass]);
    msg = "user registered";  
  }
else if ( e.parameter.fn == "login" ) {
  var loginData = sh.getDataRange().getValues();
   for ( var i = 0; i < loginData.length; i++ ) {
     if ( e.parameter.email == loginData[i][0] && e.parameter.pass == loginData[i][1] ) {
       msg = { success: true, link: loginData[i][2] };
       
     }
   }
}
else if ( e.parameter.fn == "reset" ) {
  var newpass = makePasswd();
  var newHash = makeHash(newpass,e.parameter.key);
  //change hash for email in sheet
  var loginData = sh.getDataRange().getValues();
   for ( var i = 0; i < loginData.length; i++ ) {
     if ( e.parameter.email == loginData[i][0]) {
      var rngp = sh.getRange(i+1,2);
      rngp.setValue(newHash);
       msg = "password reset";
     }
   }
  //send email with new password
  GmailApp.sendEmail(e.parameter.email,"From AI2","Your new password is: " + newpass + "\n\n Use this new password to login.\n\n Thank you.");
}
return ContentService.createTextOutput(JSON.stringify(msg));

}

function makePasswd() {
  var passwd = '';
  var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!.#*@_';
  for (i=1;i<8;i++) {
    var c = Math.floor(Math.random()*chars.length + 1);
    passwd += chars.charAt(c)
  }
  return passwd;
}

function makeHash(message,key){
  var getHash = Utilities.computeHmacSha256Signature(message,key).reduce(function(str,chr){
  chr = (chr < 0 ? chr + 256 : chr).toString(16);
  return str + (chr.length==1?'0':'') + chr;
  },'');;
  return getHash;
}

Does the script still correct?

Did you try it out ?

Does it work ?

If not, what is happening/going wrong?

Yes, I've tried it
No
I get this msg when ever the user tries to log in or register.

If something starts with DOCTYPE, it is an error message in html format and not what you might expect...

What about providing a screenshot of your relevant blocks? Where are you using the is in list block?

See also

Taifun

What about following the previously mentioned link to find out the response content?

Here is the link again

Taifun

I also cannot see how the link is being set when a user registers, or is this done later by an admin directly to the spreadsheet?

This:

else if ( e.parameter.fn == "login" ) {
  var loginData = sh.getDataRange().getValues();
   for ( var i = 0; i < loginData.length; i++ ) {
     if ( e.parameter.email == loginData[i][0] && e.parameter.pass == loginData[i][1] ) {
       msg = { success: true, link: loginData[i][2] };
       
     }
   }
}

looks alright, although your msg is not really json or a string...

perhaps:

msg = '{"success": true, "link":' + loginData[i][2] + '}';

This, in Web1.GotText, will also need re-working:

image

Now i have this msg

No links are set by admin manually

Your error:

This is the useful part, which relates to this part of your script:

Possible causes:

  1. The ID is incorrect
  2. Your script is incorrectly deployed
    • Have you deployed your script for "Anyone" ?
    • Is the spreadsheet owned/shared with the script creator ? (google account)
    • permissions have not been correctly reviewed

A guide:

The ID, am sure it's correct, or the issue will still remain even when I undo the changes to the script
Yes i deploy to Anyone

your result will be returned in a table in csv format
after fixing your initial bug (the DOCTYPE error) then you should use the "list from csv table" block to convert the csv table into a list... you are currently using the "list to csv table" block...

Taifun