Skip to content

PoC for SIWE authentication implemented with NestJS and React

KristianBalaj/siwe-auth

Repository files navigation

PoC for SIWE authentication

SIWE is a standardized approach for implementing authentication using an Ethereum crypto wallet.

This PoC is demonstrating the following functionality:

  • user sign-up
  • user sign-in (protected using nonce against replay attacks)
  • JWT authenticated API endpoint for querying the user profile

This repository is a PoC demonstrating capabilities on a simplified React frontend and core functionality being the backend written in Nestjs. The backend is implemented using a functional coding style utilising the fp-ts package.

The repository is dockerized and uses a monorepo structure using the Nx tool.

Spining up the project

Straightforward version (Unix platforms)

From the root of the project, run the following commands:

cp .env.example .env
cp ./apps/api/.env.example ./apps/api/.env
docker compose up --build

Then navigate to http://localhost:4200

Verbose version

Serving of the project is done via Docker.

  1. Create .env in the root of the project directory (feel free to just copy-paste the contents of the .env.example)
  2. Create ./apps/api/.env (feel free to copy the contents of ./apps/api/.env.example for development purposes only)
    • It's separated, so these are available only in the API container for security purposes (e.g., JWT secret).
  3. Run docker compose up --build
  4. Navigate to http://localhost:4200 in your browser

Dev platform compatibility

Developed on macOS Intel, so I can confirm only that one.

  • MacOS (Intel) ✅
  • MacOS (Apple Silicon) ❓
  • Linux ❓
  • Windows ❓

Testing

To run all the tests:

npm run test

Lint

To run lint for the whole project:

npm run lint

Formatting

To format the whole project:

npm run format

Troubleshooting

Docker containers missing dependencies

When dependencies change, run the following:

  • docker compose down -v
  • docker compose up --build

sqlite3 dependency errors in container

To modify the package-lock.json so that the dependency works in containers run the following npm install sqlite3@5.0.0. It may break after addition of other packages so feel free to npm install it again when you notice the error.

References

About

PoC for SIWE authentication implemented with NestJS and React

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published