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 1919 "@payloadcms/ui" : " 3.31.0" ,
2020 "@tailwindcss/postcss" : " ^4.0.16" ,
2121 "clsx" : " ^2.1.1" ,
22+ "graphql" : " ^16.10.0" ,
2223 "jsonwebtoken" : " ^9.0.2" ,
2324 "next" : " 15.2.4" ,
2425 "next-auth" : " 5.0.0-beta.25" ,
3334 "tailwindcss" : " ^4.0.16"
3435 },
3536 "devDependencies" : {
37+ "@payloadcms/graphql" : " 3.31.0" ,
3638 "@types/jsonwebtoken" : " ^9.0.9" ,
3739 "@types/react" : " 19.0.12" ,
3840 "dotenv" : " ^16.4.7" ,
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ export interface User {
173173export interface Example {
174174 id : number ;
175175 someField ?: string | null ;
176+ author ?: ( string | null ) | User ;
176177 updatedAt : string ;
177178 createdAt : string ;
178179}
@@ -293,6 +294,7 @@ export interface UsersSelect<T extends boolean = true> {
293294 */
294295export interface ExamplesSelect < T extends boolean = true > {
295296 someField ?: T ;
297+ author ?: T ;
296298 updatedAt ?: T ;
297299 createdAt ?: T ;
298300}
Original file line number Diff line number Diff line change 11import type { CollectionConfig } from "payload" ;
22import { hasRole } from "../access/hasRole" ;
33
4- const Examples : CollectionConfig = {
4+ const Examples : CollectionConfig < "examples" > = {
55 slug : "examples" ,
66 admin : {
77 useAsTitle : "someField" ,
@@ -17,6 +17,12 @@ const Examples: CollectionConfig = {
1717 name : "someField" ,
1818 type : "text" ,
1919 } ,
20+ {
21+ name : "author" ,
22+ type : "relationship" ,
23+ relationTo : "users" ,
24+ maxDepth : 0 ,
25+ } ,
2026 ] ,
2127} ;
2228
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { SESSION_STRATEGY } from "@/auth/base.config";
22import type { CollectionConfig , Field } from "payload" ;
33import { createdAtField } from "../fields/createdAt" ;
44
5- const Users : CollectionConfig = {
5+ const Users : CollectionConfig < "users" > = {
66 slug : "users" ,
77 admin : {
88 useAsTitle : "name" ,
@@ -14,6 +14,7 @@ const Users: CollectionConfig = {
1414 } ,
1515 auth : {
1616 useAPIKey : true ,
17+ depth : 0 ,
1718 } ,
1819 fields : [
1920 {
@@ -164,6 +165,12 @@ const Users: CollectionConfig = {
164165 } ) ,
165166 ] ,
166167 } ,
168+ /* {
169+ name: "examples",
170+ type: "join",
171+ collection: "examples",
172+ on: "author",
173+ }, */
167174 ] ,
168175 /* hooks: {
169176 afterLogout: [
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export function AuthjsAuthStrategy(
2020
2121 return {
2222 name : AUTHJS_STRATEGY_NAME ,
23- authenticate : async ( { payload } ) => {
23+ authenticate : async ( { payload, isGraphQL } ) => {
2424 // Get session from authjs
2525 const { auth } = NextAuth (
2626 withPayload ( pluginOptions . authjsConfig , {
@@ -36,6 +36,7 @@ export function AuthjsAuthStrategy(
3636 }
3737
3838 // Find user in database
39+ const sanitizedCollectionConfig = payload . collections [ collection . slug ] . config ;
3940 const payloadUser = (
4041 await payload . find ( {
4142 collection : collection . slug ,
@@ -48,6 +49,8 @@ export function AuthjsAuthStrategy(
4849 equals : session . user . email ,
4950 } ,
5051 } ,
52+ depth : isGraphQL ? 0 : sanitizedCollectionConfig . auth . depth ,
53+ limit : 1 ,
5154 } )
5255 ) . docs . at ( 0 ) ;
5356
You can’t perform that action at this time.
0 commit comments