In this step-by-step guide, we'll show you how to integrate Xano's MagicLink extension with Bubble to enable passwordless login for your users. With MagicLink, your users can log in simply by clicking a secure link sent to their email, eliminating the need to remember and manage passwords.
Setting Up the MagicLink Function
First, we'll need to make a small modification to the `generateMagicLink` function provided by the MagicLink extension.
- In Xano, go to the Library section and locate the `generateMagicLink` function.
- Click on the function to open the editor.
- Scroll down to line 9, where the `magicLink` variable is created using the `concat` filter.
- Add `?token=` as a separator before the `magicLink` variable. This will allow us to include the magic token in the URL, making it easier to retrieve later.
- Click Update* and then *Save to apply the changes.
Configuring API Endpoints in Xano
Next, we'll set up the necessary API endpoints in Xano.
- Go to the API section and locate the `authMagicLink` endpoint. This endpoint accepts the user's email address and sends them the MagicLink.
- Copy the URL for the `authMagicLink` endpoint to your clipboard.
- Locate the `authMagicLogin` endpoint. This endpoint will exchange the MagicLink token for an authorization token, enabling user authentication.
- Locate the `authMe` endpoint. This endpoint retrieves the authenticated user's information using the authorization token.
Setting Up API Calls in Bubble
With the Xano setup complete, let's move to Bubble and configure the API calls.
- In Bubble, add a new API called "MagicLink."
- Create a new API call called "Request MagicLink" and paste the `authMagicLink` endpoint URL from Xano.
- Add an email parameter and set the value to your test email address (or a user's email address).
- Create a new API call called "Login with MagicLink" and paste the `authMagicLogin` endpoint URL from Xano.
- Add the body parameter by copying the example from the Xano endpoint documentation.
- Replace the token value with a valid MagicLink token obtained by running the `generateMagicLink` function in Xano.
- Create a new API call called "Authenticated Me" and paste the `authMe` endpoint URL from Xano.
- Add an authorization header with the value `Bearer [auth_token]`, replacing `[auth_token]` with a valid authorization token obtained from Xano.
Connecting Bubble Workflows
Now, let's connect the API calls to Bubble workflows.
- On the "Send Link to Log In" button, set up a workflow to call the "Request MagicLink" API when the button is clicked.
- Create a new page called "Authenticated Page" and set the correct redirect URI in the MagicLink extension settings in Xano.
- On the "Authenticated Page," set up a workflow to call the "Login with MagicLink" API when the page loads, using the `token` parameter from the URL.
- After the "Login with MagicLink" API call, navigate to the "Authenticated Page" and send the `auth_token` as a page parameter.
- On the "Authenticated Page" design, display the user's information by inserting dynamic data from the "Authenticated Me" API call, using the `auth_token` parameter for authorization.
Testing the Passwordless Login
With everything set up, you can now test the passwordless login flow.
- Preview the index page in Bubble and enter your test email address.
- Click "Send Link to Log In" to trigger the `authMagicLink` API call.
- Check your email inbox for the MagicLink.
- Click the MagicLink in your email to be redirected to the "Authenticated Page" in Bubble.
- The "Authenticated Page" should display your user information, proving successful authentication via the MagicLink.
Congratulations! You've successfully integrated Xano's MagicLink extension with Bubble, enabling a seamless passwordless login experience for your users.