-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support for next auth v4 * fix dataset * feat: add docs and some fixes for credentials * npm ignore
- Loading branch information
Showing
17 changed files
with
398 additions
and
1,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.*.swp | ||
._* | ||
.DS_Store | ||
.git | ||
.gitignore | ||
.hg | ||
.npmignore | ||
.npmrc | ||
.lock-wscript | ||
.svn | ||
.wafpickle-* | ||
config.gypi | ||
CVS | ||
npm-debug.log | ||
/examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,27 +52,26 @@ npm i next-auth-sanity | |
|
||
```ts | ||
import NextAuth, { NextAuthOptions } from 'next-auth'; | ||
import Providers from 'next-auth/providers'; | ||
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: [ | ||
Providers.GitHub({ | ||
GitHub({ | ||
clientId: process.env.GITHUB_CLIENT_ID, | ||
clientSecret: process.env.GITHUB_CLIENT_SECRET | ||
}), | ||
SanityCredentials(client) // only if you use sign in with credentials | ||
], | ||
session: { | ||
jwt: true | ||
strategy: 'jwt' | ||
}, | ||
adapter: SanityAdapter(client) | ||
}; | ||
|
||
export default (req: NextApiRequest, res: NextApiResponse) => | ||
NextAuth(req, res, options); | ||
export default NextAuth(options); | ||
``` | ||
|
||
### Sanity Schemas | ||
|
@@ -83,11 +82,11 @@ you can install this package in your studio project and use the schemas like thi | |
import createSchema from 'part:@sanity/base/schema-creator'; | ||
|
||
import schemaTypes from 'all:part:@sanity/base/schema-type'; | ||
import { user, account, verificationRequest } from 'next-auth-sanity/schemas'; | ||
import { user, account, verificationToken } from 'next-auth-sanity/schemas'; | ||
|
||
export default createSchema({ | ||
name: 'default', | ||
types: schemaTypes.concat([user, account, verificationRequest]) | ||
types: schemaTypes.concat([user, account, verificationToken]) | ||
}); | ||
``` | ||
|
||
|
@@ -169,11 +168,11 @@ export default { | |
``` | ||
|
||
```ts | ||
// verification-request - only if you use email provider | ||
// verification-token - only if you use email provider | ||
|
||
export default { | ||
name: 'verification-request', | ||
title: 'Verification Request', | ||
name: 'verification-token', | ||
title: 'Verification Token', | ||
type: 'document', | ||
fields: [ | ||
{ | ||
|
@@ -221,13 +220,33 @@ const user = await signUp({ | |
name | ||
}); | ||
|
||
await signIn('credentials', { | ||
await signIn('sanity-login', { | ||
redirect: false, | ||
email, | ||
password | ||
}); | ||
``` | ||
|
||
## Custom Schemas | ||
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 | ||
```ts | ||
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'); | ||
``` | ||
|
||
## Author | ||
|
||
👤 **Fedeya <[email protected]>** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { FC } from 'react'; | ||
import { AppProps } from 'next/app'; | ||
import { Provider } from 'next-auth/client'; | ||
import { SessionProvider } from 'next-auth/react'; | ||
|
||
const MyApp: FC<AppProps> = ({ Component, pageProps }) => ( | ||
<Provider session={pageProps.session}> | ||
<SessionProvider session={pageProps.session}> | ||
<Component {...pageProps} /> | ||
</Provider> | ||
</SessionProvider> | ||
); | ||
|
||
export default MyApp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import NextAuth, { NextAuthOptions } from 'next-auth'; | ||
import Providers from 'next-auth/providers'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
import GitHub from 'next-auth/providers/github'; | ||
import { SanityAdapter, SanityCredentials } from '../../../../../../dist'; | ||
import { client } from '../../../libs/sanity'; | ||
|
||
const options: NextAuthOptions = { | ||
providers: [ | ||
Providers.GitHub({ | ||
GitHub({ | ||
clientId: process.env.GITHUB_CLIENT_ID, | ||
clientSecret: process.env.GITHUB_CLIENT_SECRET | ||
}), | ||
SanityCredentials(client) | ||
], | ||
session: { | ||
jwt: true | ||
strategy: 'jwt' | ||
}, | ||
adapter: SanityAdapter(client) | ||
secret: 'any-secret-word', | ||
adapter: SanityAdapter(client, { | ||
schemas: { | ||
verificationToken: 'verificationToken', | ||
account: 'account', | ||
user: 'user' | ||
} | ||
}) | ||
}; | ||
|
||
export default (req: NextApiRequest, res: NextApiResponse) => | ||
NextAuth(req, res, options); | ||
export default NextAuth(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...le/studio/schemas/verification-request.ts → ...mple/studio/schemas/verification-token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.