-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add route - add controller - update migration - save token on signup - save token on social login - save token on signin - [Finishes #170650327]
- Loading branch information
1 parent
3f958d9
commit bc2d471
Showing
9 changed files
with
140 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.addColumn('users', 'token', { | ||
type: Sequelize.TEXT | ||
}) | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.removeColumn('users', 'token') | ||
} | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/database/migrations/20200114223019-create-blacklist.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,27 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('blacklists', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
token: { | ||
type: Sequelize.TEXT | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('blacklists'); | ||
} | ||
}; |
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,10 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const blacklist = sequelize.define('blacklist', { | ||
token: DataTypes.TEXT | ||
}, {}); | ||
blacklist.associate = function(models) { | ||
// associations can be defined here | ||
}; | ||
return blacklist; | ||
}; |
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,34 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import Response from '../helpers/Response'; | ||
import UserService from '../services/UserService'; | ||
/** | ||
* verify token | ||
* @param {object} req request object | ||
* @param {object} res response object | ||
* @param {object} next response object | ||
* @returns {object} data | ||
* next | ||
*/ | ||
const verifyToken = (req, res, next) => { | ||
const token = !req.headers.token ? req.params.token : req.headers.token; | ||
if (!token) { | ||
return Response.errorMessage(req, res, 'Please, insert the token', 401); | ||
} | ||
jwt.verify( | ||
token, process.env.JWT_KEY, | ||
async (err, result) => { | ||
if (err) { | ||
return Response.errorMessage(req, res, err, 401); | ||
} | ||
const isTokenExist = await UserService.blacklistToken(token); | ||
if (isTokenExist) { | ||
return Response.errorMessage(req, res, 'You have provided an invalid token', 401); | ||
} | ||
result.token = token; | ||
req.user = result; | ||
next(); | ||
} | ||
); | ||
}; | ||
|
||
export default verifyToken; |
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