Skip to content

muhammetekurt/AuthenticatorProject

Repository files navigation

Auth Service - Authentication Microservice

Modern, güvenli ve tüm uygulamalarınıza entegre edilebilir authentication microservice.

🚀 Özellikler

  • ✅ Email/Şifre ile kayıt ve giriş
  • ✅ Email OTP (şifresiz giriş)
  • ✅ Google ile giriş
  • ✅ Facebook ile giriş
  • ✅ JWT Token doğrulama API
  • ✅ CORS desteği
  • ✅ Modern ve responsive UI

📦 Kurulum

1. Paketleri Yükle

npm install

2. Firebase Projesini Ayarla

  1. Firebase Console'a git
  2. Yeni proje oluştur
  3. Authentication > Sign-in method'a git
  4. Email/Password, Google ve Facebook'u aktifleştir
  5. Project Settings > General > Your apps > Web app ekle
  6. Config değerlerini kopyala

3. Firebase Admin SDK

  1. Project Settings > Service Accounts
  2. "Generate new private key" tıkla
  3. JSON dosyasındaki değerleri .env.local'a ekle

4. Email Ayarları (OTP için)

Gmail kullanıyorsan:

  1. Google hesabında 2FA'yı aç
  2. App Passwords'a git
  3. Yeni uygulama şifresi oluştur
  4. .env.local'a ekle

5. Environment Variables

.env.local dosyasını düzenle:

# Firebase Client
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id

# Firebase Admin
FIREBASE_ADMIN_PROJECT_ID=your_project_id
FIREBASE_ADMIN_CLIENT_EMAIL=firebase-adminsdk-xxx@your_project.iam.gserviceaccount.com
FIREBASE_ADMIN_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"

# Email (Gmail için)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@gmail.com
EMAIL_PASSWORD=your_app_password

# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
API_SECRET_KEY=random_secret_key_here

# CORS
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001

6. Çalıştır

npm run dev

http://localhost:3000 adresini ziyaret et.

🔌 API Endpoints

Authentication

Endpoint Method Açıklama
/api/auth/register POST Email/şifre ile kayıt
/api/auth/login POST Firebase token ile giriş
/api/auth/google POST Google ile giriş
/api/auth/facebook POST Facebook ile giriş
/api/auth/send-otp POST Email OTP gönder
/api/auth/verify-otp POST OTP doğrula
/api/auth/verify-token POST Token doğrula (diğer servisler için)
/api/auth/logout POST Çıkış yap
/api/user GET Kullanıcı bilgisi
/api/user PUT Profil güncelle

Diğer Uygulamalardan Kullanım

// Token doğrulama
const response = await fetch('https://your-auth-service.com/api/auth/verify-token', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${userToken}`,
    'X-API-Key': 'your-api-key', // opsiyonel, ek bilgi için
  },
});

const { valid, user } = await response.json();

if (valid) {
  console.log('User:', user.uid, user.email);
} else {
  console.log('Invalid token');
}

Response Formatları

Başarılı Giriş:

{
  "success": true,
  "message": "Giriş başarılı",
  "user": {
    "uid": "abc123",
    "email": "user@example.com",
    "displayName": "John Doe",
    "photoURL": null,
    "emailVerified": true
  }
}

Token Doğrulama:

{
  "valid": true,
  "user": {
    "uid": "abc123",
    "email": "user@example.com",
    "name": "John Doe",
    "email_verified": true
  }
}

🏗️ Proje Yapısı

src/
├── app/
│   ├── api/
│   │   ├── auth/         # Auth endpoints
│   │   └── user/         # User endpoints
│   ├── (auth)/
│   │   ├── login/        # Login sayfası
│   │   └── register/     # Kayıt sayfası
│   └── page.tsx          # Ana sayfa
├── components/           # React componentleri
├── context/              # Auth context
├── lib/
│   ├── firebase/         # Firebase config
│   ├── email/            # Email servisi
│   └── cors.ts           # CORS helper
└── types/                # TypeScript types

🚀 Deploy

Vercel (Önerilen)

  1. GitHub'a push et
  2. Vercel'e git
  3. Projeyi import et
  4. Environment variables'ları ekle
  5. Deploy!

Docker

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]

📄 Lisans

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors