1.0.0 • Published 4 years ago

@softwits/user-authentication-authorization v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Send JWT token in the name of 'Authorization'

How to use it?

import { AuthRoutes, SoftwitsAuthentication } from '@softwits/user-management';
import { MongoConnectionProps, MongoDB } from '@softwits/databases';

new MongoDB().connect(db);
const serverOpts = {
  port: 9000,
};
// To intialize local strategy
new SoftwitsAuthentication();

to setup routes

import { graphqlServer  } from '@softwits/express-graphql-rest';
graphqlServer.createApolloServer(schema, resolvers, null, { port: 4000 }, null, [new AuthRoutes()]);

or

import { expressServer } from '@softwits/express-graphql-rest';
expressServer.startServer(serverOpts, [new AuthRoutes()]);

Validate routes

   httpServer.get(
      '/test',
      (req: Request, res: Response, next: NextFunction) => {
        res.send('success');
      },
      [authenticate('jwtVerify', { session: false })],
    );

use authenticate('jwtVerify', { session: false }) as middleware in the routes