0.2.0 • Published 4 years ago

@reshuffle/passport v0.2.0

Weekly downloads
18
License
MIT
Repository
github
Last release
4 years ago

@reshuffle/passport

"out-of-the-box" auth for your app.

Meant to be paired with @reshuffle/react-auth.

See a fully working demo here.

Installation

$ npm install @reshuffle/passport

Usage

Configure backend/_handler.js

const app = express();
app.use('/', authRouter());

// Custom routes go here

app.use(defaultHandler);

export default app;

Add custom routes

app.get('/display-name', (req, res) => {
  if (!req.user) {
    return res.sendStatus(403);
  }
  res.end(req.user.displayName);
});

Access user from your @exposed functions

backend/todos.js

import { getCurrentUser } from '@reshuffle/server-function';
import { get } from '@reshuffle/db';

/* @expose */
export async function getTodos() {
  const user = getCurrentUser(true /* required - will throw an error if not authenticated */);
  return get(`/todos/${user.id}`);
});