express-laravel-passport
v1.1.2
Published
Small middleware support getting user_id from Bearer header with laravel structure database
Downloads
13
Maintainers
Readme
express-laravel-passport
You want a middleware support express get authorization from laravel-passport-structured database, this will help you.
How to install
npm install express-laravel-passport
or
npm install express-laravel-passport --save
if you use yarn
yarn add express-laravel-passport
How to use
- Define your sequelize
const sequelize = new Sequelize('your_mysql_database', 'your_mysql_username', 'your_mysql_password', {
host: 'your_mysql_host',
dialect: 'mysql'
});
- import the library
import passport from 'express-laravel-passport';
- serve in express server
express.use('/', passport(sequelize), ...);
- serve in graphql server (optional)
graphQLServer.use('/graphql', passport(sequelize), cors(), bodyParser.json(), graphqlExpress(req => {
return ({
schema: schema,
context: req
});
}));
- get user_id in express server
const user_id = request.user_id;
if (user_id) {
// logged in
} else {
// not logged in || missing authentication header || token wrong
}
- get user_id in graphql server (optional)
const resolvers = {
Query: {
async testQuery(_, args, request, info) {
const user_id = request.user_id;
if (user_id) {
// logged in
} else {
// not logged in || missing authentication header || token wrong
}
}
}
}