Skip to content

Commit

Permalink
docs(ts): update adapter documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Jul 12, 2021
1 parent b6d2d54 commit 59b4026
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 104 deletions.
10 changes: 3 additions & 7 deletions www/docs/adapters/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ See the tutorial for [creating a database Adapter](/tutorials/creating-a-databas
When writing your own custom Adapter in plain JavaScript, note that you can use **JSDoc** to get helpful editor hints and auto-completion like so:

```js
/** @type { import("next-auth/adapters").Adapter } */
const MyAdapter = () => {
/** @return { import("next-auth/adapters").Adapter } */
function MyAdapter() {
return {
async getAdapter() {
return {
// your adapter methods here
}
},
// your adapter methods here
}
}
```
Expand Down
18 changes: 5 additions & 13 deletions www/docs/getting-started/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,20 @@ If you're writing your own custom Adapter, you can take advantage of the types t
```ts
import type { Adapter } from "next-auth/adapters"

const MyAdapter: Adapter = () => {
function MyAdapter(): Adapter {
return {
async getAdapter() {
return {
// your adapter methods here
}
},
// your adapter methods here
}
}
```

When writing your own custom Adapter in plain JavaScript, note that you can use **JSDoc** to get helpful editor hints and auto-completion like so:

```js
/** @type { import("next-auth/adapters").Adapter } */
const MyAdapter = () => {
/** @return { import("next-auth/adapters").Adapter } */
function MyAdapter() {
return {
async getAdapter() {
return {
// your adapter methods here
}
},
// your adapter methods here
}
}
```
Expand Down
168 changes: 84 additions & 84 deletions www/docs/tutorials/creating-a-database-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Creating a custom adapter can be considerable undertaking and will require some

## How to create an adapter

From an implementation perspective, an adapter in NextAuth.js is a function which returns an async `getAdapter()` method, which in turn returns a Promise with a list of functions used to handle operations such as creating user, linking a user and an OAuth account or handling reading and writing sessions.
_See the code below for practical example._

It uses this approach to allow database connection logic to live in the `getAdapter()` method. By calling the function just before an action needs to happen, it is possible to check database connection status and handle connecting / reconnecting to a database as required.
### Required properties

_See the code below for practical example._
* displayName

### Required methods

Expand Down Expand Up @@ -46,88 +46,88 @@ These methods will be required in a future release, but are not yet invoked:
### Example code

```js
export default function YourAdapter (config, options = {}) {
/** @return { import("next-auth/adapters").Adapter } */
export default function MyAdapter(client, options = {}) {
return {
async getAdapter (appOptions) {
async createUser (profile) {
return null
},
async getUser (id) {
return null
},
async getUserByEmail (email) {
return null
},
async getUserByProviderAccountId (
providerId,
providerAccountId
) {
return null
},
async updateUser (user) {
return null
},
async deleteUser (userId) {
return null
},
async linkAccount (
userId,
providerId,
providerType,
providerAccountId,
refreshToken,
accessToken,
accessTokenExpires
) {
return null
},
async unlinkAccount (
userId,
providerId,
providerAccountId
) {
return null
},
async createSession (user) {
return null
},
async getSession (sessionToken) {
return null
},
async updateSession (
session,
force
) {
return null
},
async deleteSession (sessionToken) {
return null
},
async createVerificationRequest (
identifier,
url,
token,
secret,
provider
) {
return null
},
async getVerificationRequest (
identifier,
token,
secret,
provider
) {
return null
},
async deleteVerificationRequest (
identifier,
token,
secret,
provider
) {
return null
}
displayName: "foo",
async createUser (profile) {
return null
},
async getUser (id) {
return null
},
async getUserByEmail (email) {
return null
},
async getUserByProviderAccountId (
providerId,
providerAccountId
) {
return null
},
async updateUser (user) {
return null
},
async deleteUser (userId) {
return null
},
async linkAccount (
userId,
providerId,
providerType,
providerAccountId,
refreshToken,
accessToken,
accessTokenExpires
) {
return null
},
async unlinkAccount (
userId,
providerId,
providerAccountId
) {
return null
},
async createSession (user) {
return null
},
async getSession (sessionToken) {
return null
},
async updateSession (
session,
force
) {
return null
},
async deleteSession (sessionToken) {
return null
},
async createVerificationRequest (
identifier,
url,
token,
secret,
provider
) {
return null
},
async getVerificationRequest (
identifier,
token,
secret,
provider
) {
return null
},
async deleteVerificationRequest (
identifier,
token,
secret,
provider
) {
return null
}
}
}
Expand Down

0 comments on commit 59b4026

Please sign in to comment.