![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
next-auth-sanity
Advanced tools
NextAuth Adapter and Provider for Sanity
Database sessions are not implemented, this adapter relies on usage of JSON Web Tokens for stateless session management.
Storing people's user credentials is always a big responsibility. Make sure you understand the risks and inform your users accordingly. This adapter store the user information with the _id
on the user.
path. In other words, these documents can't be queried without authentication, even if your dataset is set to be public. That also means that these documents are available for everyone that's part of your Sanity project.
yarn add next-auth-sanity
npm i next-auth-sanity
import NextAuth, { NextAuthOptions } from 'next-auth';
import GitHub from 'next-auth/providers/github';
import { NextApiRequest, NextApiResponse } from 'next';
import { SanityAdapter, SanityCredentials } from 'next-auth-sanity';
import { client } from 'your/sanity/client';
const options: NextAuthOptions = {
providers: [
GitHub({
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}),
SanityCredentials(client) // only if you use sign in with credentials
],
session: {
strategy: 'jwt'
},
adapter: SanityAdapter(client)
};
export default NextAuth(options);
you can install this package in your studio project and use the schemas like this
import createSchema from 'part:@sanity/base/schema-creator';
import schemaTypes from 'all:part:@sanity/base/schema-type';
import { user, account, verificationToken } from 'next-auth-sanity/schemas';
export default createSchema({
name: 'default',
types: schemaTypes.concat([user, account, verificationToken])
});
or copy paste the schemas
// user - required
export default {
name: 'user',
title: 'User',
type: 'document',
fields: [
{
name: 'name',
title: 'Name',
type: 'string'
},
{
name: 'email',
title: 'Email',
type: 'string'
},
{
name: 'image',
title: 'Image',
type: 'url'
},
{
// this is only if you use credentials provider
name: 'password',
type: 'string',
hidden: true
},
{
name: 'emailVerified',
type: 'datetime',
hidden: true,
}
]
};
// account - required
export default {
name: 'account',
title: 'Account',
type: 'document',
fields: [
{
name: 'providerType',
type: 'string'
},
{
name: 'providerId',
type: 'string'
},
{
name: 'providerAccountId',
type: 'string'
},
{
name: 'refreshToken',
type: 'string'
},
{
name: 'accessToken',
type: 'string'
},
{
name: 'accessTokenExpires',
type: 'number'
},
{
name: 'user',
title: 'User',
type: 'reference',
to: { type: 'user' }
}
]
};
// verification-token - only if you use email provider
export default {
name: 'verification-token',
title: 'Verification Token',
type: 'document',
fields: [
{
name: 'identifier',
title: 'Identifier',
type: 'string'
},
{
name: 'token',
title: 'Token',
type: 'string'
},
{
name: 'expires',
title: 'Expires',
type: 'datetime'
}
]
};
API Route
(with pages)
// pages/api/sanity/signUp.ts
import { signUpHandler } from 'next-auth-sanity';
import { client } from 'your/sanity/client';
export default signUpHandler(client);
Route Handler
(with app directory)
// app/api/sanity/signUp/route.ts
import { signUpHandler } from 'next-auth-sanity';
import { client } from 'your/sanity/client';
export const POST = signUpHandler(client);
Client
import { signUp } from 'next-auth-sanity/client';
import { signIn } from 'next-auth/react';
const user = await signUp({
email,
password,
name
});
await signIn('sanity-login', {
redirect: false,
email,
password
});
if you want to use another schema or upgrade from previous version you can change the default schema used in the library, to do so you can pass a second argument to all methods with config
SanityAdapter(client, {
schemas: {
verificationToken: 'verification-request',
account: 'account',
user: 'profile'
}
})
// the second argument is the name of the user schema
// default: 'user'
SanityCredentials(client, 'profile');
signUpHandler(client, 'profile');
👤 Fedeya hello@fedeminaya.com
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator
FAQs
NextAuth Adapter for Sanity
The npm package next-auth-sanity receives a total of 165 weekly downloads. As such, next-auth-sanity popularity was classified as not popular.
We found that next-auth-sanity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.