-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
:feat(sign out): user should be able to sign out
- blacklist tokens and drop them as user sign out [Finishes #166789871]
- Loading branch information
Showing
16 changed files
with
261 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/db/migrations/20190704064417-create-blacklist-tokens.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: function(queryInterface, Sequelize) { | ||
return Promise.resolve() | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('BlacklistTokens'); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/db/migrations/20190708104045-create-blacklist-tokens.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: function(queryInterface, Sequelize) { | ||
return Promise.resolve() | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('BlacklistTokens'); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/db/migrations/20190708142302-create-blacklist-token.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: function(queryInterface, Sequelize) { | ||
return Promise.resolve() | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('BlacklistTokens'); | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/db/migrations/20190708144428-create-blacklist-tokens.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: function(queryInterface, Sequelize) { | ||
return Promise.resolve() | ||
}, | ||
|
||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('BlacklistTokens'); | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/db/migrations/20190708151534-create-blacklist-tokens.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('BlacklistTokens', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
token: { | ||
type: Sequelize.TEXT | ||
}, | ||
expires: { | ||
type: Sequelize.BIGINT | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('BlacklistTokens'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const BlacklistTokens = sequelize.define('BlacklistTokens', { | ||
token: DataTypes.TEXT, | ||
expires: DataTypes.BIGINT | ||
}, {}); | ||
BlacklistTokens.associate = function(models) { | ||
// associations can be defined here | ||
}; | ||
return BlacklistTokens; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'regenerator-runtime'; | ||
import Sequelize from 'sequelize'; | ||
import db from '../db/models'; | ||
|
||
const { BlacklistTokens } = db; | ||
const { Op } = Sequelize; | ||
|
||
module.exports = async () => { | ||
await BlacklistTokens.destroy({ | ||
where: { | ||
expires: { | ||
[Op.lte]: Date.now() | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import models from '../db/models'; | ||
|
||
const { BlacklistTokens } = models; | ||
/** | ||
* logout | ||
*/ | ||
class logout { | ||
/** | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* @param {object} next | ||
* @returns {message} user already logged out | ||
*/ | ||
static async logoutToken(req, res, next) { | ||
const head = req.headers.token; | ||
const findToken = await BlacklistTokens.findOne({ | ||
where: { token: head } | ||
}); | ||
if (findToken) { | ||
return res.status(400).json({ message: 'user already logged out' }); | ||
} | ||
next(); | ||
} | ||
} | ||
|
||
export default logout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.