This repository was archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.js
More file actions
75 lines (72 loc) · 1.67 KB
/
admin.js
File metadata and controls
75 lines (72 loc) · 1.67 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const AdminBro = require('admin-bro')
const AdminBroExpress = require('admin-bro-expressjs')
const AdminBroMongoose = require('admin-bro-mongoose')
const bcrypt = require('bcrypt')
const Player = require('./models/Player')
const User = require('./models/User')
AdminBro.registerAdapter(AdminBroMongoose)
const adminBro = new AdminBro({
resources: [
{
resource: Player,
options: {
properties: {
created_at: { isVisible: { list: true, filter: true, show: true, edit: false } }
}
}
},
{
resource: User,
options: {
properties: {
encrypted_password: {
isVisible: false,
},
password: {
type: 'password',
isVisible: {
list: false, edit: true, filter: false, show: false,
},
},
},
actions: {
new: {
before: async (request) => {
if(request.payload.password) {
request.payload = {
...request.payload,
encrypted_password: await bcrypt.hash(request.payload.password, 10),
password: undefined,
}
}
return request
},
}
}
}
}
],
rootPath: '/admin',
branding: {
logo: '/vereinslogo1.gif',
companyName: 'SMTL Admin',
softwareBrothers: false
}
})
const { COOKIE_PASSWORD } = process.env
if (!COOKIE_PASSWORD) {
throw new Error('process.env.COOKIE_PASSWORD must be set')
}
module.exports = AdminBroExpress.buildAuthenticatedRouter(adminBro, {
authenticate: async (email, password) => {
const user = await User.findOne({ email })
if (user) {
const match = await bcrypt.compare(password, user.encrypted_password)
if (match) {
return user
}
}
return false
},
cookiePassword: COOKIE_PASSWORD
})