File tree Expand file tree Collapse file tree 4 files changed +254
-17
lines changed
Expand file tree Collapse file tree 4 files changed +254
-17
lines changed Original file line number Diff line number Diff line change 11# Payload CMS
22PAYLOAD_SECRET = secret
33DATABASE_URI = postgres://root:root@127.0.0.1:5432/payload-authjs
4+ # DATABASE_URI=mongodb://127.0.0.1:27017/payload-authjs
45
56# Auth.js
67AUTH_SECRET = secret
Original file line number Diff line number Diff line change 1313 "generate:importmap" : " payload generate:importmap"
1414 },
1515 "dependencies" : {
16+ "@payloadcms/db-mongodb" : " 3.31.0" ,
1617 "@payloadcms/db-postgres" : " 3.31.0" ,
1718 "@payloadcms/next" : " 3.31.0" ,
1819 "@payloadcms/translations" : " 3.31.0" ,
Original file line number Diff line number Diff line change 1+ import { mongooseAdapter } from "@payloadcms/db-mongodb" ;
12import { postgresAdapter } from "@payloadcms/db-postgres" ;
23import path from "path" ;
34import { buildConfig } from "payload" ;
@@ -37,11 +38,23 @@ export default buildConfig({
3738 typescript : {
3839 outputFile : path . resolve ( dirname , "payload-types.ts" ) ,
3940 } ,
40- db : postgresAdapter ( {
41- pool : {
42- connectionString : process . env . DATABASE_URI || "" ,
43- } ,
44- } ) ,
41+ db : ( ( ) => {
42+ if ( process . env . DATABASE_URI ?. startsWith ( "postgres://" ) ) {
43+ return postgresAdapter ( {
44+ pool : {
45+ connectionString : process . env . DATABASE_URI ,
46+ } ,
47+ } ) ;
48+ }
49+
50+ if ( process . env . DATABASE_URI ?. startsWith ( "mongodb://" ) ) {
51+ return mongooseAdapter ( {
52+ url : process . env . DATABASE_URI ,
53+ } ) ;
54+ }
55+
56+ throw new Error ( "DATABASE_URI is not set" ) ;
57+ } ) ( ) ,
4558 email : ( { payload } ) => ( {
4659 name : "logger" ,
4760 defaultFromName : "Payload Auth.js" ,
You can’t perform that action at this time.
0 commit comments