You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/payload-authjs/README.md
+34-48Lines changed: 34 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ pnpm i payload-authjs
29
29
30
30
### 1. Setup Auth.js
31
31
32
-
First of all, this plugin only integrates Auth.js into Payload CMS by getting the user session from Auth.js. It doesn't handle the Auth.js stuff. You need to setup Auth.js before you can use this plugin.
32
+
This plugin integrates Auth.js into Payload CMS by getting the user session from Auth.js. You need to setup Auth.js before you can use this plugin.
Next, create your Auth.js instance in a file (e.g. `auth.ts`). But before creating the Auth.js instance, you need to wrap your Auth.js configuration with the `withPayload` function:
52
+
Next, create your Auth.js instance in a file (e.g. `auth.ts`).
53
+
54
+
> ⚠ But unlike what you would normally do in Auth.js, you need to create the Payload instance first and using the `getAuthjsInstance` function to retrieve the Auth.js instance.
53
55
54
56
```ts
55
57
// auth.ts
56
58
importpayloadConfigfrom"@payload-config";
57
-
importNextAuthfrom"next-auth";
58
-
import { withPayload } from"payload-authjs";
59
-
import { authConfig } from"./auth.config"; // ⚠ Import the config from a separate file
Add optional `middleware.ts` to keep the session alive, this will update the session expiry each time it's called.
84
80
85
-
> ⚠ Unlike what you would normally do in Auth.js, you cannot use the `middleware` of `@/auth` directly. You have to create a new Auth.js instance without the `withPayload` wrapper to be [edge-compatible](https://authjs.dev/guides/edge-compatibility).
81
+
> ⚠ Unlike what you would normally do in Auth.js, you cannot use the `middleware` of `@/auth` directly. You have to create a new Auth.js instance to be [edge-compatible](https://authjs.dev/guides/edge-compatibility).
86
82
87
83
```ts
88
84
// middleware.ts
@@ -460,48 +456,38 @@ _More information about typescript can be found in the [Auth.js documentation](h
460
456
461
457
## 🎉 Events
462
458
463
-
Auth.js emits some [events](https://authjs.dev/reference/nextjs#events) that you can listen to. This plugin extends the events with additional parameters such as the `adapter` and `payload` instance.
459
+
Auth.js emits some [events](https://authjs.dev/reference/nextjs#events) that you can listen to. This plugin extends the events with additional parameters such as the database `adapter` and the`payload` instance.
464
460
465
461
_More information about the events can be found in the [Auth.js documentation](https://authjs.dev/reference/nextjs#events)._
466
462
467
-
The following events are available:
468
-
469
-
- signIn
470
-
- signOut
471
-
- createUser
472
-
- updateUser
473
-
- linkAccount
474
-
- session
475
-
476
-
### `signIn` Event
463
+
### Example: `signIn` Event
477
464
478
465
The `signIn` event is fired when a user successfully signs in. For example, you could use this event to update the user's name on every sign-in:
0 commit comments