-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSession.js
61 lines (50 loc) · 1.42 KB
/
Session.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
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
const moment = require('moment-timezone');
module.exports = {
primaryKey: 'id',
attributes: {
id: {
type: 'string',
columnType: 'varchar(36)',
required: true
},
user: {
model: 'User',
required: true
},
data: {
type: 'json'
},
csrfSecret: {
type: 'string',
columnType: 'varchar(105)',
required: true,
encrypt: true
},
expiresAt: {
type: 'ref',
columnType: 'datetime',
required: false // If we make this `true`, it will force controllers to have to supply an empty string on creation.
},
createdAt: {
type: 'ref',
columnType: 'datetime',
autoCreatedAt: true
},
updatedAt: {
type: 'ref',
columnType: 'datetime',
autoUpdatedAt: true
}
},
customToJSON: function() { // DO NOT use => function!
// This will be run by the "keep-models-safe" helper.
return _.omit(this, [
'csrfSecret'
]);
},
beforeCreate: (session, next) => {
session.id = sails.helpers.generateUuid();
session.expiresAt = moment(new Date()).add(sails.config.session.expiresAt.amount, sails.config.session.expiresAt.unit).toDate();
return next();
}
};