Single Use Magic Link - here's how

I was trying to make the magic link more secure. Make it easier for people who seem to have issues with passwords and getting recovery emails so I want to send them the magic link . .

BUT the magic link is insecure becuase our user base forward our emails around all the time and it means if forwarded then people have access to someone elses account.

So made this in Airtable automations. 2 steps.

First step you need to create is one that watches the “Last seen time” field that you have set in Softr in the user base/synched with Airtable . ., then when that changes, the code makes SOFTR update the magic link.

Dead simple, you will need your API key, your domain name (the softr one not your pretty one), the record ID you pull from the automation step, and the email address field as that is what it uses for the record.


let table = base.getTable("YOURTARLENAME");
let recordId = input.config().recordid; // Use the correct input variable name
let record = await table.selectRecordAsync(recordId);

let userEmail = record.getCellValue("EMAILADDRESSCOLUMNNAME");

if (userEmail) {
  let apiEndpoint = `https://studio-api.softr.io/v1/api/users/magic-link/generate/${userEmail}`;
  let apiKey = 'YOURAPIKEY';
  let domain = 'YOURDOMAINMUSTBETHESOFTRDOMAINNOTTHEREDIRECTEDONE';

  let response = await fetch(apiEndpoint, {
    method: 'POST',
    headers: {
      'Softr-Api-Key': apiKey,
      'Softr-Domain': domain,
    },
  });

  let magicLink = await response.text(); // Get the response as text
  console.log('Magic link generated:', magicLink); // Log the magic link

  // You can now use the magic link as needed
} else {
  console.error('User email is undefined');
}
1 Like

Thanks for sharing this @Deekay !