Skip to content

Commit

Permalink
1.3.0 (#6)
Browse files Browse the repository at this point in the history
* 1.3.0

* refactor: removed handler types

* fix: user not found

* fix: removed id and name of credentials

* fix: verification request hash
  • Loading branch information
fedeya authored Jul 3, 2021
1 parent fde04f7 commit 74659dc
Show file tree
Hide file tree
Showing 14 changed files with 5,128 additions and 322 deletions.
Binary file added .DS_Store
Binary file not shown.
58 changes: 49 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
### Features

- Saving users and account in Sanity
- Email Provider Support
- Retrieving of full linked provider information for a user
- Stale While Revalidate
- Auth with Credentials
- Hash Credentials Passwords with Argon2

Expand Down Expand Up @@ -63,12 +63,12 @@ const options: NextAuthOptions = {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}),
SanityCredentials({ client }) // only if you use sign in with credentials
SanityCredentials(client) // only if you use sign in with credentials
],
session: {
jwt: true
},
adapter: SanityAdapter({ client })
adapter: SanityAdapter(client)
};

export default (req: NextApiRequest, res: NextApiResponse) =>
Expand All @@ -77,8 +77,24 @@ export default (req: NextApiRequest, res: NextApiResponse) =>

### Sanity Schemas

you can install this package in your studio project and use the schemas like this

```ts
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';

export default createSchema({
name: 'default',
types: schemaTypes.concat([user, account, verificationRequest])
});
```

or copy paste the schemas

```ts
// user
// user - required

export default {
name: 'user',
Expand Down Expand Up @@ -111,7 +127,7 @@ export default {
```

```ts
// account
// account - required

export default {
name: 'account',
Expand Down Expand Up @@ -152,6 +168,33 @@ export default {
};
```

```ts
// verification-request - only if you use email provider

export default {
name: 'verification-request',
title: 'Verification Request',
type: 'document',
fields: [
{
name: 'identifier',
title: 'Identifier',
type: 'string'
},
{
name: 'token',
title: 'Token',
type: 'string'
},
{
name: 'expires',
title: 'Expires',
type: 'date'
}
]
};
```

### Sign Up and Sign In With Credentials

### Setup
Expand All @@ -160,13 +203,10 @@ export default {

```ts
// pages/api/sanity/signUp.ts

import { signUpHandler } from 'next-auth-sanity';
import { NextApiRequest, NextApiResponse } from 'next';
import { client } from 'your/sanity/client';

export default (req: NextApiRequest, res: NextApiResponse) =>
signUpHandler({ req, res, client });
export default signUpHandler(client);
```

`Client`
Expand Down
2 changes: 1 addition & 1 deletion examples/full-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"@sanity/client": "^2.8.0",
"next": "10.1.3",
"next-auth": "^3.17.2",
"next-auth": "^3.27.1",
"react": "17.0.2",
"react-dom": "17.0.2"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/full-example/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const options: NextAuthOptions = {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}),
SanityCredentials({ client })
SanityCredentials(client)
],
session: {
jwt: true
},
adapter: SanityAdapter({ client })
adapter: SanityAdapter(client)
};

export default (req: NextApiRequest, res: NextApiResponse) =>
Expand Down
4 changes: 1 addition & 3 deletions examples/full-example/src/pages/api/sanity/signUp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { signUpHandler } from '../../../../../../dist';
import { NextApiRequest, NextApiResponse } from 'next';
import { client } from '../../../libs/sanity';

export default (req: NextApiRequest, res: NextApiResponse) =>
signUpHandler({ req, res, client });
export default signUpHandler(client);
6 changes: 3 additions & 3 deletions examples/full-example/studio/schemas/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import createSchema from 'part:@sanity/base/schema-creator';

// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type';
import user from './user';
import account from './account';
import { user, account, verificationRequest } from '../../../../dist/schemas';

// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
Expand All @@ -15,6 +14,7 @@ export default createSchema({
types: schemaTypes.concat([
/* Your types here! */
user,
account
account,
verificationRequest
])
});
24 changes: 24 additions & 0 deletions examples/full-example/studio/schemas/verification-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Document } from './schemaTypes';

export default <Document>{
name: 'verification-request',
title: 'Verification Request',
type: 'document',
fields: [
{
name: 'identifier',
title: 'Identifier',
type: 'string'
},
{
name: 'token',
title: 'Token',
type: 'string'
},
{
name: 'expires',
title: 'Expires',
type: 'date'
}
]
};
Loading

0 comments on commit 74659dc

Please sign in to comment.