@stanlemon/server-with-auth

0.3.9 • Public • Published

Express App Server with Authentication

npm version

This is a base express app server that is wired up with sensible defaults, like compression, json support and serving the dist folder statically and also includes basic authentication support. It builds off of the @stanlemon/server package.

This package includes authentication against secure endpoints using JWT. There are endpoints for logging in and signing up, as well as basic user management flows such as updating a profile, verifying a user and resetting a password.

When NODE_ENV=development the server will also proxy requests to webpack.

This library goes well with @stanlemon/webdev. You can see this package, along with [@stanlemon/webdev] in action by using the @stanlemon/app-template package.

import {
  createAppServer,
  asyncJsonHandler as handler,
  NotFoundException,
  LowDBUserDao,
  createLowDb
} from "@stanlemon/server-with-auth";
import  from "./src/data/lowdb-user-dao.js";

const db = createLowDb();
const dao = new LowDBUserDao(db);

const app = createAppServer({
  port: 3003,secure: ["/api/"],
  schemas,
  dao,
 });


// Insecure endpoint
app.get(
  "/",
  handler(() => ({ hello: "world" }))
);

// Secure endpoint
app.get(
  "/api/users",
  handler(() => ({
    users: db.data.users.map((u) =>
      omit(u, ["password", "verification_token"])
    ),
  }))
);

Readme

Keywords

none

Package Sidebar

Install

npm i @stanlemon/server-with-auth

Weekly Downloads

58

Version

0.3.9

License

MIT

Unpacked Size

45.2 kB

Total Files

19

Last publish

Collaborators

  • stanlemon