Frequently Asked Questions

Technical Setup & Integration

What are the prerequisites for integrating NextAuth.js with Hygraph?

To integrate NextAuth.js with Hygraph, you need a Hygraph account, a Next.js application, your Hygraph endpoint, and a Permanent Auth Token with permissions to query and mutate the NextUser model. (Source)

How do I configure the NextUser model in Hygraph for authentication?

Create a NextUser model in Hygraph with two fields: Email (single line text, required, unique) and Password (single line text, required, API only). Set the Password field to API only in advanced visibility settings. (Source)

Which dependencies are required for setting up NextAuth.js with Hygraph?

You need to install next-auth, bcrypt, graphql-request, and graphql to set up authentication between NextAuth.js and Hygraph. (Source)

How do I securely store user passwords when using Hygraph with NextAuth.js?

User passwords should be hashed using the bcrypt library before storing them in Hygraph. The Password field in the NextUser model should be set to API only for security. (Source)

How do I configure the CredentialsProvider in NextAuth.js for Hygraph authentication?

In your Next.js project, add the [...nextauth].js file in pages/api/auth and use the CredentialsProvider to handle email and password authentication. Implement an authorize function that checks for existing users in Hygraph and creates new users if needed. (Source)

How do I use GraphQL queries and mutations for user authentication in Hygraph?

Use a GraphQL client to query for users by email and create new users with email and hashed password. Example queries include GetUserByEmail and CreateNextUserByEmail. (Source)

How do I display the current user state in a Next.js app using NextAuth.js and Hygraph?

Use the useSession hook from next-auth/react to access session data and conditionally render sign-in/sign-out links and user information based on authentication state. (Source)

Where can I find a demo of Next.js authentication with NextAuth.js and Hygraph?

A demo is provided in the tutorial, showing the sign-in/sign-out flow and user state management. (Source)

What environment variables are needed for Hygraph integration?

You need to set HYGRAPH_ENDPOINT and HYGRAPH_TOKEN in your .env file to connect your Next.js app to Hygraph. (Source)

How do I handle user creation if the user does not exist in Hygraph?

If a user does not exist, use a GraphQL mutation to create a new user with the provided email and hashed password. This is handled in the authorize function of the CredentialsProvider. (Source)

How do I verify user credentials with Hygraph and NextAuth.js?

Use the compare function from bcrypt to verify the provided password against the hashed password stored in Hygraph. If the credentials are incorrect, throw an error in the authorize function. (Source)

How do I wrap my Next.js application with SessionProvider for authentication?

Update pages/_app.[js,ts] to wrap your application with SessionProvider, passing the session from component props to enable authentication state management. (Source)

What is the recommended way to manage user sessions in Next.js with Hygraph?

Use NextAuth.js's SessionProvider and useSession hook to manage user sessions and authentication state in your Next.js app. (Source)

Can I use Hygraph with other authentication providers besides NextAuth.js?

The tutorial focuses on NextAuth.js, but Hygraph's flexible API and schema allow integration with other authentication providers as long as you manage user data and authentication flows appropriately. (Source)

Where can I find more tutorials on integrating Hygraph with popular frameworks?

Hygraph's blog features tutorials on integrating with frameworks like Next.js, Nuxt.js, and more. Explore the blog for guides on multilingual products, headless CMS comparisons, and best practices. (Source)

How do I get support for technical issues when integrating Hygraph?

You can access Hygraph's documentation, join the community Slack channel, or contact support via the website for help with technical issues. (Source)

Is there a newsletter for updates on Hygraph features and tutorials?

Yes, you can sign up for Hygraph's newsletter to receive updates on releases, industry news, and new tutorials. (Source)

What is the role of Permanent Auth Tokens in Hygraph authentication?

Permanent Auth Tokens in Hygraph are used to authorize GraphQL requests for querying and mutating user data securely. (Source)

How do I handle errors during authentication with Hygraph and NextAuth.js?

In the authorize function, throw an error if credentials are invalid or if authentication fails. This will prevent unauthorized access and provide feedback to users. (Source)

Can I customize the authentication UI in my Next.js app using Hygraph?

Yes, you can customize the authentication UI by using session data and conditional rendering in your Next.js components, as shown in the tutorial. (Source)

Is the authentication flow with Hygraph and NextAuth.js secure?

Yes, the authentication flow is secure when you hash passwords with bcrypt, use API-only fields for sensitive data, and authorize requests with Permanent Auth Tokens. (Source)

Can I manage multilingual content with Hygraph?

Yes, Hygraph supports multilingual content management. You can find tutorials on integrating Hygraph with localization platforms like Lokalise in the blog. (Source)

Features & Capabilities

What are the key features of Hygraph?

Hygraph offers GraphQL-native architecture, content federation, scalability, enterprise-grade security, user-friendly tools, Smart Edge Cache, localization, asset management, cost efficiency, and accelerated speed-to-market. (Source)

Does Hygraph provide APIs for integration?

Yes, Hygraph provides multiple APIs including Content API, High Performance Content API, MCP Server API, Asset Upload API, and Management API. (Source)

