https://github.com/alectrocute/fastify-nedb-auth-boilerplate
a simple API boilerplate for server-side auth with fastify and nedb 💡
https://github.com/alectrocute/fastify-nedb-auth-boilerplate
api auth authentication boilerplate db example express fastify javascript js nedb node nodejs server user
Last synced: 2 months ago
JSON representation
a simple API boilerplate for server-side auth with fastify and nedb 💡
- Host: GitHub
- URL: https://github.com/alectrocute/fastify-nedb-auth-boilerplate
- Owner: alectrocute
- Created: 2020-05-06T20:33:30.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-06T21:01:14.000Z (about 6 years ago)
- Last Synced: 2026-02-08T20:57:21.558Z (4 months ago)
- Topics: api, auth, authentication, boilerplate, db, example, express, fastify, javascript, js, nedb, node, nodejs, server, user
- Language: JavaScript
- Homepage:
- Size: 1.89 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://github.com/louischatriot/nedb), it'll just have a bunch of [salted hashes]([https://en.wikipedia.org/wiki/Salt_(cryptography)](https://en.wikipedia.org/wiki/Salt_(cryptography)))).
## Ingredients
* [fastify](https://www.fastify.io/)
* [fastify-cookie](https://github.com/fastify/fastify-cookie)
* [fastify-session](https://www.npmjs.com/package/fastify-session)
* [nedb](https://github.com/louischatriot/nedb)
## Getting Started
Assuming you have any version of Node.js installed...
#### Clone and install dependencies
```bash
git clone https://github.com/alectrocute/fastify-nedb-auth-boilerplate.git boilerplate;
cd boilerplate;
npm i;
```
#### Config
In the file `config.js` –
```js
{
// sessions
secret: "ExCL45zXxL5LuAWqcFswQBvX11FiKYNRoawivW8KjH0UuKJDLysYMkhgwkrh",
cookieName: "boilerplate_cookie_example",
// nedb compaction rate
compactInterval: 5000,
// for fastify server
hostname: "localhost",
port: 3000,
}
```
#### Run
```bash
npm run serve
```
## Endpoints
#### POST /api/register
Registers an account.
Expects JSON, payload example:
```js
{
"email": "ceo@ecorp.com",
"password": "hunter1"
"passwordConfirm": "hunter1"
}
```
#### POST /api/login
Authenticates and creates a session for the user.
Expects JSON, payload example:
```js
{
"email": "ceo@ecorp.com",
"password": "hunter1"
}
```
#### PUT /api/account
Modifies details in the authenticated user's database entry.
Expects JSON, payload example:
```js
{
"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:
```js
200
{
"email": "ceo@ecorp.com",
"salt": "3rh808j0n#2f9"
}
```
#### GET /api/logout
Removes the requester's session, if any.
Returns JSON, payload example:
```js
200
{
"res": "true"
}
```