In my previous stories, I showed you comprehensive step-by-step guides on how to start with Next.js 14 from scratch. You will find advice on how to set up the project, how to style it, how to integrate an amazing CMS like Contentful with ease, and how to sync your data with Algolia (state-of-the-art AI-powered on-site search and Data Engine). All you need is a free GitHub account, which you can use for the social login on the mentioned services. They all offer generous free plans, which are enough for a normal website/blog.
But one piece is missing, and that's user registration and login (Authentication and Authorization), which is crucial nowadays.
Auth Solution ShortList
There are many offerings on the market, but let’s focus on the big ones like Auth0, Aws, Microsoft, and Google.
Auth0: Auth0 is a customizable identity management platform supporting B2B and B2C scenarios. It offers features like social login, multi-factor authentication, and fully customizable universal login pages. Auth0 is known for its developer-friendly approach and extensive documentation.
Amazon Cognito: Part of Amazon Web Services, Amazon Cognito provides a simple and secure user sign-up, sign-in, and access control for mobile and web applications. It supports integration with social identity providers as well as SAML and OpenID Connect.
Google Firebase Auth: This service provides backend support and ready-to-use UI libraries to authenticate users in your app. It supports authentication using passwords, phone numbers, popular federated identity providers like Google, Facebook, and Twitter, and more. Firebase Auth integrates seamlessly with other Firebase services and is designed to be easily implemented and managed, enhancing the user experience.
Azure AD B2C: Offers a highly scalable, secure, and customizable identity management solution. Its strengths lie in supporting diverse authentication methods, integrating seamlessly with numerous applications, and providing robust compliance features, making it ideal for organizations looking to manage large-scale consumer identities efficiently.
In this post, I will focus on the preparation of a Microsoft Azure AD B2C Tenant, which we will then use in the real-world Next.js 14 example, which has already integrated Contentful as CMS, Algolia as on-site search, Google or Piwik for analytics, etc.
Azure AD B2C offers a free plan with a limit of 50,000 MAU (monthly active users). If you exceed this limit, you can switch to a pay-as-you-go solution, but 50k Users is a lot, trust me. ;-) 50 K MAU is also the limit for Google Firebase and AWS Cognito.
Azure Account Creation
As I said at the beginning, the easiest way is to create a free GitHub account, which you can reuse to create the additional accounts you need. In this example, we will create an Azure account with a Subscription to create the AD B2C Tenant. The Azure account creation is free, but you need to provide a payment method (I used a credit card) to finish the creation process.
Go to https://signup.live.com/signup and provide your mail address, Name, Region, and birth date. After that, you will receive a confirmation mail/OTP code, and you will be done.
![Microsoft-account-Home](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F1we1a7B29veffGhLf0Bigy%2Ff82694c9f7491682485db9ea5fadf6ad%2FMicrosoft-account-Home.png&w=3840&q=75)
Then we go to portal.azure.com, and you're already logged in. Microsoft has already created a subscription for you that is connected to a new Azure AD Directory.
Small side note on the naming because Microsoft decided some time ago to rename the service Active Directory to Entra ID, which is kind of weird for an Auth solution, but that’s Microsoft’s secret ;-)
![Settings-Microsoft-Azure](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F1P6279uQfRpB860acBvPRS%2Fcb41c041e5d209ec5408661fdc9dc16a%2FSettings-Microsoft-Azure.png&w=3840&q=75)
Now, we click on the hamburger menu in the upper left corner and select “Home,” which leads us to this screen.
![Home-Azure-Create-Entraid](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F2OxJSHeoVOM1NRa7zOwq0j%2Fb5f17bb5f779c597eb9e24627ac4cd07%2FHome-Azure-Create-Entraid.png&w=3840&q=75)
Creation of new resource “Entra ID”
We click on “Create a resource,” which leads to a new page where we can search for the service we are going to create.
Search for Entra ID and select “Create” at the bottom of the result card.
![Create-a-tenant-Microsoft-Azure-1](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F1XEg3dt6zOHJCizxQ9q7iR%2F6ac3a7d87a40c746c89c1235735ad103%2FCreate-a-tenant-Microsoft-Azure-1.png&w=3840&q=75)
Provide the needed data and keep attention on the “Initial domain name” because it will be reused later and will be part of your tenant url.
![Create-a-tenant-Microsoft-Azure-2](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F4C4JwueKTsILE03G8WTAVx%2F532f5e629cf97678cf4ef2209814ee10%2FCreate-a-tenant-Microsoft-Azure-2.png&w=3840&q=75)
Click on “Next: Review + Create,” and as soon as the creation process is finished, you can see the second tenant under the directory overview.
![Overview-directories-two-tenants](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2FAxC7ygvvHVy8g7uvwBO8S%2F0468f278ce5d19edc6baa27d15f929e7%2FOverview-directories-two-tenants.png&w=3840&q=75)
If not yet selected, select the new AD B2C tenant.
Now, we can start with the creation of two new app registrations. You find the menu point under manage within your AD B2c tenant on the left side.
1 — Localhost
2- Production Site
![Azure-AD-B2C-Default-App-Registration](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F38yS4Sl69vMCtbPMuwcBtQ%2F0653acc03deff858e71eeb6c13e7c612%2FAzure-AD-B2C-Default-App-Registration.png&w=3840&q=75)
There is also one default user, already present in the directory, which we need for the certain actions. I will explain it later. Below you can see the system-assigned rights for those user.
![AD-Default-App-Registration-Rights](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F7avrTVWr6v9ixC0R4AUq19%2Fcda590a180e59d3bbbd95bb4e7164619%2FAD-Default-App-Registration-Rights.png&w=3840&q=75)
Custom User Attributes
Let’s return to the Azure AD B2C Overview page and then select “User attributes” because we want to add a new custom attribute “Role”, which we will need in the next story, when we integrate the Azure AD B2C tenant into our Next.js 14 project.
![Azure-Addin-Custom-Attribute](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F7c8z9FvXb66JSCsxugcxNd%2F2e351f7d66b3c3706531c5031122510d%2FAzure-Addin-Custom-Attribute.png&w=3840&q=75)
Adding a new User Flow
![Azure-AD-B2C-Uesrflow](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F2awleBYB0QPsPHckqpT8rv%2F9ba7a759dd0a65eee0a8e0cda4fcfb14%2FAzure-AD-B2C-Uesrflow.png&w=3840&q=75)
Now we click on “New User Flow” upper left
![Create-a-user-flow-Microsoft-Azure](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F2yFhvnSUMTsHz5MIK3EWEn%2Fa9858e536dd54759d31520b41a67906f%2FCreate-a-user-flow-Microsoft-Azure.png&w=3840&q=75)
and then “Create”.
![Create-Microsoft-AD-Userflow](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F6gzJP1L0YlpmCZYTyw1jAK%2F0bdae487bb18b9f9b5aacdb4be08ad6c%2FCreate-Microsoft-AD-Userflow.png&w=3840&q=75)
Fill out the mandatory fields and enable the correct attributes for the column “Collect Attribute” and “Return Claim”.
Collect Attribute are the attributes that we will ask during the registration process and Return claim are the attributes, which the Azure Endpoint will send us back after a successful login.
Now with the Userflow in place we can finally create the needed app registrations that we need in our Next.js14 project. So let’s go back to the Azure tenant overview and click on “New Registration” upper left.
![Register-an-application-Microsoft-Azure](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F3AOkOq4taOjJ4fJpc0oxcY%2F18a3c453cf9ca4cadc4a932d4ebff0ca%2FRegister-an-application-Microsoft-Azure.png&w=3840&q=75)
As soon as the new app registration is ready click on “Localhost” and select “Certificates & secrets” on the left menu, then select the tab “Client secrets” and click on “New client secret”.
![AD-Adding-Secrets](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F5ZNjPUf95u00ZnGtUOE30O%2Fd559e82f097f538e87ce2501424d638f%2FAD-Adding-Secrets.png&w=3840&q=75)
Use “Localhost” for the description field on the upper right and use the recommended expiration of 180 days. Click save and copy the “Secret Value” which you will see after the creation because we will need it for the Next.js project.
![AD-Localhost-User-Overview](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fdlgtvh48u7by%2F61AcuX3BOi7VlqvZZQnFiP%2F2cd8638f641b614868e63f22037faf97%2FAD-Localhost-User-Overview.png&w=3840&q=75)
Great, now we are done, and we have the information that we need for the Next.js 14 integration.
Cloudapp-dev, and before you leave us
Thank you for reading until the end. Before you go:
Please consider clapping and following the writer! 👏 on our Medium Account