ref: Add log out event, refactoring
parent
220cb1427b
commit
891b7ce90a
@ -1,6 +1,9 @@
|
|||||||
TZ=UTC
|
|
||||||
BASE_URL=http://localhost:1337
|
BASE_URL=http://localhost:1337
|
||||||
DATABASE_URL=postgresql://postgres@localhost/planka
|
DATABASE_URL=postgresql://postgres@localhost/planka
|
||||||
SECRET_KEY=notsecretkey
|
SECRET_KEY=notsecretkey
|
||||||
|
|
||||||
# In days
|
# In days
|
||||||
ACCESS_TOKEN_EXPIRES=365
|
TOKEN_EXPIRES_IN=365
|
||||||
|
|
||||||
|
# Do not edit this
|
||||||
|
TZ=UTC
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
const jwt = require('jsonwebtoken');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
sync: true,
|
||||||
|
|
||||||
|
inputs: {
|
||||||
|
subject: {
|
||||||
|
type: 'json',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
issuedAt: {
|
||||||
|
type: 'ref',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
fn(inputs) {
|
||||||
|
const { issuedAt = new Date() } = inputs;
|
||||||
|
const iat = Math.floor(issuedAt / 1000);
|
||||||
|
|
||||||
|
return jwt.sign(
|
||||||
|
{
|
||||||
|
iat,
|
||||||
|
sub: inputs.subject,
|
||||||
|
exp: iat + sails.config.custom.tokenExpiresIn * 24 * 60 * 60,
|
||||||
|
},
|
||||||
|
sails.config.session.secret,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -1,18 +0,0 @@
|
|||||||
const jwt = require('jsonwebtoken');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
sync: true,
|
|
||||||
|
|
||||||
inputs: {
|
|
||||||
payload: {
|
|
||||||
type: 'json',
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
fn(inputs) {
|
|
||||||
return jwt.sign({ sub: inputs.payload }, sails.config.session.secret, {
|
|
||||||
expiresIn: `${process.env.ACCESS_TOKEN_EXPIRES}d`,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue