Skip to content

malik900/Emergency-QR

Repository files navigation

Emergency Data System

A comprehensive QR code-based emergency medical information system built with Next.js, Supabase, and TypeScript.

Features

Core Functionality

  • User Authentication - Secure email/password authentication with Supabase
  • Emergency Data Dashboard - Manage personal profile, emergency contacts, and medical information
  • QR Code Generation - Generate unique QR codes linking to emergency data pages
  • Public Emergency Pages - First responder-optimized pages displaying critical information
  • Scan Tracking - Monitor when and where your QR code is accessed

Security Features

  • Two-Factor Authentication (2FA) - TOTP-based 2FA with authenticator apps
  • Password-Protected Personal Data - Additional encryption layer for sensitive documents
  • Row Level Security (RLS) - Database-level security ensuring data privacy
  • Activity Logging - Comprehensive audit trail of all system actions

Advanced Features

  • Admin Panel - User management, analytics, and system monitoring
  • Multi-Language Support - English, Spanish, French, and German
  • Data Export - Export emergency data as HTML or CSV
  • Responsive Design - Optimized for mobile and desktop devices

Database Schema

The system uses the following main tables:

  • profiles - User profiles and preferences
  • emergency_contacts - Emergency contact information
  • medical_info - Critical health data (blood type, allergies, medications)
  • personal_data - Password-protected sensitive information
  • qr_codes - QR code records with scan tracking
  • qr_scans - Individual scan events
  • password_protection - Encrypted passwords for personal data
  • activity_log - System-wide audit trail

All tables have Row Level Security (RLS) enabled.

Getting Started

Prerequisites

  • Node.js 18+
  • Supabase account
  • npm or yarn

Installation

  1. Run the database migration scripts in order:

    • 001_create_schema.sql - Create tables and RLS policies
    • 002_create_profile_trigger.sql - Auto-create profiles on signup
    • 003_qr_scan_function.sql - QR scan tracking function
    • 004_create_first_admin.sql - Make first user an admin
  2. Environment variables are already configured via Supabase integration

  3. Start the development server and navigate to the app

First-Time Setup

  1. Create an account at /auth/sign-up
  2. Confirm your email address
  3. Run the admin script to make yourself an admin (optional)
  4. Complete your profile and emergency information
  5. Generate your QR code
  6. Download and print your QR code for wallet/keychain

Usage

For Users

  • Dashboard - Access at /dashboard to manage all information
  • QR Code - Generate and download from dashboard
  • Security - Enable 2FA at /dashboard/security
  • Personal Data - Access password-protected data at /dashboard/personal-data
  • Export - Download your data from security settings

For First Responders

  • Scan the QR code to access /public/[userId]
  • View critical medical information without login
  • Contact listed emergency contacts
  • Information is optimized for high-stress situations

For Admins

  • Admin Panel - Access at /admin
  • View all users and their data
  • Monitor system activity
  • Track QR code scans across the platform

Security Best Practices

  1. Enable 2FA - Adds critical extra security layer
  2. Strong Passwords - Use unique passwords for both account and personal data
  3. Regular Updates - Keep emergency contacts and medical info current
  4. Print QR Code - Keep physical copy in wallet
  5. Regular Exports - Download backups periodically

Technology Stack

  • Framework - Next.js 16 (App Router)
  • Database - Supabase (PostgreSQL)
  • Authentication - Supabase Auth with 2FA
  • Styling - Tailwind CSS v4
  • UI Components - shadcn/ui
  • QR Codes - qrcode library
  • 2FA - otplib
  • Password Hashing - bcryptjs

API Routes

  • POST /api/qr/generate - Generate QR code
  • POST /api/qr/scan - Record QR scan
  • POST /api/2fa/setup - Setup 2FA
  • POST /api/2fa/verify - Verify 2FA code
  • POST /api/2fa/disable - Disable 2FA
  • POST /api/personal-data/set-password - Set protection password
  • POST /api/personal-data/verify-password - Verify protection password
  • GET /api/personal-data/get-hint - Get password hint
  • GET /api/export/pdf - Export as HTML
  • GET /api/export/csv - Export as CSV
  • POST /api/admin/make-admin - Grant admin role

License

MIT

Support

For issues or questions, open a support ticket at vercel.com/help