A secure, WebAuthn-based authentication system built with NestJS that implements passwordless authentication using passkeys.
- Node.js (v20 or higher)
- PostgreSQL (v15 or higher)
- Docker & Docker Compose (for containerized setup)
- mkcert (for local HTTPS setup)
- Clone the repository:
git clone https://github.com/tarunvaddeSoul/passkey-auth.git
cd passkey-auth
- Create
.env
file:
cp .env.sample .env
- Start the application:
# Development mode
docker compose up -d
# Apply prisma generate
docker compose exec api npx prisma generate
docker compose exec api npx prisma db push
- Access the application:
- API: https://localhost:3000
- Swagger Documentation: https://localhost:3000/api
- Clone the repository:
git clone https://github.com/tarunvaddeSoul/passkey-auth.git
cd passkey-auth
- Install dependencies:
npm install
- Set up the database:
# Create a PostgreSQL database
createdb passkey_db
# Apply prisma
npx prisma generate
npx prisma db push
- Create
.env
file:
cp .env.example .env
- Start the application:
# Development mode
npm run start:dev
# Production mode
npm run build
npm run start:prod
- Install mkcert:
# macOS
brew install mkcert
mkcert -install
# Ubuntu/Debian
apt install mkcert
mkcert -install
# Windows (using Chocolatey)
choco install mkcert
mkcert -install
- Generate certificates:
mkcert localhost
- Update certificate paths in your code:
// main.ts
const httpsOptions = {
key: fs.readFileSync('./localhost-key.pem'),
cert: fs.readFileSync('./localhost.pem'),
};
- Trust the certificates:
# The certificates should be automatically trusted after running mkcert -install
# You can verify by opening https://localhost:3000 in your browser
Once the application is running, visit https://localhost:3000/api for the Swagger documentation.
# Application
PORT=3000
RP_NAME=Your App Name
RP_ID=localhost
ORIGIN=https://localhost:3000
# Database
POSTGRES_USER=passkey_user
POSTGRES_PASSWORD=your_password
POSTGRES_DB=passkey_db
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}