Skip to content

Login-by-email feature and supporting infrastructure #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 118 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
67428df
feat: implement CryptoModule and CryptoService for password hashing
tomast1337 Dec 20, 2024
db12764
feat: add LoginDto and RegisterDto for user validation
tomast1337 Dec 20, 2024
9d51116
fix: clean up imports in song module and service test files
tomast1337 Dec 20, 2024
7dad819
feat: add SocialLinks schema to User entity for enhanced social media…
tomast1337 Dec 20, 2024
f157009
feat: integrate CryptoService into UserService for password hashing a…
tomast1337 Dec 20, 2024
abd5623
feat: add user registration and login endpoints to AuthController and…
tomast1337 Dec 20, 2024
0cb0e42
feat: integrate CryptoModule into the application for enhanced securi…
tomast1337 Dec 20, 2024
598ed0d
test: add unit tests for password hashing and comparison in CryptoSer…
tomast1337 Dec 20, 2024
8464484
Merge branch 'feature/env-validation' of https://github.com/OpenNBS/N…
tomast1337 Dec 20, 2024
0332443
feat: add MinIO service to docker-compose for object storage
tomast1337 Dec 21, 2024
20748ec
feat: add SALTS_ROUNDS environment variable validation to Environment…
tomast1337 Dec 21, 2024
f5442ad
refactor: convert CryptoModule to use @Module decorator for improved …
tomast1337 Dec 21, 2024
60a69bd
refactor: simplify CryptoModule imports by removing forRoot calls
tomast1337 Dec 21, 2024
27322fc
chore: update dependencies to latest versions for improved stability …
tomast1337 Dec 24, 2024
f16b9bc
fix: set default value for APP_DOMAIN in EnvironmentVariables class
tomast1337 Dec 24, 2024
b2b80b2
feat: add user authentication method to validate email and password
tomast1337 Dec 24, 2024
aa816e6
refactor: update CryptoModule to use useFactory for SALTS_ROUNDS and …
tomast1337 Dec 24, 2024
de16d67
refactor: streamline error handling in user authentication process
tomast1337 Dec 24, 2024
fbe0042
refactor: simplify login method and update dependency injection to us…
tomast1337 Dec 24, 2024
9275669
fix: correct email extraction from response data in AuthService
tomast1337 Dec 24, 2024
6d9a3ce
feat: implement Seed module with controller and service for developme…
tomast1337 Dec 24, 2024
b4c7575
refactor: remove unnecessary console log in AuthService constructor
tomast1337 Dec 24, 2024
b61326f
feat: add SeedModule to app module for development seeding
tomast1337 Dec 24, 2024
e714994
feat: add @faker-js/faker to devDependencies for test data generation
tomast1337 Dec 24, 2024
50c7a27
feat: update @faker-js/faker to version 9.3.0 in devDependencies
tomast1337 Dec 24, 2024
2544253
feat: add LoginForm and RegistrationForm components for user authenti…
tomast1337 Dec 24, 2024
204f36a
feat: add LoginWithEmailPage component and update LoginPage with emai…
tomast1337 Dec 24, 2024
bb58231
feat: add Login and Registration pages with email authentication
tomast1337 Dec 24, 2024
f30154f
feat: add SubmitButton component for form submissions
tomast1337 Dec 24, 2024
9e68c64
feat: add RegistrationPage component for user registration
tomast1337 Dec 24, 2024
056ff01
feat: add MinIO client service to docker-compose for managing MinIO b…
tomast1337 Dec 25, 2024
f101778
feat: improve MinIO service startup command to wait for availability …
tomast1337 Dec 25, 2024
4e15cd1
feat: add ApiTags decorator to MySongsController for improved Swagger…
tomast1337 Dec 25, 2024
97b020b
feat: add update method to UserService for updating user documents
tomast1337 Dec 25, 2024
25fb2e1
feat: refactor FileModule and FileService to use factory providers an…
tomast1337 Dec 25, 2024
89e80e2
feat: remove console log from validate function in EnvironmentVariables
tomast1337 Dec 25, 2024
8e45924
feat: refactor SongUploadService to streamline file validation and bu…
tomast1337 Dec 25, 2024
33f4c1d
feat: add getSongById method to SongService for retrieving songs by p…
tomast1337 Dec 25, 2024
9e52a45
feat: implement seedDev method for seeding development data and updat…
tomast1337 Dec 25, 2024
6da8f46
feat: implement EmailLogin module with controller and service, includ…
tomast1337 Dec 29, 2024
313b910
feat: implement Mailing module with controller and service, including…
tomast1337 Dec 29, 2024
21c58fb
feat: add EmailLogin and Mailing modules to the application imports
tomast1337 Dec 29, 2024
3000808
feat: refactor RegistrationForm component and add validation schema
tomast1337 Dec 29, 2024
a65388c
feat: add reusable Button component with disabled state support
tomast1337 Dec 29, 2024
1790c01
Merge branch 'develop' of https://github.com/OpenNBS/NoteBlockWorld i…
tomast1337 Dec 29, 2024
b9e6500
refactor: clean up imports and formatting across multiple files
tomast1337 Dec 29, 2024
0b76d51
feat: implement email sending functionality in MailingService and add…
tomast1337 Dec 29, 2024
9b00dad
refactor: remove Crypto module and service along with their tests
tomast1337 Dec 29, 2024
ec5bcee
feat: add mailer and magic login passport modules to package.json
tomast1337 Dec 29, 2024
d8f85ed
feat: add maildev service to docker-compose for email testing
tomast1337 Dec 29, 2024
16c9d3b
feat: add Swagger plugin and update asset configuration in nest-cli.json
tomast1337 Dec 29, 2024
73837d7
feat: refactor User entity and service to remove password handling an…
tomast1337 Dec 29, 2024
4d55df2
feat: implement email strategy for magic link authentication
tomast1337 Dec 29, 2024
6ebf9d8
feat: implement email-based registration and login flow with single-u…
tomast1337 Dec 29, 2024
b0d5d66
feat: export MailingService from MailingModule and fix import order i…
tomast1337 Dec 29, 2024
ac29c61
feat: update user creation in SeedService to use email instead of pas…
tomast1337 Dec 29, 2024
9763909
feat: update EnvironmentVariables to include magic link auth and mail…
tomast1337 Dec 29, 2024
d051238
feat: integrate MailerModule for email handling with Handlebars templ…
tomast1337 Dec 29, 2024
6e356a2
refactor: rename login template to magic-link and update link variable
tomast1337 Dec 30, 2024
516942d
refactor: update sendEmail method to accept a single object parameter…
tomast1337 Dec 30, 2024
4ba1ebd
fix: update output directory for mailing templates in nest-cli config…
tomast1337 Dec 30, 2024
6b9e07d
refactor: remove unused Inject decorator from user service
tomast1337 Dec 30, 2024
1d31da7
refactor: reorganize MailerModule and HandlebarsAdapter imports in ap…
tomast1337 Dec 30, 2024
fcda2e6
docs: add comments for maildev and MinIO web interface access in dock…
tomast1337 Dec 30, 2024
eee7070
refactor: replace EmailStrategy with MagicLinkEmailStrategy for impro…
tomast1337 Dec 30, 2024
cfabec9
test: add unit tests for MagicLinkEmailStrategy functionality
tomast1337 Dec 30, 2024
67c5841
feat: implement magic link authentication flow in AuthController and …
tomast1337 Dec 30, 2024
f5d8907
fix: correct async call in onModuleInit and comment out logging in po…
tomast1337 Dec 30, 2024
344dd92
fix: remove console log for background color in getUploadDiscordEmbed…
tomast1337 Dec 30, 2024
39c0c40
fix: update default values for description and profileImage in User e…
tomast1337 Dec 30, 2024
8a3d28c
refactor: rename and reorganize user DTOs for improved clarity and st…
tomast1337 Dec 30, 2024
486d78b
Merge branch 'main' into feature/login-by-email
Bentroen Dec 31, 2024
541ba14
feat: add throttling functionality with @nestjs/throttler for rate li…
tomast1337 Dec 31, 2024
b78338b
refactor: remove register endpoint and update magic link login summar…
tomast1337 Dec 31, 2024
f1782f6
refactor: simplify createWithEmail method by removing DTO and using e…
tomast1337 Dec 31, 2024
73e1439
fix: add TODO comment for enabling custom domain usage in getPublicFi…
tomast1337 Dec 31, 2024
fb65247
refactor: remove registration components and update login form to han…
tomast1337 Dec 31, 2024
2f468df
refactor: update user creation to use email parameter directly instea…
tomast1337 Dec 31, 2024
6c392ac
refactor: update magic link strategy to create user if not found and …
tomast1337 Dec 31, 2024
2d87f5b
refactor: remove email validation logic from signInWithEmail and Auth…
tomast1337 Dec 31, 2024
230901c
Merge branch 'feature/login-by-email' of https://github.com/OpenNBS/N…
tomast1337 Dec 31, 2024
c78b9db
refactor: inject COOKIE_EXPIRES_IN into AuthService and update cookie…
tomast1337 Dec 31, 2024
0d54192
refactor: inject COOKIE_EXPIRES_IN into AuthService tests and update …
tomast1337 Dec 31, 2024
9d37124
refactor: enhance magic link strategy to create user if not found and…
tomast1337 Dec 31, 2024
ad6e988
refactor: mock SeedService in SeedController tests
tomast1337 Dec 31, 2024
70c3b73
refactor: update AuthController to implement magic link login and red…
tomast1337 Dec 31, 2024
e1b2f2c
Merge branch 'develop' of https://github.com/OpenNBS/NoteBlockWorld i…
tomast1337 Dec 31, 2024
57fad57
chore: re-added add dependencies for mailer, throttler, and magic log…
tomast1337 Dec 31, 2024
9a546c4
Merge branch 'develop' of https://github.com/OpenNBS/NoteBlockWorld i…
tomast1337 Jan 1, 2025
23ee4f7
test: add HeadBucketCommand mock and verifyBucket tests in FileService
tomast1337 Jan 1, 2025
5740581
Lint fixes
tomast1337 Jan 1, 2025
bd4c742
feat: update login form to use magic link and add success/error notif…
tomast1337 Jan 1, 2025
2dbefff
fix: update asset include pattern for Handlebars templates in nest-cl…
tomast1337 Jan 1, 2025
26df20a
fix: handle potential errors when retrieving token in Axios request i…
tomast1337 Jan 1, 2025
69f72b5
fix: update default profile image path in User entity
tomast1337 Jan 1, 2025
8855511
Added note-block-pfp.jpg for default profile picture
tomast1337 Jan 1, 2025
435c8a4
feat: enhance success notifications for magic link login process
tomast1337 Jan 1, 2025
1949a4d
feat: add email login option to the login page
tomast1337 Jan 1, 2025
0db3b64
fix: remove unused axios import in LoginForm component
tomast1337 Jan 1, 2025
20b5c99
feat: implement throttle configuration and usage for rate limiting
tomast1337 Jan 1, 2025
5e07e4e
feat: add throttle usage for magic link login endpoint
tomast1337 Jan 1, 2025
554547a
refactor: update throttler configuration for improved rate limiting
tomast1337 Jan 1, 2025
7c24ec9
Update CONTRIBUTING.md
tomast1337 Jan 4, 2025
936b797
feat: update seed method to return seeding progress message
tomast1337 Jan 4, 2025
358dcd3
refactor: remove unnecessary logging from seed generation process
tomast1337 Jan 4, 2025
71bed47
feat: update MinIO configuration to expose console and set bucket pol…
tomast1337 Jan 4, 2025
ddd4cfe
feat: add localhost configuration to Next.js settings
tomast1337 Jan 4, 2025
a659241
feat: enhance getPublicFileUrl to support MinIO endpoint for local de…
tomast1337 Jan 4, 2025
12f8a49
feat: specify port for localhost configuration in Next.js settings
tomast1337 Jan 4, 2025
335fc95
feat: add support for image attachments in mailing service and update…
tomast1337 Jan 5, 2025
d7cce6d
feat: enhance email templates with improved styling and button for lo…
tomast1337 Jan 5, 2025
3db9c9c
feat: simplify magic link email templates by removing outer div and u…
tomast1337 Jan 5, 2025
fb977ce
feat: update MagicLinkEmailStrategy to create user if not found and i…
tomast1337 Jan 5, 2025
2e959a4
feat: implement throttling guard and update throttling configuration …
tomast1337 Jan 6, 2025
bcd085a
refactor: remove Throttle configuration and related tests for cleaner…
tomast1337 Jan 6, 2025
33c5d33
feat: enhance error handling in LoginForm to provide specific feedbac…
tomast1337 Jan 6, 2025
bbfd4b1
Merge branch 'develop' of https://github.com/OpenNBS/NoteBlockWorld i…
tomast1337 Jan 19, 2025
9491151
Merge branch 'develop' of https://github.com/OpenNBS/NoteBlockWorld i…
tomast1337 Mar 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 99 additions & 28 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,92 @@

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.

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).
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).

