Skip to content

Small middleware support getting user_id from Bearer header with laravel structure database

Notifications You must be signed in to change notification settings

EugeneNguyen/express-laravel-passport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Define your sequelize
const sequelize = new Sequelize('your_mysql_database', 'your_mysql_username', 'your_mysql_password', {
  host: 'your_mysql_host',
  dialect: 'mysql'
});
  1. import the library
import passport from 'express-laravel-passport';
  1. serve in express server
express.use('/', passport(sequelize), ...);
  1. serve in graphql server (optional)
graphQLServer.use('/graphql', passport(sequelize), cors(), bodyParser.json(), graphqlExpress(req => {
  return ({
    schema: schema,
    context: req
  });
}));
  1. 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
}
  1. 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
      }
    }
  }
}

Support

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>
  }
}

Donation

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

paypal

About

Small middleware support getting user_id from Bearer header with laravel structure database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published