File tree Expand file tree Collapse file tree 6 files changed +41
-55
lines changed
payload-authjs/src/payload Expand file tree Collapse file tree 6 files changed +41
-55
lines changed Original file line number Diff line number Diff line change 19
19
"@payloadcms/ui" : " 3.31.0" ,
20
20
"@tailwindcss/postcss" : " ^4.0.16" ,
21
21
"clsx" : " ^2.1.1" ,
22
+ "graphql" : " ^16.10.0" ,
22
23
"jsonwebtoken" : " ^9.0.2" ,
23
24
"next" : " 15.2.4" ,
24
25
"next-auth" : " 5.0.0-beta.25" ,
33
34
"tailwindcss" : " ^4.0.16"
34
35
},
35
36
"devDependencies" : {
37
+ "@payloadcms/graphql" : " 3.31.0" ,
36
38
"@types/jsonwebtoken" : " ^9.0.9" ,
37
39
"@types/react" : " 19.0.12" ,
38
40
"dotenv" : " ^16.4.7" ,
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ export interface User {
173
173
export interface Example {
174
174
id : number ;
175
175
someField ?: string | null ;
176
+ author ?: ( string | null ) | User ;
176
177
updatedAt : string ;
177
178
createdAt : string ;
178
179
}
@@ -293,6 +294,7 @@ export interface UsersSelect<T extends boolean = true> {
293
294
*/
294
295
export interface ExamplesSelect < T extends boolean = true > {
295
296
someField ?: T ;
297
+ author ?: T ;
296
298
updatedAt ?: T ;
297
299
createdAt ?: T ;
298
300
}
Original file line number Diff line number Diff line change 1
1
import type { CollectionConfig } from "payload" ;
2
2
import { hasRole } from "../access/hasRole" ;
3
3
4
- const Examples : CollectionConfig = {
4
+ const Examples : CollectionConfig < "examples" > = {
5
5
slug : "examples" ,
6
6
admin : {
7
7
useAsTitle : "someField" ,
@@ -17,6 +17,12 @@ const Examples: CollectionConfig = {
17
17
name : "someField" ,
18
18
type : "text" ,
19
19
} ,
20
+ {
21
+ name : "author" ,
22
+ type : "relationship" ,
23
+ relationTo : "users" ,
24
+ maxDepth : 0 ,
25
+ } ,
20
26
] ,
21
27
} ;
22
28
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { SESSION_STRATEGY } from "@/auth/base.config";
2
2
import type { CollectionConfig , Field } from "payload" ;
3
3
import { createdAtField } from "../fields/createdAt" ;
4
4
5
- const Users : CollectionConfig = {
5
+ const Users : CollectionConfig < "users" > = {
6
6
slug : "users" ,
7
7
admin : {
8
8
useAsTitle : "name" ,
@@ -14,6 +14,7 @@ const Users: CollectionConfig = {
14
14
} ,
15
15
auth : {
16
16
useAPIKey : true ,
17
+ depth : 0 ,
17
18
} ,
18
19
fields : [
19
20
{
@@ -164,6 +165,12 @@ const Users: CollectionConfig = {
164
165
} ) ,
165
166
] ,
166
167
} ,
168
+ /* {
169
+ name: "examples",
170
+ type: "join",
171
+ collection: "examples",
172
+ on: "author",
173
+ }, */
167
174
] ,
168
175
/* hooks: {
169
176
afterLogout: [
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export function AuthjsAuthStrategy(
20
20
21
21
return {
22
22
name : AUTHJS_STRATEGY_NAME ,
23
- authenticate : async ( { payload } ) => {
23
+ authenticate : async ( { payload, isGraphQL } ) => {
24
24
// Get session from authjs
25
25
const { auth } = NextAuth (
26
26
withPayload ( pluginOptions . authjsConfig , {
@@ -36,6 +36,7 @@ export function AuthjsAuthStrategy(
36
36
}
37
37
38
38
// Find user in database
39
+ const sanitizedCollectionConfig = payload . collections [ collection . slug ] . config ;
39
40
const payloadUser = (
40
41
await payload . find ( {
41
42
collection : collection . slug ,
@@ -48,6 +49,8 @@ export function AuthjsAuthStrategy(
48
49
equals : session . user . email ,
49
50
} ,
50
51
} ,
52
+ depth : isGraphQL ? 0 : sanitizedCollectionConfig . auth . depth ,
53
+ limit : 1 ,
51
54
} )
52
55
) . docs . at ( 0 ) ;
53
56
You can’t perform that action at this time.
0 commit comments