forked from luizpicolo/assifems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.js
28 lines (26 loc) · 901 Bytes
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const AdminJS = require('adminjs')
const AdminJSExpress = require('@adminjs/express')
const AdminJSSequelize = require('@adminjs/sequelize')
const options = require('./config/options.js');
AdminJS.registerAdapter(AdminJSSequelize);
const { User } = require('./app/models');
const bcrypt = require('bcryptjs');
const adminJs = new AdminJS(options)
if (process.env.NODE_ENV == 'production'){
module.exports = adminRouter = AdminJSExpress.buildAuthenticatedRouter(adminJs, {
authenticate: async (email, password) => {
const user = await User.findOne({ email })
if (user) {
const matched = await bcrypt.compare(password, user.password)
if (matched) {
return user
}
}
return false
},
cookieName: 'adminjs',
cookiePassword: process.env.SECRET,
})
} else {
module.exports = adminRouter = AdminJSExpress.buildRouter(adminJs);
}