## Stack

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.

## Setting up
## Setting up the project for development

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

```bash
docker-compose up -d
docker-compose -f docker-compose-dev.yml up -d
```
obs: You can remove the `-d` flag to see the containers' logs.

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

---
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:

Alternatively, you can install and use `pnpm` directly:
### backend:

```bash
npm i -g pnpm
pnpm install
```
export NODE_ENV=development

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:
export GITHUB_CLIENT_ID=UNSET
export GITHUB_CLIENT_SECRET=UNSET

```bash
export JWT_SECRET="jwtsecret"
export JWT_EXPIRES_IN="1d"
export DB_HOST="localhost:27017"
export DB_PASSWORD="noteblockworldpassword"
export DB_USER="noteblockworlduser"
export SERVER_URL="http://localhost:3000"
export GOOGLE_CLIENT_ID=UNSET
export GOOGLE_CLIENT_SECRET=UNSET

export DISCORD_CLIENT_ID=UNSET
export DISCORD_CLIENT_SECRET=UNSET

export MAGIC_LINK_SECRET=development_magic_link_secret

# in seconds
export COOKIE_EXPIRES_IN=604800 # 1 week

export JWT_SECRET=developmentsecret
export JWT_EXPIRES_IN=1h

export JWT_REFRESH_SECRET=developmentrefreshsecret
export JWT_REFRESH_EXPIRES_IN=7d

export MONGO_URL=mongodb://noteblockworlduser:noteblockworldpassword@localhost:27017/noteblockworld?authSource=admin

export SERVER_URL=http://localhost:4000
export FRONTEND_URL=http://localhost:3000
#APP_DOMAIN=

export RECAPTCHA_KEY=disabled

export S3_ENDPOINT=http://localhost:9000
export S3_BUCKET_SONGS=noteblockworld-songs
export S3_BUCKET_THUMBS=noteblockworld-thumbs
export S3_KEY=minioadmin
export S3_SECRET=minioadmin
export S3_REGION=us-east-1

export WHITELISTED_USERS=

export DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/UNSET

export MAIL_TRANSPORT=smtp://user:pass@localhost:1025
export MAIL_FROM="Example <noreply@noteblock.world>"
```

