Gathering detailed insights and metrics for next-auth-sanity
Gathering detailed insights and metrics for next-auth-sanity
Gathering detailed insights and metrics for next-auth-sanity
Gathering detailed insights and metrics for next-auth-sanity
npm install next-auth-sanity
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
82 Stars
68 Commits
20 Forks
5 Watchers
4 Branches
7 Contributors
Updated on Mar 20, 2025
Latest Version
1.5.3
Package Id
next-auth-sanity@1.5.3
Unpacked Size
22.04 kB
Size
6.16 kB
File Count
15
NPM Version
8.19.4
Node Version
16.20.1
Published on
Aug 19, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
2
5
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.
1yarn add next-auth-sanity
1npm i next-auth-sanity
1import NextAuth, { NextAuthOptions } from 'next-auth'; 2import GitHub from 'next-auth/providers/github'; 3import { NextApiRequest, NextApiResponse } from 'next'; 4import { SanityAdapter, SanityCredentials } from 'next-auth-sanity'; 5import { client } from 'your/sanity/client'; 6 7const options: NextAuthOptions = { 8 providers: [ 9 GitHub({ 10 clientId: process.env.GITHUB_CLIENT_ID, 11 clientSecret: process.env.GITHUB_CLIENT_SECRET 12 }), 13 SanityCredentials(client) // only if you use sign in with credentials 14 ], 15 session: { 16 strategy: 'jwt' 17 }, 18 adapter: SanityAdapter(client) 19}; 20 21export default NextAuth(options);
you can install this package in your studio project and use the schemas like this
1import createSchema from 'part:@sanity/base/schema-creator'; 2 3import schemaTypes from 'all:part:@sanity/base/schema-type'; 4import { user, account, verificationToken } from 'next-auth-sanity/schemas'; 5 6export default createSchema({ 7 name: 'default', 8 types: schemaTypes.concat([user, account, verificationToken]) 9});
or copy paste the schemas
1// user - required 2 3export default { 4 name: 'user', 5 title: 'User', 6 type: 'document', 7 fields: [ 8 { 9 name: 'name', 10 title: 'Name', 11 type: 'string' 12 }, 13 { 14 name: 'email', 15 title: 'Email', 16 type: 'string' 17 }, 18 { 19 name: 'image', 20 title: 'Image', 21 type: 'url' 22 }, 23 { 24 // this is only if you use credentials provider 25 name: 'password', 26 type: 'string', 27 hidden: true 28 }, 29 { 30 name: 'emailVerified', 31 type: 'datetime', 32 hidden: true, 33 } 34 ] 35};
1// account - required 2 3export default { 4 name: 'account', 5 title: 'Account', 6 type: 'document', 7 fields: [ 8 { 9 name: 'providerType', 10 type: 'string' 11 }, 12 { 13 name: 'providerId', 14 type: 'string' 15 }, 16 { 17 name: 'providerAccountId', 18 type: 'string' 19 }, 20 { 21 name: 'refreshToken', 22 type: 'string' 23 }, 24 { 25 name: 'accessToken', 26 type: 'string' 27 }, 28 { 29 name: 'accessTokenExpires', 30 type: 'number' 31 }, 32 { 33 name: 'user', 34 title: 'User', 35 type: 'reference', 36 to: { type: 'user' } 37 } 38 ] 39};
1// verification-token - only if you use email provider 2 3export default { 4 name: 'verification-token', 5 title: 'Verification Token', 6 type: 'document', 7 fields: [ 8 { 9 name: 'identifier', 10 title: 'Identifier', 11 type: 'string' 12 }, 13 { 14 name: 'token', 15 title: 'Token', 16 type: 'string' 17 }, 18 { 19 name: 'expires', 20 title: 'Expires', 21 type: 'datetime' 22 } 23 ] 24};
API Route
(with pages)
1// pages/api/sanity/signUp.ts 2import { signUpHandler } from 'next-auth-sanity'; 3import { client } from 'your/sanity/client'; 4 5export default signUpHandler(client);
Route Handler
(with app directory)
1// app/api/sanity/signUp/route.ts 2import { signUpHandler } from 'next-auth-sanity'; 3import { client } from 'your/sanity/client'; 4 5export const POST = signUpHandler(client);
Client
1import { signUp } from 'next-auth-sanity/client'; 2import { signIn } from 'next-auth/react'; 3 4const user = await signUp({ 5 email, 6 password, 7 name 8}); 9 10await signIn('sanity-login', { 11 redirect: false, 12 email, 13 password 14});
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
1SanityAdapter(client, {
2 schemas: {
3 verificationToken: 'verification-request',
4 account: 'account',
5 user: 'profile'
6 }
7})
8
9
10// the second argument is the name of the user schema
11// default: 'user'
12
13SanityCredentials(client, 'profile');
14
15signUpHandler(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
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/21 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
113 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More