-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
I've tried implementing the example of an authenticated router provided here but I am running into an error message.
I have changed to use my DB_URI and I am able to access DB_URI both locally and remotely on my fly.io app, but in both cases I run into this error:
const adminRouter = AdminJSExpress.buildAuthenticatedRouter(
^
TypeError: AdminJSExpress.buildAuthenticatedRouter is not a function
at start (etc)
Here is the code I am running, based off that adminjsexpress example:
import AdminJS from 'adminjs'
import * as AdminJSExpress from '@adminjs/express'
import express from 'express'
import Connect from 'connect-pg-simple'
import session from 'express-session'
// import from 'express-session'
import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config()
const PORT = 3000
const DEFAULT_ADMIN = {
email: '[email protected]',
password: 'password',
}
const authenticate = async (email, password) => {
if (email === DEFAULT_ADMIN.email && password === DEFAULT_ADMIN.password) {
return Promise.resolve(DEFAULT_ADMIN)
}
return null
}
console.log("hi");
console.log(process.env.DB_URI);
const start = async () => {
const app = express()
const admin = new AdminJS({})
const ConnectSession = Connect(session)
const sessionStore = new ConnectSession({
conObject: {
connectionString: process.env.DB_URI,
ssl: process.env.NODE_ENV === 'production',
},
tableName: 'session',
createTableIfMissing: true,
})
const adminRouter = AdminJSExpress.buildAuthenticatedRouter(
admin,
{
authenticate,
cookieName: 'adminjs',
cookiePassword: 'sessionsecret',
},
null,
{
store: sessionStore,
resave: true,
saveUninitialized: true,
secret: 'sessionsecret',
cookie: {
httpOnly: process.env.NODE_ENV === 'production',
secure: process.env.NODE_ENV === 'production',
},
name: 'adminjs',
}
)
app.use(admin.options.rootPath, adminRouter)
app.listen(PORT, () => {
console.log(`AdminJS started on http://localhost:${PORT}${admin.options.rootPath}`)
})
}
start()
Metadata
Metadata
Assignees
Labels
No labels