You can generate a JWT secret with OpenSSL and replace `jwtsecret` with the output:
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.

### frontend:

```bash
openssl rand -hex 64
export THUMBNAIL_URL=localhost:9000
export NEXT_PUBLIC_RECAPTCHA_SITE_KEY="6Le7JNEpAAAAAN7US0WVtz10Mb-IfnTgw-IvEC6s"
export NEXT_PUBLIC_URL=http://localhost:3000
export NEXT_PUBLIC_API_URL=http://localhost:4000/api/v1
```

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

```bash
set JWT_SECRET="jwtsecret"
set JWT_EXPIRES_IN="1d"
set DB_HOST="mongodb://localhost:27017/noteblockworld"
set DB_PASSWORD="noteblockworldpassword"
set DB_USER="noteblockworlduser"
set SERVER_URL="http://localhost:3000"
In Windows, you can use `set` instead of `export`.
```cmd
set THUMBNAIL_URL=localhost:9000
set NEXT_PUBLIC_RECAPTCHA_SITE_KEY="6Le7JNEpAAAAAN7US0WVtz10Mb-IfnTgw-IvEC6s"
set NEXT_PUBLIC_URL=http://localhost:3000
set NEXT_PUBLIC_API_URL=http://localhost:4000/api/v1
```

Finally, to run the frontend and backend servers:
Expand All @@ -61,4 +96,40 @@ Finally, to run the frontend and backend servers:
pnpm run dev
```

