Existing Authentication System - Existing Customer

For existing customers, the best practice is to minimize the friction of augmented the user account with blockchain capability. The best approach would be to create a button that triggers the login process with the user’s email address inferred in the request. We’d suggest two options:

  • A button on an account page that calls the same passport.login method that is called above:

user=await passport.login('magicLink',{'email': emailValue})

In this situation, the webpage should already be aware of the email address, so emailValue can be easily populated and the passport Object will automatically trigger the passworldless authentication workflow.

  • Also, an email can be sent to existing users touting the benefits of the program, and offering a link to register. The link can embed the email address and the receiving URL can process the link and trigger the registration/login workflow. For example, you could put a link in the email that redirects to https://www.yoururl.com/registerBlockchain and includes the user’s address.

    Unfortunately, the link cannot be pre-emptive as our links only stay active for 10 minutes and need to be spawned by a browser running a Passport object to receive notification of confirmed login. In the example below, this code runs on a Passport-enabled page and pulls the email address from the querystring (we’d recommend encrypting and decrypting, but for simplicity, we skip that step).

    <script>
      const start = async () => {
          const passport = new window.CredenzaPassport({
        	    chainId: '4',
        	    config: {  /* Headless */   	    },
           })
          const params = new Proxy(new URLSearchParams(window.location.search), {
    	get: (searchParams, prop) => searchParams.get(prop),});
          let emailValue = params.email; // "some_value"
          if (emailValue)
    	await passport.login('magicLink', {'email': emailValue})
          passport.onLogin(async (data) => {
             window.location.href=’ https://www.yoururl.com/registerSuccess’;
           })
        }
        start();

    </script>

So https://www.yoururl.com/[email protected] would take you to a page where the workflow is triggered and, upon confirmation of login check, redirects you to a success page where you can welcome the user and provide some additional information (or maybe collect some additional information).

Note that if a user clicks this after they have already registered, the experience will be the same (although the link does expire after 10 minutes).

Last updated