You want a middleware support express get authorization from laravel-passport-structured database, this will help you.
npm install express-laravel-passport
or
npm install express-laravel-passport --save
if you use yarn
yarn add express-laravel-passport
- 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
}
}
}
}
if (<you have any idea for our library>) {
if (<you can do it by yourself>) {
<please do it and make a pull request>
<then [email me [email protected]](mailto:[email protected])>
} else {
<just [email me [email protected]](mailto:[email protected]), we will discuss how to deal with that>
}
}
If the library help you to solve your problem, you can buy me a coffee for night-shift-working to improve this. I will personally send you a picture of that coffee :D