What integrations does Hygraph support?

Hygraph supports integrations with DAM systems (Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot), Adminix, Plasmic, custom SDK/API integrations, and marketplace apps for commerce and PIMs. (Source)

How does Hygraph optimize performance for content delivery?

Hygraph offers high-performance endpoints for low latency and high read-throughput, actively measures GraphQL API performance, and provides best practices for optimization. (Source)

What technical documentation is available for Hygraph?

Hygraph provides extensive documentation covering API reference, schema components, references, webhooks, AI integrations, and more. (Source)

Pricing & Plans

What pricing plans does Hygraph offer?

Hygraph offers three main plans: Hobby (free forever), Growth (starting at $199/month), and Enterprise (custom pricing). Each plan includes different features and limits. (Source)

What features are included in the Hobby plan?

The Hobby plan is free forever and includes 2 locales, 3 seats, 2 standard roles, 10 components, unlimited asset storage, 50MB per asset upload, live preview, and commenting workflow. (Source)

What features are included in the Growth plan?

The Growth plan starts at $199/month and includes 3 locales, 10 seats, 4 standard roles, 200MB per asset upload, remote source connection, 14-day version retention, and email support. (Source)

What features are included in the Enterprise plan?

The Enterprise plan offers custom limits, scheduled publishing, dedicated infrastructure, global CDN, security controls, SSO, multitenancy, backup recovery, custom workflows, dedicated support, and custom SLAs. (Source)

Security & Compliance

What security certifications does Hygraph have?

Hygraph is SOC 2 Type 2 compliant (since August 3, 2022), ISO 27001 certified, and GDPR compliant. (Source)

How does Hygraph ensure data security?

Hygraph uses granular permissions, audit logs, SSO integrations, encryption at rest and in transit, regular backups, and dedicated hosting options to ensure data security. (Source)

Is Hygraph GDPR compliant?

Yes, Hygraph is GDPR compliant and adheres to data protection and privacy regulations. (Source)

Use Cases & Benefits

Who can benefit from using Hygraph?

Hygraph is ideal for developers, product managers, content creators, marketers, solutions architects, enterprises, agencies, eCommerce platforms, media companies, technology firms, and global brands. (Source)

What industries use Hygraph?

Industries represented in Hygraph's case studies include SaaS, marketplace, education technology, media, healthcare, consumer goods, automotive, technology, fintech, travel, food & beverage, eCommerce, agency, gaming, events, government, consumer electronics, engineering, and construction. (Source)

What business impact can customers expect from using Hygraph?

Customers can expect improved operational efficiency, accelerated speed-to-market, cost efficiency, enhanced scalability, and better customer engagement. Case studies show 3x faster launches and increased engagement rates. (Source)

Can you share specific case studies of customers using Hygraph?

Yes, notable case studies include Samsung, Dr. Oetker, Komax, AutoWeb, BioCentury, Voi, HolidayCheck, and Lindex Group. Each demonstrates measurable business outcomes. (Source)

How long does it take to implement Hygraph?

Implementation time varies, but case studies show projects like Top Villas launched in just 2 months. Si Vale met aggressive deadlines with smooth onboarding. (Source)

How easy is it to start using Hygraph?

Hygraph offers a free API playground, free developer account, structured onboarding, training resources, extensive documentation, and a community Slack channel for easy adoption. (Source)

Competition & Comparison

How does Hygraph compare to traditional CMS platforms?

Hygraph is the first GraphQL-native Headless CMS, offering simplified schema evolution, content federation, and user-friendly tools, which sets it apart from traditional CMS platforms that rely on REST APIs and developer intervention. (Source)

Why choose Hygraph over alternatives like Contentful or Sanity?

Hygraph stands out with its GraphQL-native architecture, content federation, enterprise-grade features, proven ROI, and market recognition (ranked 2nd out of 102 Headless CMSs in G2 Summer 2025). (Source)

How does Hygraph address common pain points compared to competitors?

Hygraph eliminates developer dependency, modernizes legacy tech stacks, ensures content consistency, and offers robust integration and performance optimization, differentiating itself from competitors. (Source)

Customer Experience & Feedback

What feedback have customers given about Hygraph's ease of use?

Customers praise Hygraph for its intuitive UI, easy setup, custom app integration, independent content management, and real-time changes. Some note complexity for less technical users. (Source)

What pain points does Hygraph solve for its customers?

Hygraph solves operational inefficiencies, developer dependency, legacy tech stack modernization, content inconsistency, workflow challenges, high costs, slow speed-to-market, scalability issues, schema evolution complexity, integration difficulties, performance bottlenecks, and localization challenges. (Source)

Introducing Click to Edit

Next.js Authentication with NextAuth.js and Hygraph

Learn how to integrate NextAuth.js with Hygraph to authenticate your Next.js users.
Jamie Barton

Written by Jamie 

Oct 19, 2021
NextAuth.js with hygraph

The popular React framework that has dominated developers node_modules folders over the last few years we all know of is Next.js — and rightly so, with its stellar developer experience, blazing fast compiler, and tons more.

