Providers

Pricing

Log In
Sign Up

All Posts

INTEGRATIONSENGINEERING

The Three Things to Never Build In Your App: Authentication, Notifications, and Payments

Tejas Kumthekar

May 13, 2021

Back in early 2018, I embarked on a side gig with a few partners - the idea was to make ridesharing socially engaging and fun. We made a ton of mistakes and never really got the product off the launchpad, however in retrospect, the biggest mistakes we made were wasting precious time in writing code for authentication and authorization as well as user notifications. We learned to focus on customer value the hard way. 

Every startup should consider the trade-offs of buying vs building non-differentiated features like authentication, notifications, payments etc. Companies like Auth0 (authentication and authorization platform), Courier (one API to design and deliver notifications across multiple channels), and Stripe (payments infrastructure for the internet) have solved these problems so you, the entrepreneur or developer, can stay laser-focused on what your users truly want out of your product.

Whether you are working on a side gig like me or starting a company, shipping an MVP as quickly as possible helps you get feedback much earlier in the product development cycle. Outsourcing authentication, notifications, and payments tremendously helps in rolling your MVP out the door. The project I mentioned above took months to reach the MVP stage and outsourcing the non-core features could have had a great impact on shortening that time frame.

In this post, we shall focus on a pretty common use case that suits almost every product you will ever build. A user signs up for your product, you save the user details, and send them a welcome message. We will be using Auth0’s post-user registration hook and Courier’s automations feature to build this use case fairly quickly. Let’s dive right in!

With a single “send” API invocation, you can use Courier to reach your customers across one or more channels (email, text, push, or a direct message). We learned through talking to our customers that more often than not, they need something more powerful than just a single “send” action. They need workflows that do multiple actions with a single invocation, like making a single API call to send an email to their users and wait for a desired period of time (inducing a delay) and thereafter send a follow-up email. Another example of a workflow we've heard quite a lot is scheduled notifications, like sending product updates every week. The Courier Automations API gives you the ability to build such workflows and quite literally “automate” your notifications. We will see it in action soon :)

Configuring the Courier side of things

Let's start by creating a free account on Courier, which lets you send up to 10,000 free notifications every month. For the use case we are tackling in this blog post, we will be leveraging Courier’s Automations API. With a single API call, you’ll be able to create a new user profile inside Courier followed by a welcome message to send to this newly created user. The Automations Guide has a detailed walkthrough of all the cool features unlocked via Courier’s Automations API. Today, we will be invoking an automation that has two steps - update-profile and send.

Step 1: update-profile

This step essentially takes any profile JSON object with a unique ID (called recipient ID) and saves it inside Courier. It stays as a permanent record inside Courier that you can further use to send notifications, add it to a list of users/profiles, customize preferences such as opt-in/opt-out, and so on. In our use case, this would originate from Auth0. Here’s how it would look:

{ "action": "update-profile", "recipient_id": "<RECIPIENT_ID>", "profile": { // User properties from Auth0 // plus any more properties you want to attach to the user }, "merge": "none" }

=  A unique ID that you can use to identify your user.

Step 2: send

This step sends a welcome email to the user. We will be sending users an email using Sendgrid as the downstream email provider. This Setup Email using SendGrid guide walks you through sending an email notification using Courier and SendGrid. Once you have created a notification template (with email as the channel using SendGrid), you can construct a send step that looks like this:

{ "action": "send", "profile": { "email": "foo@bar.com" }, "recipient": "<RECIPIENT_ID>", "template": "<TEMPLATE_ID>" }

= User ID you are sending the notification to (same as step 1)

= ID of the notification template you just created for welcoming the new user.

Final Payload

Here’s how the payload to automations/invoke endpoint will look:

{ "automation":{ "steps":[ { "action":"update-profile", "recipient_id":"unique-foo", "profile":{ "email":"foo@bar.com", "first_name":"Foo", "last_name":"Bar" }, "merge":"none" }, { "action":"send", "profile":{ "email":"foo@bar.com" }, "template":"AAZRHC4TDAMEHKGJHDAA9199WMVH", "recipient":"unique-foo" } ] } }

Configuring the Auth0 side of things

This post assumes you have a basic understanding of Auth0 and have set up an application in Auth0 before, but if not, follow the Auth0 Getting Started guide. 

Let's take a step back and imagine how things would look if there was no integration between Auth0 and Courier. Every time you would have a new user signed up with Auth0, you would have to explicitly invoke Courier to create their profile and send them a welcome message. This would require writing more code in your application, deploying it reliably and maintaining it as your application scales. Having Auth0 and Courier integrated out of the box gives you great leverage in the form of speed and agility to move fast - without having to maintain a single line of code in your infrastructure.

We want Auth0 + Courier to work together automatically - like magic. Once a new user registers for the product, we want to trigger Courier’s Invoke Automation API - this is where Auth0 Post-User Registration comes into picture. Here’s the code that lives behind Auth0 hook and uses the Courier Node.js SDK to invoke the automation dynamically based on the user obtained via Auth0 registration.

module.exports = async function (user, context, cb) { const { CourierClient } = require("@trycourier/courier"); const courier = CourierClient({ authorizationToken: context.webtask.secrets.COURIER_AUTH_TOKEN }); await courier.automations.invokeAdHocAutomation({ automation: { steps: [ { action: "update-profile", recipient_id: user.id, profile: { email: user.email, username: user.username, phoneNumber: user.phoneNumber }, merge: "none" }, { action: "send", profile:{ email: user.email }, template: "AAZRHC4TDAMEHKGJHDAA9199WMVH", recipient: user.id } ] } }); cb(); };

This saves the user profile to Courier followed by sending the welcome email you configured in the template. 

The profiles can be viewed in Courier UI under Data Recipients tab:

Next, the welcome email is sent to the user - it looks just like how you configured it to look in Courier. Just to give an example of how a notification could look:

Feel the Magic Automation?

We just saw how Auth0 + Courier can help you automagically build user onboarding flow without having to maintain any code in your own system, and as we all know, the best code is no code that allows us to focus our energies where they are most needed.

Of course, Courier Integrates with more than just Auth0. Just like we sent an email using Sendgrid in this blog post, you can use any of these channels - email, SMS, push, direct messaging, etc. with providers like Mailgun, Twilio, and Slack with just a single API to power your notification workflows. Sign up for a free Courier account. You build the next big thing and let us handle the notifications for you. 🚀

Additional References -

Courier Docs

Auth0 docs

Courier Node.js SDK

Subscribe

More from Integrations

INTEGRATIONS

Who Knew Email Subjects Are So Complicated

Here is our journey into email subjects upon finding out that Microsoft Outlook didn’t work with certain...

Riley Napier

June 10, 2021

INTEGRATIONS

Follow These Considerations For An Effective Push Notification System Design

Push notifications are generally an effective mechanism for user engagement, but it's no longer enough t...

Kevin Krige

April 01, 2021

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Product

Company

© 2021 Courier. All rights reserved.