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 1
1
# Payload CMS
2
2
PAYLOAD_SECRET = secret
3
3
DATABASE_URI = postgres://root:root@127.0.0.1:5432/payload-authjs
4
+ # DATABASE_URI=mongodb://127.0.0.1:27017/payload-authjs
4
5
5
6
# Auth.js
6
7
AUTH_SECRET = secret
Original file line number Diff line number Diff line change 13
13
"generate:importmap" : " payload generate:importmap"
14
14
},
15
15
"dependencies" : {
16
+ "@payloadcms/db-mongodb" : " 3.31.0" ,
16
17
"@payloadcms/db-postgres" : " 3.31.0" ,
17
18
"@payloadcms/next" : " 3.31.0" ,
18
19
"@payloadcms/translations" : " 3.31.0" ,
Original file line number Diff line number Diff line change
1
+ import { mongooseAdapter } from "@payloadcms/db-mongodb" ;
1
2
import { postgresAdapter } from "@payloadcms/db-postgres" ;
2
3
import path from "path" ;
3
4
import { buildConfig } from "payload" ;
@@ -37,11 +38,23 @@ export default buildConfig({
37
38
typescript : {
38
39
outputFile : path . resolve ( dirname , "payload-types.ts" ) ,
39
40
} ,
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
+ } ) ( ) ,
45
58
email : ( { payload } ) => ( {
46
59
name : "logger" ,
47
60
defaultFromName : "Payload Auth.js" ,
You can’t perform that action at this time.
0 commit comments