Basic auth plugin for Graffiti.js
Add basic email & password based authentication to Graffiti.js GraphQL backend.
Installation
npm install graffiti-plugin-auth
Usage
Create a graffiti.config.js
in your project:
const authPlugin = ; moduleexports = mongoUrl: 'mongodb://localhost/graffiti-example' plugins: ;
Plugin settings
Auth plugin accepts the following options during init:
;
Dev-mode auth forms
For convenience, when running in development mode, auth plugin creates two pages /dev/register
and /dev/login
that allow you to register and login without setting up any front-end.
Accessing current user
You might need to access current user in some cases.
This can be either done from fastify (through request.user
), or through GraphQL context, e.g.:
// define new resolvers function that will create our custom resolverexports { // Define new resolver 'myResolver' resolver // This example is just a simple resolver that shows how to access current user typedef;};