first commit
This commit is contained in:
275
ROUTES.md
Normal file
275
ROUTES.md
Normal file
@@ -0,0 +1,275 @@
|
||||
# 🔗 Next.js Routes - Email Link Configuration
|
||||
|
||||
Bu doküman, Django backend'de email template'lerinde kullanılması gereken Next.js route formatlarını içerir.
|
||||
|
||||
## 📧 Email Template URL Formatları
|
||||
|
||||
### ✅ Aktivasyon Email Linki
|
||||
|
||||
**Django Backend Email Template:**
|
||||
```python
|
||||
# Django settings veya email template'de:
|
||||
FRONTEND_URL = "http://localhost:3000" # Development
|
||||
# FRONTEND_URL = "https://yourdomain.com" # Production
|
||||
|
||||
# Email template'de kullanım:
|
||||
activation_url = f"{FRONTEND_URL}/activate/{uid}/{token}/"
|
||||
```
|
||||
|
||||
**Next.js Routes (Her ikisi de çalışır):**
|
||||
- ✅ `/activate/{uid}/{token}` - Django default format (ÖNERİLEN)
|
||||
- ✅ `/auth/activate/{uid}/{token}` - Next.js convention
|
||||
|
||||
**Örnek Link:**
|
||||
```
|
||||
http://localhost:3000/activate/Ng/d1aceh-398e275f6a6fa4b1de05846e9f2903aa/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### ✅ Şifre Sıfırlama Email Linki
|
||||
|
||||
**Django Backend Email Template:**
|
||||
```python
|
||||
# Email template'de kullanım:
|
||||
password_reset_url = f"{FRONTEND_URL}/password/reset/confirm/{uid}/{token}/"
|
||||
```
|
||||
|
||||
**Next.js Routes (Her ikisi de çalışır):**
|
||||
- ✅ `/password/reset/confirm/{uid}/{token}` - Django default format (ÖNERİLEN)
|
||||
- ✅ `/auth/password-reset/confirm/{uid}/{token}` - Next.js convention
|
||||
|
||||
**Örnek Link:**
|
||||
```
|
||||
http://localhost:3000/password/reset/confirm/Ng/d1aceh-398e275f6a6fa4b1de05846e9f2903aa/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🗺️ Tüm Next.js Rotaları
|
||||
|
||||
### Public Routes (Giriş Gerektirmez)
|
||||
|
||||
| Route | Açıklama | Kullanım |
|
||||
|-------|----------|----------|
|
||||
| `/` | Ana sayfa | Landing page |
|
||||
| `/auth/login` | Login sayfası | Kullanıcı girişi |
|
||||
| `/auth/register` | Kayıt sayfası | Yeni kullanıcı kaydı |
|
||||
| `/activate/{uid}/{token}` | Email aktivasyonu | Django email linki |
|
||||
| `/auth/activate/{uid}/{token}` | Email aktivasyonu (alternatif) | Manuel link |
|
||||
| `/auth/resend-activation` | Aktivasyon tekrar gönder | Kullanıcı isteği |
|
||||
| `/auth/password-reset` | Şifre sıfırlama talebi | Şifre unutma |
|
||||
| `/password/reset/confirm/{uid}/{token}` | Şifre sıfırlama onayı | Django email linki |
|
||||
| `/auth/password-reset/confirm/{uid}/{token}` | Şifre sıfırlama onayı (alternatif) | Manuel link |
|
||||
| `/auth/error` | Auth hata sayfası | NextAuth error callback |
|
||||
|
||||
### Protected Routes (Giriş Gerektirir)
|
||||
|
||||
| Route | Açıklama | Redirect |
|
||||
|-------|----------|----------|
|
||||
| `/dashboard` | Dashboard | → `/auth/login` |
|
||||
| `/profile` | Kullanıcı profili | → `/auth/login` |
|
||||
|
||||
### API Routes
|
||||
|
||||
| Route | Açıklama |
|
||||
|-------|----------|
|
||||
| `/api/auth/[...nextauth]` | NextAuth handler |
|
||||
| `/api/auth/signin` | NextAuth login |
|
||||
| `/api/auth/signout` | NextAuth logout |
|
||||
| `/api/auth/session` | Session info |
|
||||
| `/api/auth/callback/{provider}` | OAuth callback |
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Django Email Template Örnekleri
|
||||
|
||||
### Aktivasyon Email Template
|
||||
|
||||
```html
|
||||
<!-- templates/email/activation_email.html -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hesabınızı Aktifleştirin</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hoş Geldiniz!</h1>
|
||||
<p>Hesabınızı aktifleştirmek için aşağıdaki linke tıklayın:</p>
|
||||
|
||||
<a href="{{ protocol }}://{{ domain }}/activate/{{ uid }}/{{ token }}/">
|
||||
Hesabı Aktifleştir
|
||||
</a>
|
||||
|
||||
<p>Veya linki tarayıcınıza kopyalayın:</p>
|
||||
<p>{{ protocol }}://{{ domain }}/activate/{{ uid }}/{{ token }}/</p>
|
||||
|
||||
<p>Bu link 24 saat geçerlidir.</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### Şifre Sıfırlama Email Template
|
||||
|
||||
```html
|
||||
<!-- templates/email/password_reset_email.html -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Şifre Sıfırlama</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Şifre Sıfırlama Talebi</h1>
|
||||
<p>Şifrenizi sıfırlamak için aşağıdaki linke tıklayın:</p>
|
||||
|
||||
<a href="{{ protocol }}://{{ domain }}/password/reset/confirm/{{ uid }}/{{ token }}/">
|
||||
Şifreyi Sıfırla
|
||||
</a>
|
||||
|
||||
<p>Veya linki tarayıcınıza kopyalayın:</p>
|
||||
<p>{{ protocol }}://{{ domain }}/password/reset/confirm/{{ uid }}/{{ token }}/</p>
|
||||
|
||||
<p>Bu link 1 saat geçerlidir.</p>
|
||||
|
||||
<p><small>Bu talebi siz yapmadıysanız, bu emaili görmezden gelebilirsiniz.</small></p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Django Djoser Konfigürasyonu
|
||||
|
||||
```python
|
||||
# settings.py
|
||||
|
||||
DJOSER = {
|
||||
'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',
|
||||
'ACTIVATION_URL': 'activate/{uid}/{token}',
|
||||
'SEND_ACTIVATION_EMAIL': True,
|
||||
'SEND_CONFIRMATION_EMAIL': False,
|
||||
'PASSWORD_CHANGED_EMAIL_CONFIRMATION': False,
|
||||
'USERNAME_CHANGED_EMAIL_CONFIRMATION': False,
|
||||
'USER_CREATE_PASSWORD_RETYPE': True,
|
||||
'PASSWORD_RESET_CONFIRM_RETYPE': True,
|
||||
|
||||
# Email context
|
||||
'DOMAIN': 'localhost:3000', # Development
|
||||
# 'DOMAIN': 'yourdomain.com', # Production
|
||||
'SITE_NAME': 'Your App Name',
|
||||
'PROTOCOL': 'http', # Development
|
||||
# 'PROTOCOL': 'https', # Production
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🌍 Environment Variables
|
||||
|
||||
### Development (.env.local)
|
||||
|
||||
```env
|
||||
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000/api/v1
|
||||
NEXTAUTH_URL=http://localhost:3000
|
||||
```
|
||||
|
||||
### Production
|
||||
|
||||
```env
|
||||
NEXT_PUBLIC_API_BASE_URL=https://api.yourdomain.com/api/v1
|
||||
NEXTAUTH_URL=https://yourdomain.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Test Senaryosu
|
||||
|
||||
### 1. Aktivasyon Linki Test
|
||||
|
||||
```bash
|
||||
# Django'dan gönderilen email:
|
||||
http://localhost:3000/activate/Ng/d1aceh-398e275f6a6fa4b1de05846e9f2903aa/
|
||||
|
||||
# ✅ Next.js'te çalışır:
|
||||
/activate/[uid]/[token]/page.tsx
|
||||
|
||||
# ✅ Alternatif de çalışır:
|
||||
/auth/activate/[uid]/[token]/page.tsx
|
||||
```
|
||||
|
||||
### 2. Password Reset Linki Test
|
||||
|
||||
```bash
|
||||
# Django'dan gönderilen email:
|
||||
http://localhost:3000/password/reset/confirm/Ng/d1aceh-398e275f6a6fa4b1de05846e9f2903aa/
|
||||
|
||||
# ✅ Next.js'te çalışır:
|
||||
/password/reset/confirm/[uid]/[token]/page.tsx
|
||||
|
||||
# ✅ Alternatif de çalışır:
|
||||
/auth/password-reset/confirm/[uid]/[token]/page.tsx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 Notlar
|
||||
|
||||
### URL Format Esnekliği
|
||||
|
||||
Her iki format da destekleniyor:
|
||||
- **Django Default**: `/activate/{uid}/{token}` - Email template'lerde kullanım için
|
||||
- **Next.js Convention**: `/auth/activate/{uid}/{token}` - Manuel link paylaşımı için
|
||||
|
||||
### Trailing Slash
|
||||
|
||||
Django varsayılan olarak URL sonuna `/` ekler. Next.js her iki formatı da kabul eder:
|
||||
- ✅ `/activate/Ng/token/` (trailing slash ile)
|
||||
- ✅ `/activate/Ng/token` (trailing slash olmadan)
|
||||
|
||||
### Production Checklist
|
||||
|
||||
- [ ] Django `DJOSER['DOMAIN']` production URL'e güncellendi
|
||||
- [ ] Django `DJOSER['PROTOCOL']` = `'https'`
|
||||
- [ ] Next.js `NEXTAUTH_URL` production URL'e güncellendi
|
||||
- [ ] Email template'ler test edildi
|
||||
- [ ] Aktivasyon linki çalışıyor
|
||||
- [ ] Password reset linki çalışıyor
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Debugging
|
||||
|
||||
### Link 404 Hatası Veriyorsa
|
||||
|
||||
1. **URL formatını kontrol edin:**
|
||||
```bash
|
||||
# ✅ Doğru:
|
||||
/activate/Ng/d1aceh-398e275f6a6fa4b1de05846e9f2903aa
|
||||
|
||||
# ❌ Yanlış:
|
||||
/activate?uid=Ng&token=d1aceh-398e275f6a6fa4b1de05846e9f2903aa
|
||||
```
|
||||
|
||||
2. **Next.js route'ları kontrol edin:**
|
||||
```bash
|
||||
ls -la app/activate/[uid]/[token]/
|
||||
ls -la app/auth/activate/[uid]/[token]/
|
||||
ls -la app/password/reset/confirm/[uid]/[token]/
|
||||
ls -la app/auth/password-reset/confirm/[uid]/[token]/
|
||||
```
|
||||
|
||||
3. **Browser console'da hata var mı bakın**
|
||||
|
||||
4. **Django email template'i kontrol edin:**
|
||||
```python
|
||||
# settings.py veya email template
|
||||
ACTIVATION_URL = 'activate/{uid}/{token}' # ✅ Doğru
|
||||
# NOT: 'auth/activate/{uid}/{token}' # ❌ Gerekmiyor (ama çalışır)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Son Güncelleme**: 24 Aralık 2025
|
||||
**Version**: 1.0.0
|
||||
**Status**: ✅ Tested & Working
|
||||
|
||||
Reference in New Issue
Block a user