Skip to content

Commit b7a5f49

Browse files
authored
Merge pull request #23 from OpenNBS/feature/login-by-email
Login-by-email feature and supporting infrastructure
2 parents 0ee5639 + 9491151 commit b7a5f49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3621
-165
lines changed

CONTRIBUTING.md

+99-28
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,92 @@
22

33
Hello! We're glad to have you interested in contributing to Note Block World. This document will guide you through the process of setting up the project and submitting your contributions.
44

5-
This page is a work-in-progress and will be updated as the project evolves. If you have any questions or need help, feel free to reach out to us on our [Discord server](https://discord.gg/note-block-world-608692895179997252).
5+
This page is a work in progress and will be updated as the project evolves. If you have any questions or need help, feel free to reach out to us on our [Discord server](https://discord.gg/note-block-world-608692895179997252).
66

77
## Stack
88

99
This is a multipackage monorepo managed by [pnpm](https://pnpm.io/), which houses both the backend and frontend of the website. The backend is built with [NestJS](https://nestjs.com/) and the frontend is built with [Next.js](https://nextjs.org/) using server-side rendering (SSR). We use [MongoDB](https://www.mongodb.com/) as our database and [Backblaze B2](https://www.backblaze.com/cloud-storage) for file storage via its S3-compatible API.
1010

11-
## Setting up
11+
## Setting up the project for development
1212

13-
To easily install the project, you can use the [docker-compose.yml](docker-compose.yml) file.
13+
To easily install the project, you can use the [docker-compose-dev.yml](docker-compose-dev.yml) file.
1414

1515
```bash
16-
docker-compose up -d
16+
docker-compose -f docker-compose-dev.yml up -d
1717
```
18+
obs: You can remove the `-d` flag to see the containers' logs.
1819

19-
This will start the backend and frontend servers, as well as a MongoDB instance.
20+
This will start a database container, a maildev container, a minio container, and a minio-client container.
21+
You can check the authentication details in the [docker-compose-dev.yml](docker-compose-dev.yml) file.
2022

21-
---
23+
To configure the env variables, create `.env.development` and `.env.local` files in the [backend](server) and [front-end](web) packages, based on the example files provided. Alternatively, set the environment variables directly in your shell like so:
2224

23-
Alternatively, you can install and use `pnpm` directly:
25+
### backend:
2426

2527
```bash
26-
npm i -g pnpm
27-
pnpm install
28-
```
28+
export NODE_ENV=development
2929

30-
To configure the env variables, create `.env.development` and `.env.local` files in the backend and front-end packages, based on the example files provided. Alternatively, set the environment variables directly in your shell:
30+
export GITHUB_CLIENT_ID=UNSET
31+
export GITHUB_CLIENT_SECRET=UNSET
3132

32-
```bash
33-
export JWT_SECRET="jwtsecret"
34-
export JWT_EXPIRES_IN="1d"
35-
export DB_HOST="localhost:27017"
36-
export DB_PASSWORD="noteblockworldpassword"
37-
export DB_USER="noteblockworlduser"
38-
export SERVER_URL="http://localhost:3000"
33+
export GOOGLE_CLIENT_ID=UNSET
34+
export GOOGLE_CLIENT_SECRET=UNSET
35+
36+
export DISCORD_CLIENT_ID=UNSET
37+
export DISCORD_CLIENT_SECRET=UNSET
38+
39+
export MAGIC_LINK_SECRET=development_magic_link_secret
40+
41+
# in seconds
42+
export COOKIE_EXPIRES_IN=604800 # 1 week
43+
44+
export JWT_SECRET=developmentsecret
45+
export JWT_EXPIRES_IN=1h
46+
47+
export JWT_REFRESH_SECRET=developmentrefreshsecret
48+
export JWT_REFRESH_EXPIRES_IN=7d
49+
50+
export MONGO_URL=mongodb://noteblockworlduser:noteblockworldpassword@localhost:27017/noteblockworld?authSource=admin
51+
52+
export SERVER_URL=http://localhost:4000
53+
export FRONTEND_URL=http://localhost:3000
54+
#APP_DOMAIN=
55+
56+
export RECAPTCHA_KEY=disabled
57+
58+
export S3_ENDPOINT=http://localhost:9000
59+
export S3_BUCKET_SONGS=noteblockworld-songs
60+
export S3_BUCKET_THUMBS=noteblockworld-thumbs
61+
export S3_KEY=minioadmin
62+
export S3_SECRET=minioadmin
63+
export S3_REGION=us-east-1
64+
65+
export WHITELISTED_USERS=
66+
67+
export DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/UNSET
68+
69+
export MAIL_TRANSPORT=smtp://user:pass@localhost:1025
70+
export MAIL_FROM="Example <noreply@noteblock.world>"
3971
```
4072

41-
You can generate a JWT secret with OpenSSL and replace `jwtsecret` with the output:
73+
Note that for the OAuth providers, you will need to create an application on their respective developer portals and replace `UNSET` , in development, you can use the magic link login method for easy testing.
74+
75+
### frontend:
4276

4377
```bash
44-
openssl rand -hex 64
78+
export THUMBNAIL_URL=localhost:9000
79+
export NEXT_PUBLIC_RECAPTCHA_SITE_KEY="6Le7JNEpAAAAAN7US0WVtz10Mb-IfnTgw-IvEC6s"
80+
export NEXT_PUBLIC_URL=http://localhost:3000
81+
export NEXT_PUBLIC_API_URL=http://localhost:4000/api/v1
4582
```
4683

47-
In Windows, you can use `set` instead of `export`:
4884

49-
```bash
50-
set JWT_SECRET="jwtsecret"
51-
set JWT_EXPIRES_IN="1d"
52-
set DB_HOST="mongodb://localhost:27017/noteblockworld"
53-
set DB_PASSWORD="noteblockworldpassword"
54-
set DB_USER="noteblockworlduser"
55-
set SERVER_URL="http://localhost:3000"
85+
In Windows, you can use `set` instead of `export`.
86+
```cmd
87+
set THUMBNAIL_URL=localhost:9000
88+
set NEXT_PUBLIC_RECAPTCHA_SITE_KEY="6Le7JNEpAAAAAN7US0WVtz10Mb-IfnTgw-IvEC6s"
89+
set NEXT_PUBLIC_URL=http://localhost:3000
90+
set NEXT_PUBLIC_API_URL=http://localhost:4000/api/v1
5691
```
5792

5893
Finally, to run the frontend and backend servers:
@@ -61,4 +96,40 @@ Finally, to run the frontend and backend servers:
6196
pnpm run dev
6297
```
6398

99+
If you only want to run the backend or frontend, you can use the following commands:
100+
101+
```bash
102+
pnpm run dev:server
103+
```
104+
105+
```bash
106+
pnpm run dev:web
107+
```
108+
64109
The backend server will be available at [http://localhost:3000](http://localhost:3000) and the frontend server will be available at [http://localhost:4000](http://localhost:4000).
110+
111+
112+
For populating the database with some test data by sending a post request:
113+
114+
```bash
115+
curl -X 'GET' \
116+
'http://localhost:4000/api/v1/seed/seed-dev' \
117+
-H 'accept: */*'
118+
```
119+
120+
Just so you know, the seed route is only available in development mode.
121+
122+
Currently, tests are only available for the [backend](server), and [shared](shared) packages.
123+
124+
We use [Jest](https://jestjs.io/) for testing. To run the tests, you can use the following command on the package you want to test:
125+
126+
```bash
127+
pnpm test
128+
```
129+
130+
## Code style
131+
132+
We provide a [Prettier](https://prettier.io/) and [ESLint](https://eslint.org/) configuration for the project. You can run the following command to format your code:
133+
```bash
134+
pnpm run lint
135+
```

docker-compose-dev.yml

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version: '3.8'
21
services:
32
mongodb:
3+
container_name: opennoteworld-mongodb-dev
44
image: mongo
55
volumes:
66
- mongodb_data:/data/db
@@ -11,5 +11,54 @@ services:
1111
- MONGO_INITDB_DATABASE=noteblockworld
1212
- MONGO_INITDB_ROOT_USERNAME=noteblockworlduser
1313

14+
maildev:
15+
container_name: opennoteworld-maildev-dev
16+
image: maildev/maildev
17+
ports:
18+
- '1080:1080' # Web Interface
19+
- '1025:1025' # SMTP Server
20+
# to use the maildev container, you need to set the following environment variables in your application:
21+
# MAIL_TRANSPORT=smtp://maildev:1025 or MAIL_TRANSPORT=smtp://localhost:1025
22+
# MAIL_FROM="Example <noreply@noteblock.world>"
23+
#
24+
# You can also use the maildev web interface to view sent emails at http://localhost:1080
25+
26+
minio:
27+
container_name: minio
28+
image: minio/minio
29+
command: server /data --console-address :9001
30+
ports:
31+
- "9000:9000"
32+
- "9001:9001"
33+
environment:
34+
- MINIO_ROOT_USER=minioadmin
35+
- MINIO_ROOT_PASSWORD=minioadmin
36+
volumes:
37+
- minio_data:/data
38+
# You can access the MinIO web interface at http://localhost:9000
39+
# You can access the MinIO console at http://localhost:9001
40+
41+
mc:
42+
container_name: minio-client
43+
image: minio/mc
44+
entrypoint: ['/bin/sh', '-c']
45+
depends_on:
46+
- minio
47+
environment:
48+
- MINIO_ROOT_USER=minioadmin
49+
- MINIO_ROOT_PASSWORD=minioadmin
50+
command: >
51+
-c '
52+
while ! mc alias set minio http://minio:9000 minioadmin minioadmin; do
53+
echo "Waiting for MinIO to be available..."
54+
sleep 2
55+
done &&
56+
mc mb minio/noteblockworld-songs &&
57+
mc mb minio/noteblockworld-thumbs &&
58+
mc policy set public minio/noteblockworld-songs &&
59+
mc policy set public minio/noteblockworld-thumbs
60+
'
61+
1462
volumes:
1563
mongodb_data:
64+
minio_data:

0 commit comments

Comments
 (0)