Javascript Vue

Simplistic quote saving web app, built with Nuxt and Prisma3 min read

QuoteDB

Started for use in a friend group, this project is both a very minimal quote DB and a nice PoC for Nuxt3 + Prisma with an API and JWT authentication.

ToDo

[x] API

[x] Database schema
[x] Quote CRUD
[x] Users

[x] Login
[x] Invite & register

[x] User interface

[x] List quotes
[x] Log in & register
[x] Profile
[x] Invite
[ ] Edit quotes

[ ] Complete README
[x] Docker configuration
[ ] Unbodge

[ ] Use native store instead of bodged cookie store for state persistence
[ ] Make a proper API client

Use

The database does not contain any data out of the box. You also don’t need an invite token to create the first user account.

API

The API is used internally, but may also be used by 3rd party applications.

Endpoints

Method
Endpoint
Auth
Description

GET
/quotes
๐Ÿ”
Lists all quotes if authenticated; only public quotes otherwise

GET
/quotes/:id
๐Ÿ”
Returns quote referenced by :id (if public or authenticated)

POST
/quotes
๐Ÿ”’
Creates a new quote

POST
/quotes/:id
๐Ÿ”’
Updates the quote referenced by :id

DELETE
/quotes/:id
๐Ÿ”
Deletes the quote referenced by :id

GET
/user
๐Ÿ”’
Returns the profile of the authenticated user

POST
/user/login
โŒ
Verifies the received credentials and returns a JWT token if successful

POST
/user/register
โŒ
Creates an account using an invite token; returns a JWT token if successful

GET
/user/invite
๐Ÿ”’
Creates an invite token (up to 5 per user)

Auth

The API uses Bearer authentication with JWT tokens.
The table below explains the authentication/authorization indications in the endpoints table.

Icon
Authorization

๐Ÿ”’
Only authenticated access

๐Ÿ”
Only author can perform action

๐Ÿ”
Partial unauthenticated access

โŒ
Only unauthenticated access

Wanna help?

First of all, check out the Nuxt 3 documentation. Keep in mind this version of the framework is in beta.

Setup

Install dependencies

yarn install

Copy example.env -> .env and make changes where necessary.

To create/update the database schema, run Prisma migrate:

npx prisma migrate dev

In order for this to work, the configured database user needs permission to connect and to query and alter tables.

Development

Start the development server on http://localhost:3000

yarn dev

Test build

Build the application for production:

yarn build

You can also test migrations in production mode using:

npx prisma migrate deploy

Again, the configured database user needs to have permission to alter the DB schema in order for Prisma to work.

Deployment on Docker

The docker configuration in this repository is made for the following environment:

An nginx-proxy (with acme-companion) container handles incoming HTTP traffic and certificates, and is reachable via a docker network named web.
A Postgres database is reachable via a docker network named postgres; its URL and credentials for it are set in the DATABASE_URL variable in .env.
The specified database user needs to be able to connect and to alter the database schema.
The JWT_SECRET is set in .env.

Of course you can deviate from this if you want to run this project yourself.

On startup, the container runs migrations and then starts the server.

GitHub

https://github.com/Pwuts/quotes

Pin It on Pinterest

Generated by Feedzy