If you only want to run the backend or frontend, you can use the following commands:

```bash
pnpm run dev:server
```

```bash
pnpm run dev:web
```

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).


For populating the database with some test data by sending a post request:

```bash
curl -X 'GET' \
'http://localhost:4000/api/v1/seed/seed-dev' \
-H 'accept: */*'
```

Just so you know, the seed route is only available in development mode.

Currently, tests are only available for the [backend](server), and [shared](shared) packages.

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:

```bash
pnpm test
```

## Code style

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:
```bash
pnpm run lint
```
51 changes: 50 additions & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3.8'
services:
mongodb:
container_name: opennoteworld-mongodb-dev
image: mongo
volumes:
- mongodb_data:/data/db
Expand All @@ -11,5 +11,54 @@ services:
- MONGO_INITDB_DATABASE=noteblockworld
- MONGO_INITDB_ROOT_USERNAME=noteblockworlduser

maildev:
container_name: opennoteworld-maildev-dev
image: maildev/maildev
ports:
- '1080:1080' # Web Interface
- '1025:1025' # SMTP Server
# to use the maildev container, you need to set the following environment variables in your application:
# MAIL_TRANSPORT=smtp://maildev:1025 or MAIL_TRANSPORT=smtp://localhost:1025
# MAIL_FROM="Example <noreply@noteblock.world>"
#
# You can also use the maildev web interface to view sent emails at http://localhost:1080

minio:
container_name: minio
image: minio/minio
command: server /data --console-address :9001
ports:
- "9000:9000"
- "9001:9001"
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
volumes:
- minio_data:/data
# You can access the MinIO web interface at http://localhost:9000
# You can access the MinIO console at http://localhost:9001

mc:
container_name: minio-client
image: minio/mc
entrypoint: ['/bin/sh', '-c']
depends_on:
- minio
environment:
- MINIO_ROOT_USER=minioadmin
- MINIO_ROOT_PASSWORD=minioadmin
command: >
-c '
while ! mc alias set minio http://minio:9000 minioadmin minioadmin; do
echo "Waiting for MinIO to be available..."
sleep 2
done &&
mc mb minio/noteblockworld-songs &&
mc mb minio/noteblockworld-thumbs &&
mc policy set public minio/noteblockworld-songs &&
mc policy set public minio/noteblockworld-thumbs
'

volumes:
mongodb_data:
minio_data:
Loading