Modern, güvenli ve tüm uygulamalarınıza entegre edilebilir authentication microservice.
- ✅ 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
npm install- Firebase Console'a git
- Yeni proje oluştur
- Authentication > Sign-in method'a git
- Email/Password, Google ve Facebook'u aktifleştir
- Project Settings > General > Your apps > Web app ekle
- Config değerlerini kopyala
- Project Settings > Service Accounts
- "Generate new private key" tıkla
- JSON dosyasındaki değerleri
.env.local'a ekle
Gmail kullanıyorsan:
- Google hesabında 2FA'yı aç
- App Passwords'a git
- Yeni uygulama şifresi oluştur
.env.local'a ekle
.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:3001npm run devhttp://localhost:3000 adresini ziyaret et.
| 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 |
// 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');
}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
}
}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
- GitHub'a push et
- Vercel'e git
- Projeyi import et
- Environment variables'ları ekle
- Deploy!
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]MIT