alectrocute / fastify-nedb-auth-boilerplate

a simple API boilerplate for server-side auth with fastify and nedb πŸ’‘

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fastify-nedb-auth-boilerplate

a simple API boilerplate for server-side auth with fastify and nedb πŸ’‘

If you hate databases that run binaries and are comfortable with JS - then this boilerplate may be for you.

It also features shoddy best password security practices (so even if baddies get that sweet, sweet static-file nedb database, it'll just have a bunch of salted hashes).

Ingredients

Getting Started

Assuming you have any version of Node.js installed...

Clone and install dependencies

git clone https://github.com/alectrocute/fastify-nedb-auth-boilerplate.git boilerplate;
cd boilerplate;
npm i;

Config

In the file config.js –

{
   // sessions
   secret: "ExCL45zXxL5LuAWqcFswQBvX11FiKYNRoawivW8KjH0UuKJDLysYMkhgwkrh",
   cookieName: "boilerplate_cookie_example",
   // nedb compaction rate
   compactInterval: 5000,
   // for fastify server
   hostname: "localhost",
   port: 3000,
 }

Run

npm run serve

Endpoints

POST /api/register

Registers an account.

Expects JSON, payload example:

{
  "email": "ceo@ecorp.com",
  "password": "hunter1"
  "passwordConfirm": "hunter1"
}

POST /api/login

Authenticates and creates a session for the user.

Expects JSON, payload example:

{
  "email": "ceo@ecorp.com",
  "password": "hunter1"
}

PUT /api/account

Modifies details in the authenticated user's database entry.

Expects JSON, payload example:

{
  "email": "ceo@ecorp.com",
  "key": "meta.subscriberActive",
  "value": "true"
}

GET /api/session

Returns the server-persisted session of the requester, if any.

Returns JSON, payload example:

200

{
  "email": "ceo@ecorp.com",
  "salt": "3rh808j0n#2f9"
}

GET /api/logout

Removes the requester's session, if any.

Returns JSON, payload example:

200

{
  "res": "true"
}

About

a simple API boilerplate for server-side auth with fastify and nedb πŸ’‘


Languages

Language:JavaScript 100.0%