-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(logout): User should be able to sign out
- add authentication middleware - add functionality to sign out a user - write tests for logout route - add a pretest script [Finishes #167164982]
- Loading branch information
Showing
14 changed files
with
189 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ after_success: | |
- npm run coveralls | ||
|
||
git: | ||
depth: 20 | ||
depth: 50 |
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
23 changes: 23 additions & 0 deletions
23
src/database/migrations/20190807135714-create-blacklisted-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,23 @@ | ||
export const up = (queryInterface, Sequelize) => queryInterface.createTable('BlacklistedTokens', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
expTime: { | ||
type: Sequelize.STRING | ||
}, | ||
token: { | ||
type: Sequelize.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
export const down = queryInterface => queryInterface.dropTable('BlacklistedTokens'); |
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,8 @@ | ||
export default (sequelize, DataTypes) => { | ||
const BlacklistedToken = sequelize.define('BlacklistedToken', { | ||
expTime: DataTypes.STRING, | ||
token: DataTypes.STRING | ||
}, {}); | ||
BlacklistedToken.associate = () => {}; | ||
return BlacklistedToken; | ||
}; |
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,9 @@ | ||
import db from '../database/models'; | ||
|
||
const { BlacklistedToken } = db; | ||
|
||
const findBlacklistedToken = token => BlacklistedToken.findOne({ where: { token } }); | ||
|
||
export default { | ||
findBlacklistedToken | ||
}; |
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,23 @@ | ||
import Sequelize from 'sequelize'; | ||
import db from '../database/models'; | ||
|
||
|
||
const { BlacklistedToken } = db; | ||
const { Op } = Sequelize; | ||
|
||
const deleteExpiredBlacklistedToken = async () => { | ||
const todaysDate = new Date(); | ||
const currentUnixTime = Math.floor(todaysDate.getTime() / 1000); | ||
const tokens = await BlacklistedToken.findAll({ | ||
where: { expTime: { [Op.lte]: currentUnixTime.toString() } } | ||
}); | ||
|
||
const tokenArray = tokens.map(value => value.id); | ||
BlacklistedToken.destroy({ | ||
where: { | ||
id: tokenArray | ||
} | ||
}); | ||
}; | ||
|
||
deleteExpiredBlacklistedToken(); |
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
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