Posts

Secure Your Sitecore XM Cloud App with NextAuth.js: Authentication & Authorization

Modern digital experiences demand secure, personalized, and seamless user access. In projects built with Sitecore XM Cloud and Next.js , combining NextAuth.js with Azure AD B2C offers a robust solution for authentication, while custom middleware provides fine-grained authorization. In this blog post, I’ll walk you through how we implemented both in a Sitecore XM Cloud project. Authentication with Azure AD B2C and NextAuth.js We’re using NextAuth.js for handling authentication via Azure AD B2C . This provider allows us to manage sign-in, profile editing, and password reset flows while integrating additional user metadata from Salesforce. Key Features Azure AD B2C handles user identity and federation. NextAuth.js supports multiple user flows as separate providers. JWT-based sessions allow for stateless authentication across SSR and API routes. Here’s the core setup in /pages/api/auth/[...nextauth].ts : interface AzureADB2CProfile {   sub: string;   given_na...

Sitecore XM Cloud - Language Fallback on Item Buckets

Today, I ran into an intriguing issue while troubleshooting GraphQL queries in a Sitecore XM Cloud implementation. I observed that certain queries were unexpectedly failing to return fallback values in the preview API, despite working seamlessly with the delivery API. After investigating, I realized this behavior occurs specifically with search-based GraphQL queries. Unlike regular content queries, search queries depend on data present directly in the search index. As it turns out, fallback values aren't included in the search index by default. To resolve this, you'll need to explicitly enable item fallback in your search index configuration. Fortunately, Sitecore provides detailed guidance on how to adjust your settings correctly :  This is the patch file you will need to deploy to your XM Cloud environment to enable item level fallback (the same can be done for field level fallback).  <?xml version="1.0" encoding="utf-8"?> <configuration xmlns:pat...

Sitecore Content Hub - Reset Password for Mixed Users (SSO + CH Credentials)

Image
I recently encountered a situation where users who had their accounts created directly in Content Hub and also logged in through Sitecore SSO faced difficulties when attempting to reset their Content Hub credentials. The issue stemmed from the fact that the reset password button disappeared after a user signed in using SSO. In this blog post, we will delve into this problem and provide a detailed guide on how to address it. When a regular user tries to reset their password, they typically see the following interface: However, after the same user logs in via Sitecore SSO, the interface undergoes a transformation and ends up looking like this: Sitecore Content Hub offers users the option to sign in using their Content Hub credentials or their Sitecore Authentication. In theory, users should still be able to reset their regular Content Hub credentials even when logged in through SSO. However, due to the disappearance of the Reset Password button, the only way to achieve this is through t...

Sitecore Powershell Extensions - Upload data to Sitecore from a csv file

Image
As Sitecore developers or content managers working with large amounts of data we often need a way to update items in bulk using CSV files. In this blog post, I'll walk you through how to use a script to update fields in Sitecore items based on a corresponding CSV file entry. In this specific example, we will use Price Codes already existing in Sitecore items and update the corresponding Price field. However, this script can be extended to support different scenarios. The final version of the script is the following: $fieldRequiredValidator = { if([string]::IsNullOrEmpty($variable.Value)){ $variable.Error = "Please provide a value." } } $dialogProps = @{ Parameters = @( @{ Name = "itemPath"; Title="Root"; Tooltip="The root of the items to be updated"; Source="Datasource=/sitecore/content/"; editor="droptree";}, @{ Name = "csvPath"; Value="...

Sitecore Content Hub DAM - Custom Crop Tutorial

In this short video I will show you how you can create custom public links with any dimensions from the Sitecore Connect for Content Hub connector:   

Sitecore Content Hub - Using Transformations on our Sitecore site

Transformations are a very important (and often ignored) feature, it basically lets you crop images on the fly and set the quality of images, without the need of creating custom public links. This is Sitecore's documentation related to Content Hub Transformations , however, how do we actually use these from a Sitecore site?  The short answer is you can't use Transformations using the Sitecore Connect for Content Hub connector. I have talked to Sitecore Support and they added a feature request so that public links inserted from the connector support transformations (reference number 518659).  In the meantime, what we can do, is add the transformations programmatically (I know, it's not the best) but if we want to leverage Content Hub Transformations on our Sitecore sites that's the only thing we can do for now. Sitecore support recommended using something like this in code:  Sitecore.Data.Fields.XmlField imageField = Sitecore.Context.Item.Fields["image"]; str...

Sitecore Tip: Content Author minimum roles

 At a bare minimum, you want your content authors to have these OOTB roles:  sitecore\Sitecore Client Advanced Publishing sitecore\Sitecore Client Designing sitecore\Sitecore Client Authoring You should also have custom roles to further classify your content authors, e.g.:  Site Owner (Content Author "admin" for a specific site)  Workflow Approver/Reader (to push/approve items through workflows) etc