One topic that often comes up in discussions when evaluating if Next.js is right for you is whether or not it can handle authentication. For a long time there wasn't any "documentation" around this, which led to many developers building and pitching their own solutions to handle Next.js Auth.

Let me introduce to you NextAuth.js — Authentication for Next.js. It's completely open source, and you are in control of your data. It boasts itself on being secure, flexible, and easy to use.

Note: You'll need a Hygraph account, and Next.js application if you're following along. You'll also need your Hygraph endpoint, and a Permanent Auth Token with permissions to query and mutate the NextUser model.

#1. Configure Hygraph

I'll make the assumption you already have a Hygraph account, and project. If not, you know what to do.

We'll opt to store user data from NextAuth.js, including user email and encrypted passwords.

To keep things simple for the purposes of this tutorial, create the model NextUser with two fields:

  • Email / Single line text / Required / Unique
  • Password / Single line text / Required / API Only

NextUser Model Schema

Make sure you set the Password field to API only within the advanced visibility settings.

#2. Setup dependencies

We'll be using the following dependencies to configure, and work with NextAuth.js:

  • next-auth
  • bcrypt
  • graphql-request
  • graphql
npm install next-auth@beta bcrypt graphql-request graphql

Next, create the file .env and add your Hygraph endpoint and token:

HYGRAPH_ENDPOINT=
HYGRAPH_TOKEN=

#3. Configure NextAuth.js

Within your Next.js project, add the file [...nextauth].js in pages/api/auth and invoke the CredentialsProvider.

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
export default NextAuth({
providers: [
CredentialsProvider({
name: "Email and Password",
credentials: {
email: {
label: "Email",
type: "email",
placeholder: "jamie@hygraph.com"
},
password: {
label: "Password",
type: "password",
placeholder: "Password"
},
},
},
]
})

Now, this code alone won't do anything other than give you an email and password form at the route /api/auth/signin.

NextAuth Credentials Form

Next you'll want to create (or update if it exists) pages/_app.[js,ts] to wrap your application with `SessionProvider, passing it the session from the component props:

import { SessionProvider } from 'next-auth/react';
export default function MyApp({
Component,
pageProps: { session, ...pageProps },
}) {
return (
<SessionProvider session={session}>
<Component {...pageProps} />
</SessionProvider>
);
}

#4. Integrate Hygraph

We'll be working within pages/api/auth/[...nextauth].js to handle checking Hygraph if a user exists, and if they don't, create one.

Add the following imports:

import { compare, hash } from "bcrypt";
import { GraphQLClient } from "graphql-request";

Let's now create a GraphQL client for Hygraph with our endpoint and Permanent Auth Token.

const client = new GraphQLClient(process.env.HYGRAPH_ENDPOINT, {
headers: {
Authorization: `Bearer ${process.env.HYGRAPH_TOKEN}`,
},
});

Now, we'll add a query to get a user by email and a mutation to create a user with an email and password:

const GetUserByEmail = gql`
query GetUserByEmail($email: String!) {
user: nextUser(where: { email: $email }, stage: DRAFT) {
id
password
}
}
`;
const CreateNextUserByEmail = gql`
mutation CreateNextUserByEmail($email: String!, $password: String!) {
newUser: createNextUser(data: { email: $email, password: $password }) {
id
}
}
`;

Don't worry, we won't be saving passwords as plain text, but instead using the bcrypt library we installed to hash, and verify.

Inside of the CredentialsProvider config below credentials, add the following authorize function:

authorize: async ({ email, password }) => {
const { user } = await client.request(GetUserByEmail, {
email,
});
if (!user) {
const { newUser } = await client.request(
CreateNextUserByEmail,
{
email,
password: await hash(password, 12),
}
);
return {
id: newUser.id,
username: email,
email,
};
}
const isValid = await compare(password, user.password);
if (!isValid) {
throw new Error("Wrong credentials. Try again.");
}
return {
id: user.id,
username: email,
email,
};
},

#5. Current user UI

Now, let's finish by updating creating an pages/index.js to show our current user state and links to sign in/out based on our session state.

import { useSession, signIn, signOut } from "next-auth/react";
function AuthLinks() {
const { data: session, status } = useSession();
const loading = status === "loading";
if (loading) return null;
return (
<>
{session ? (
<p>
<span>Signed in as {session?.user?.email}</span>
<button onClick={signOut}>Sign out</button>
</p>
) : (
<>
<button onClick={signIn}>Sign in</button>
</>
)}
</>
);
}
export default function IndexPage() {
return <AuthLinks />;
}

#6. Demo

You should by now have something that looks like this:

CleanShot 2021-10-15 at 09.08.51.gif

There you have it! You've now used NextAuth.js and Hygraph to authenticate your Next.js users.

Blog Author

Jamie Barton

Jamie Barton

Jamie is a software engineer turned developer advocate. Born and bred in North East England, he loves learning and teaching others through video and written tutorials. Jamie currently publishes Weekly GraphQL Screencasts.

Share with others

Sign up for our newsletter!

Be the first to know about releases and industry news and insights.