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).
Assuming you have any version of Node.js installed...
git clone https://github.com/alectrocute/fastify-nedb-auth-boilerplate.git boilerplate;
cd boilerplate;
npm i;
In the file config.js
β
{
// sessions
secret: "ExCL45zXxL5LuAWqcFswQBvX11FiKYNRoawivW8KjH0UuKJDLysYMkhgwkrh",
cookieName: "boilerplate_cookie_example",
// nedb compaction rate
compactInterval: 5000,
// for fastify server
hostname: "localhost",
port: 3000,
}
npm run serve
Registers an account.
Expects JSON, payload example:
{
"email": "ceo@ecorp.com",
"password": "hunter1"
"passwordConfirm": "hunter1"
}
Authenticates and creates a session for the user.
Expects JSON, payload example:
{
"email": "ceo@ecorp.com",
"password": "hunter1"
}
Modifies details in the authenticated user's database entry.
Expects JSON, payload example:
{
"email": "ceo@ecorp.com",
"key": "meta.subscriberActive",
"value": "true"
}
Returns the server-persisted session of the requester, if any.
Returns JSON, payload example:
200
{
"email": "ceo@ecorp.com",
"salt": "3rh808j0n#2f9"
}
Removes the requester's session, if any.
Returns JSON, payload example:
200
{
"res": "true"
}