first commit
This commit is contained in:
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
README.md
|
||||||
|
.next
|
||||||
|
.git
|
||||||
|
.env
|
||||||
|
.DS_Store
|
||||||
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.*
|
||||||
|
.yarn/*
|
||||||
|
!.yarn/patches
|
||||||
|
!.yarn/plugins
|
||||||
|
!.yarn/releases
|
||||||
|
!.yarn/versions
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# env files (can opt-in for committing if needed)
|
||||||
|
.env*
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
10
.idea/.gitignore
generated
vendored
Normal file
10
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Ignored default folder with query files
|
||||||
|
/queries/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
6
.idea/copilot.data.migration.agent.xml
generated
Normal file
6
.idea/copilot.data.migration.agent.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AgentMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/copilot.data.migration.ask.xml
generated
Normal file
6
.idea/copilot.data.migration.ask.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AskMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/copilot.data.migration.ask2agent.xml
generated
Normal file
6
.idea/copilot.data.migration.ask2agent.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Ask2AgentMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/copilot.data.migration.edit.xml
generated
Normal file
6
.idea/copilot.data.migration.edit.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EditMigrationStateService">
|
||||||
|
<option name="migrationStatus" value="COMPLETED" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/next-go-blog.iml" filepath="$PROJECT_DIR$/.idea/next-go-blog.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
8
.idea/next-go-blog.iml
generated
Normal file
8
.idea/next-go-blog.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"nuxt.isNuxtApp": false
|
||||||
|
}
|
||||||
171
AGENTS.md
Normal file
171
AGENTS.md
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
# Genimi (AI) Kuralları
|
||||||
|
- **Dil:** Her zaman (kod blokları hariç) Türkçe cevap vermelisin.
|
||||||
|
|
||||||
|
# Go Backend Guidelines — JWT + OAuth + RBAC & Security
|
||||||
|
# Go Next Js Guidelines
|
||||||
|
Bu doküman Next frontend'e hizmet edecek Go (backend) uygulaması için güncel proje ve mimari rehberidir.
|
||||||
|
|
||||||
|
## Proje Backend Durumu ve Özellikler
|
||||||
|
|
||||||
|
- **Go Sürümü:** 1.25.6
|
||||||
|
- **Veritabanı:** PostgreSQL
|
||||||
|
- **Web Framework:** Gin
|
||||||
|
- **Mimari:** RESTful API
|
||||||
|
|
||||||
|
## Proje Frontend Durumu ve Özellikler
|
||||||
|
|
||||||
|
- **Next js:** 16.1.6
|
||||||
|
- **Next-auth":** 4.24.13
|
||||||
|
- **Radix-ui":** 1.4.3
|
||||||
|
- **Shadcn/ui":** Latest
|
||||||
|
- **Sweetalert2":** 11.26.18
|
||||||
|
- **Ioredis":** 5.9.2
|
||||||
|
- **Redux":** 1.4.3
|
||||||
|
- **Redux Toolkit":** 1.4.3
|
||||||
|
- **Zod":** 4.3.6
|
||||||
|
- **Tailwindcss":** 4
|
||||||
|
- **Tailwind-merge":** 3.4.0
|
||||||
|
- **Lucide-react":** 0.563.0
|
||||||
|
- **Tw-animate-css":** 1.4.0
|
||||||
|
- **server side rendering:** true
|
||||||
|
|
||||||
|
## API Uç Noktaları
|
||||||
|
|
||||||
|
-- Register Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/register
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**",
|
||||||
|
"username":"test yaptim"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJwZXJtaXNzaW9ucyI6WyJ1c2VyOnJlYWQiXSwiaXNzIjoiZ2F1dGgtY2VudHJhbCIsImV4cCI6MTc3MDEzMDQ2OCwiaWF0IjoxNzcwMTI5NTY4fQ.Qc5EnE2r-In7hm6-NjP6WX2TKm3MyuM68SwsHYUNJbI",
|
||||||
|
"email": "bexysshanod@beyhan.dev",
|
||||||
|
"message": "User created successfully",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwNzM0MzY4LCJpYXQiOjE3NzAxMjk1Njh9.JE2UZ6jJti2N2jbExx_TTY5VPSfXKvc2ZGB-Nw_toLQ",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "f05ee74f-ab83-4171-b277-fdc446a607b7",
|
||||||
|
"username": "test yaptim"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Login Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/login
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMwNjU3LCJpYXQiOjE3NzAxMjk3NTd9.QbsRFn5fr7L4Wc7HCxOs0_zOWWhuceWzPmt20TV5lNI",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ1NTcsImlhdCI6MTc3MDEyOTc1N30.wBML1pT9S9i9FtAw3PKmJBMdcobZexWVBTRV5remb_s",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Refresh Token
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/refresh
|
||||||
|
-- Gönderilen JSON
|
||||||
|
{
|
||||||
|
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ2NDUsImlhdCI6MTc3MDEyOTg0NX0.ACDDM20v1u6yjyNrqBnWafjXnrRAAT1-8CvfqSkjTsE"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMxMjYwLCJpYXQiOjE3NzAxMzAzNjB9.BKmZBkL6FPo208mYLeBFMkNOqJ2tsmGXJUN_0bdZFHQ",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzUxNjAsImlhdCI6MTc3MDEzMDM2MH0.tkpcbQ6QmVVXK-r0QgP333X_FrAktVOuh1AJhwvV1BQ"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Me (Kullanıcı Profili)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/me
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"created_at": "2026-02-03T17:03:07.863425+03:00",
|
||||||
|
"updated_at": "2026-02-03T17:03:07.880923+03:00",
|
||||||
|
"social_accounts": null,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Validate Token (Token Doğrulama)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/validate
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği, body gönderilmez)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"message": "Token is valid",
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373"
|
||||||
|
}
|
||||||
|
## Kurulum ve Çalıştırma
|
||||||
|
|
||||||
|
1. `.env.example` dosyasını `.env` olarak kopyalayın ve değerleri düzenleyin.
|
||||||
|
2. Docker ile veritabanını ve uygulamayı başlatmak için:
|
||||||
|
```bash
|
||||||
|
./scripts/run.sh
|
||||||
|
```
|
||||||
|
_(Bu script Docker konteynerini kontrol eder, yoksa başlatır ve ardından Go sunucusunu çalıştırır)_
|
||||||
|
|
||||||
|
## Geliştirme Notları
|
||||||
|
|
||||||
|
- **Env Değişkenleri:**
|
||||||
|
- `RATE_LIMIT_BLACKLIST_IPS=...`, `RATE_LIMIT_BLACKLIST_DOMAINS=...` ile yasaklama.
|
||||||
|
- `RATE_LIMIT_WHITELIST=...`, `RATE_LIMIT_WHITELIST_DOMAINS=...` ile muafiyet.
|
||||||
|
|
||||||
|
- **Migration Ekleme:** `internal/db/migrations` klasörüne `00000X_description.up.sql` formatında yeni dosya ekleyin.
|
||||||
|
- **Admin Kullanıcısı:** Sistem ilk açılışta `admin@example.com` / `admin123` kullanıcısını otomatik oluşturur.
|
||||||
|
- **Docker Volume:** `/uploads` klasörü `uploads_data` volume'ü ile kalıcı hale getirilmiştir.
|
||||||
|
- **Image Processing:** WebP desteği için Dockerfile `CGO_ENABLED=1` ve `build-base` içerir.
|
||||||
223
BACKEND_ENDPOINT.mb
Normal file
223
BACKEND_ENDPOINT.mb
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
-- Register Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/register
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**",
|
||||||
|
"username":"test yaptim"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJwZXJtaXNzaW9ucyI6WyJ1c2VyOnJlYWQiXSwiaXNzIjoiZ2F1dGgtY2VudHJhbCIsImV4cCI6MTc3MDEzMDQ2OCwiaWF0IjoxNzcwMTI5NTY4fQ.Qc5EnE2r-In7hm6-NjP6WX2TKm3MyuM68SwsHYUNJbI",
|
||||||
|
"email": "bexysshanod@beyhan.dev",
|
||||||
|
"message": "User created successfully",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwNzM0MzY4LCJpYXQiOjE3NzAxMjk1Njh9.JE2UZ6jJti2N2jbExx_TTY5VPSfXKvc2ZGB-Nw_toLQ",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "f05ee74f-ab83-4171-b277-fdc446a607b7",
|
||||||
|
"username": "test yaptim"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Login Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/login
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMwNjU3LCJpYXQiOjE3NzAxMjk3NTd9.QbsRFn5fr7L4Wc7HCxOs0_zOWWhuceWzPmt20TV5lNI",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ1NTcsImlhdCI6MTc3MDEyOTc1N30.wBML1pT9S9i9FtAw3PKmJBMdcobZexWVBTRV5remb_s",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Refresh Token
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/refresh
|
||||||
|
-- Gönderilen JSON
|
||||||
|
{
|
||||||
|
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ2NDUsImlhdCI6MTc3MDEyOTg0NX0.ACDDM20v1u6yjyNrqBnWafjXnrRAAT1-8CvfqSkjTsE"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMxMjYwLCJpYXQiOjE3NzAxMzAzNjB9.BKmZBkL6FPo208mYLeBFMkNOqJ2tsmGXJUN_0bdZFHQ",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzUxNjAsImlhdCI6MTc3MDEzMDM2MH0.tkpcbQ6QmVVXK-r0QgP333X_FrAktVOuh1AJhwvV1BQ"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Me (Kullanıcı Profili)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/me
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"created_at": "2026-02-03T17:03:07.863425+03:00",
|
||||||
|
"updated_at": "2026-02-03T17:03:07.880923+03:00",
|
||||||
|
"social_accounts": null,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Validate Token (Token Doğrulama)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/validate
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği, body gönderilmez)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"message": "Token is valid",
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- userlist admin
|
||||||
|
{
|
||||||
|
"pagination": {
|
||||||
|
"limit": 10,
|
||||||
|
"page": 1,
|
||||||
|
"total": 5,
|
||||||
|
"totalPages": 1
|
||||||
|
},
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"id": "d056c1fd-4f99-42ab-bad9-0f205555a872",
|
||||||
|
"username": "ares2000@gmail.com",
|
||||||
|
"email": "zxczxcc@sdfsdf.com",
|
||||||
|
"avatar": "/uploads/avatars/d056c1fd-4f99-42ab-bad9-0f205555a872_1770180464146441000.png",
|
||||||
|
"created_at": "2026-02-04T07:47:44.100874+03:00",
|
||||||
|
"updated_at": "2026-02-04T07:47:44.148572+03:00",
|
||||||
|
"email_verified": true,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fbfdfb16-3ffa-423a-9914-b1624aab2ddb",
|
||||||
|
"username": "adsssssmin@demo.com",
|
||||||
|
"email": "xxxxxadmin@demo.com",
|
||||||
|
"avatar": "/uploads/avatars/fbfdfb16-3ffa-423a-9914-b1624aab2ddb_1770179925659471000.png",
|
||||||
|
"created_at": "2026-02-04T07:38:45.618572+03:00",
|
||||||
|
"updated_at": "2026-02-04T07:44:54.318372+03:00",
|
||||||
|
"email_verified": true,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4f177189-7c96-48cd-825d-4e9a5a76421a",
|
||||||
|
"username": "admin@demo.com",
|
||||||
|
"email": "admin@demo.com",
|
||||||
|
"avatar": "/uploads/avatars/4f177189-7c96-48cd-825d-4e9a5a76421a_1770180623694066000.png",
|
||||||
|
"created_at": "2026-02-04T07:37:17.716058+03:00",
|
||||||
|
"updated_at": "2026-02-04T07:50:23.696197+03:00",
|
||||||
|
"email_verified": true,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4971553b-99da-432c-99a8-28ef172cb139",
|
||||||
|
"username": "Beyhan Oğur",
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"avatar": "/uploads/avatars/4971553b-99da-432c-99a8-28ef172cb139_1770181055825103000.png",
|
||||||
|
"created_at": "2026-02-04T06:05:17.334092+03:00",
|
||||||
|
"updated_at": "2026-02-04T07:57:35.826692+03:00",
|
||||||
|
"email_verified": true,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "admin",
|
||||||
|
"description": "Default admin role",
|
||||||
|
"permissions": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "2503e3d9-3ff5-4e4a-97af-b23ac37f37db",
|
||||||
|
"username": "admin",
|
||||||
|
"email": "admin@gauth.local",
|
||||||
|
"avatar": "/uploads/avatars/2503e3d9-3ff5-4e4a-97af-b23ac37f37db_1770181222075819000.png",
|
||||||
|
"created_at": "2026-02-04T06:04:40.83783+03:00",
|
||||||
|
"updated_at": "2026-02-04T08:00:22.077544+03:00",
|
||||||
|
"email_verified": true,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "admin",
|
||||||
|
"description": "Default admin role",
|
||||||
|
"permissions": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
620
CORS_API_DOCUMENTATION.md
Normal file
620
CORS_API_DOCUMENTATION.md
Normal file
@@ -0,0 +1,620 @@
|
|||||||
|
# CORS Whitelist & Blacklist API Dokümantasyonu
|
||||||
|
|
||||||
|
## 📋 Genel Bakış
|
||||||
|
|
||||||
|
AuthCentral'da CORS (Cross-Origin Resource Sharing) yönetimi için Whitelist ve Blacklist sistemleri mevcuttur.
|
||||||
|
|
||||||
|
### Özellikler:
|
||||||
|
- ✅ CRUD operasyonları (Create, Read, Update, Delete)
|
||||||
|
- ✅ Redis cache desteği
|
||||||
|
- ✅ Admin only endpoints
|
||||||
|
- ✅ Active/Inactive durumları
|
||||||
|
- ✅ Audit trail (created_by, updated_by)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔐 Authentication
|
||||||
|
|
||||||
|
Tüm endpoint'ler **Admin** yetkisi gerektirir:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {admin_access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📡 CORS Whitelist API
|
||||||
|
|
||||||
|
### 1. Tüm Whitelist Kayıtlarını Listele
|
||||||
|
|
||||||
|
```http
|
||||||
|
GET /v1/settings/cors/whitelist
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Yanıt:**
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "http://localhost:3000",
|
||||||
|
"description": "Development frontend",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "admin@gauth.local",
|
||||||
|
"created_at": "2026-02-05T10:00:00Z",
|
||||||
|
"updated_at": "2026-02-05T10:00:00Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "https://myapp.com",
|
||||||
|
"description": "Production frontend",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "admin@gauth.local",
|
||||||
|
"created_at": "2026-02-05T09:00:00Z",
|
||||||
|
"updated_at": "2026-02-05T09:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Whitelist Kaydı Oluştur
|
||||||
|
|
||||||
|
```http
|
||||||
|
POST /v1/settings/cors/whitelist
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "https://example.com",
|
||||||
|
"description": "Customer frontend application"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt (201):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "new-uuid",
|
||||||
|
"origin": "https://example.com",
|
||||||
|
"description": "Customer frontend application",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "admin@gauth.local",
|
||||||
|
"created_at": "2026-02-05T11:00:00Z",
|
||||||
|
"updated_at": "2026-02-05T11:00:00Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Whitelist Kaydını Güncelle
|
||||||
|
|
||||||
|
```http
|
||||||
|
PUT /v1/settings/cors/whitelist/{id}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body (tüm alanlar opsiyonel):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "https://new-domain.com",
|
||||||
|
"description": "Updated description",
|
||||||
|
"is_active": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Whitelist updated successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Whitelist Kaydını Sil
|
||||||
|
|
||||||
|
```http
|
||||||
|
DELETE /v1/settings/cors/whitelist/{id}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Whitelist entry deleted successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚫 CORS Blacklist API
|
||||||
|
|
||||||
|
### 1. Tüm Blacklist Kayıtlarını Listele
|
||||||
|
|
||||||
|
```http
|
||||||
|
GET /v1/settings/cors/blacklist
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Yanıt:**
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "https://malicious-site.com",
|
||||||
|
"reason": "Security threat detected",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "admin@gauth.local",
|
||||||
|
"created_at": "2026-02-05T10:00:00Z",
|
||||||
|
"updated_at": "2026-02-05T10:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Blacklist Kaydı Oluştur
|
||||||
|
|
||||||
|
```http
|
||||||
|
POST /v1/settings/cors/blacklist
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "https://spam-domain.com",
|
||||||
|
"reason": "Spam attempts detected"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt (201):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "new-uuid",
|
||||||
|
"origin": "https://spam-domain.com",
|
||||||
|
"reason": "Spam attempts detected",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "admin@gauth.local",
|
||||||
|
"created_at": "2026-02-05T11:00:00Z",
|
||||||
|
"updated_at": "2026-02-05T11:00:00Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Blacklist Kaydını Güncelle
|
||||||
|
|
||||||
|
```http
|
||||||
|
PUT /v1/settings/cors/blacklist/{id}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Body (tüm alanlar opsiyonel):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "https://updated-domain.com",
|
||||||
|
"reason": "Updated reason",
|
||||||
|
"is_active": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Blacklist updated successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Blacklist Kaydını Sil
|
||||||
|
|
||||||
|
```http
|
||||||
|
DELETE /v1/settings/cors/blacklist/{id}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
```
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Blacklist entry deleted successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 Kullanım Örnekleri
|
||||||
|
|
||||||
|
### Tam İş Akışı (cURL)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 1. Admin Login
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
echo "Token: ${TOKEN:0:30}..."
|
||||||
|
|
||||||
|
# 2. Whitelist'e domain ekle
|
||||||
|
echo -e "\n=== Create Whitelist Entry ==="
|
||||||
|
curl -X POST http://localhost:8080/v1/settings/cors/whitelist \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"origin": "https://myapp.com",
|
||||||
|
"description": "Production app"
|
||||||
|
}' | jq .
|
||||||
|
|
||||||
|
# 3. Tüm whitelist'i listele
|
||||||
|
echo -e "\n=== List All Whitelist ==="
|
||||||
|
curl -X GET http://localhost:8080/v1/settings/cors/whitelist \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq .
|
||||||
|
|
||||||
|
# 4. Blacklist'e domain ekle
|
||||||
|
echo -e "\n=== Create Blacklist Entry ==="
|
||||||
|
curl -X POST http://localhost:8080/v1/settings/cors/blacklist \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"origin": "https://spam.com",
|
||||||
|
"reason": "Spam detected"
|
||||||
|
}' | jq .
|
||||||
|
|
||||||
|
# 5. Whitelist entry'yi güncelle (ID'yi yukarıdaki response'dan alın)
|
||||||
|
WHITELIST_ID="your-whitelist-id-here"
|
||||||
|
echo -e "\n=== Update Whitelist Entry ==="
|
||||||
|
curl -X PUT "http://localhost:8080/v1/settings/cors/whitelist/$WHITELIST_ID" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"description": "Updated description",
|
||||||
|
"is_active": true
|
||||||
|
}' | jq .
|
||||||
|
|
||||||
|
# 6. Blacklist entry'yi sil
|
||||||
|
BLACKLIST_ID="your-blacklist-id-here"
|
||||||
|
echo -e "\n=== Delete Blacklist Entry ==="
|
||||||
|
curl -X DELETE "http://localhost:8080/v1/settings/cors/blacklist/$BLACKLIST_ID" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq .
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 Frontend Entegrasyonu (React)
|
||||||
|
|
||||||
|
### API Client
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
class CorsSettingsAPI {
|
||||||
|
constructor(baseURL, token) {
|
||||||
|
this.baseURL = baseURL;
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====== Whitelist ======
|
||||||
|
|
||||||
|
async getWhitelist() {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/whitelist`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async createWhitelist(origin, description) {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/whitelist`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ origin, description })
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateWhitelist(id, updates) {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/whitelist/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(updates)
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteWhitelist(id) {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/whitelist/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====== Blacklist ======
|
||||||
|
|
||||||
|
async getBlacklist() {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/blacklist`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async createBlacklist(origin, reason) {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/blacklist`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ origin, reason })
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateBlacklist(id, updates) {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/blacklist/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(updates)
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteBlacklist(id) {
|
||||||
|
const response = await fetch(`${this.baseURL}/v1/settings/cors/blacklist/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kullanım
|
||||||
|
const api = new CorsSettingsAPI('http://localhost:8080', YOUR_ADMIN_TOKEN);
|
||||||
|
|
||||||
|
// Whitelist listele
|
||||||
|
const whitelists = await api.getWhitelist();
|
||||||
|
console.log(whitelists);
|
||||||
|
|
||||||
|
// Yeni whitelist ekle
|
||||||
|
const newEntry = await api.createWhitelist('https://newapp.com', 'New application');
|
||||||
|
console.log(newEntry);
|
||||||
|
```
|
||||||
|
|
||||||
|
### React Component Örneği
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
function CorsWhitelistManager() {
|
||||||
|
const [whitelists, setWhitelists] = useState([]);
|
||||||
|
const [newOrigin, setNewOrigin] = useState('');
|
||||||
|
const [newDescription, setNewDescription] = useState('');
|
||||||
|
const token = localStorage.getItem('admin_token');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchWhitelists();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const fetchWhitelists = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/settings/cors/whitelist', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
setWhitelists(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching whitelists:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCreate = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/settings/cors/whitelist', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
origin: newOrigin,
|
||||||
|
description: newDescription
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
setNewOrigin('');
|
||||||
|
setNewDescription('');
|
||||||
|
fetchWhitelists(); // Refresh list
|
||||||
|
alert('Whitelist entry created!');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error creating whitelist:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async (id) => {
|
||||||
|
if (!confirm('Are you sure you want to delete this entry?')) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`http://localhost:8080/v1/settings/cors/whitelist/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
fetchWhitelists(); // Refresh list
|
||||||
|
alert('Whitelist entry deleted!');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting whitelist:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleActive = async (id, currentStatus) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`http://localhost:8080/v1/settings/cors/whitelist/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
is_active: !currentStatus
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
fetchWhitelists(); // Refresh list
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating whitelist:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="cors-whitelist-manager">
|
||||||
|
<h2>CORS Whitelist Manager</h2>
|
||||||
|
|
||||||
|
{/* Add New Entry Form */}
|
||||||
|
<form onSubmit={handleCreate} className="add-form">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Origin (e.g., https://example.com)"
|
||||||
|
value={newOrigin}
|
||||||
|
onChange={(e) => setNewOrigin(e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Description"
|
||||||
|
value={newDescription}
|
||||||
|
onChange={(e) => setNewDescription(e.target.value)}
|
||||||
|
/>
|
||||||
|
<button type="submit">Add to Whitelist</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* Whitelist Table */}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Origin</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Active</th>
|
||||||
|
<th>Created By</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{whitelists.map(entry => (
|
||||||
|
<tr key={entry.id}>
|
||||||
|
<td>{entry.origin}</td>
|
||||||
|
<td>{entry.description}</td>
|
||||||
|
<td>
|
||||||
|
<button onClick={() => toggleActive(entry.id, entry.is_active)}>
|
||||||
|
{entry.is_active ? '✅ Active' : '❌ Inactive'}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
<td>{entry.created_by}</td>
|
||||||
|
<td>
|
||||||
|
<button onClick={() => handleDelete(entry.id)}>Delete</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CorsWhitelistManager;
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 API Endpoints Özeti
|
||||||
|
|
||||||
|
| Endpoint | Method | Açıklama | Admin Required |
|
||||||
|
|----------|--------|----------|----------------|
|
||||||
|
| `/v1/settings/cors/whitelist` | GET | Whitelist listele | ✅ |
|
||||||
|
| `/v1/settings/cors/whitelist` | POST | Whitelist ekle | ✅ |
|
||||||
|
| `/v1/settings/cors/whitelist/:id` | PUT | Whitelist güncelle | ✅ |
|
||||||
|
| `/v1/settings/cors/whitelist/:id` | DELETE | Whitelist sil | ✅ |
|
||||||
|
| `/v1/settings/cors/blacklist` | GET | Blacklist listele | ✅ |
|
||||||
|
| `/v1/settings/cors/blacklist` | POST | Blacklist ekle | ✅ |
|
||||||
|
| `/v1/settings/cors/blacklist/:id` | PUT | Blacklist güncelle | ✅ |
|
||||||
|
| `/v1/settings/cors/blacklist/:id` | DELETE | Blacklist sil | ✅ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Cache Yönetimi
|
||||||
|
|
||||||
|
CORS ayarları Redis'te cache'lenir:
|
||||||
|
- **Cache süresi:** 1 saat
|
||||||
|
- **Otomatik invalidation:** Create/Update/Delete işlemlerinde
|
||||||
|
- **Cache key:**
|
||||||
|
- Whitelist: `cors:whitelist`
|
||||||
|
- Blacklist: `cors:blacklist`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Test Checklist
|
||||||
|
|
||||||
|
- [ ] Admin token alındı
|
||||||
|
- [ ] Whitelist ekleme testi
|
||||||
|
- [ ] Whitelist listeleme testi
|
||||||
|
- [ ] Whitelist güncelleme testi
|
||||||
|
- [ ] Whitelist silme testi
|
||||||
|
- [ ] Blacklist ekleme testi
|
||||||
|
- [ ] Blacklist listeleme testi
|
||||||
|
- [ ] Blacklist güncelleme testi
|
||||||
|
- [ ] Blacklist silme testi
|
||||||
|
- [ ] Swagger dokümantasyonu kontrol edildi
|
||||||
|
|
||||||
|
**CORS Whitelist & Blacklist API'leri tam çalışır durumda!** 🚀
|
||||||
70
Dockerfile
Normal file
70
Dockerfile
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Base image
|
||||||
|
FROM node:23-alpine AS base
|
||||||
|
|
||||||
|
# Install dependencies only when needed
|
||||||
|
FROM base AS deps
|
||||||
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install dependencies based on the preferred package manager
|
||||||
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
||||||
|
else echo "Lockfile not found." && exit 1; fi
|
||||||
|
|
||||||
|
|
||||||
|
# Rebuild the source code only when needed
|
||||||
|
FROM base AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
|
ARG NEXT_PUBLIC_API_BASE
|
||||||
|
ENV NEXT_PUBLIC_API_BASE=$NEXT_PUBLIC_API_BASE
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
if [ -f yarn.lock ]; then yarn run build; \
|
||||||
|
elif [ -f package-lock.json ]; then npm run build; \
|
||||||
|
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||||
|
else echo "Lockfile not found." && exit 1; fi
|
||||||
|
|
||||||
|
# Production image, copy all the files and run next
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV production
|
||||||
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||||
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
|
# User and Group creation
|
||||||
|
RUN addgroup --system --gid 1001 nodejs
|
||||||
|
RUN adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
# Automatically leverage output traces to reduce image size
|
||||||
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENV PORT 3000
|
||||||
|
|
||||||
|
# Set hostname to localhost by default, but allow overwriting.
|
||||||
|
# For Docker, 0.0.0.0 is needed to accept connections from outside the container
|
||||||
|
ENV HOSTNAME "0.0.0.0"
|
||||||
|
|
||||||
|
# server.js is created by next build from the standalone output
|
||||||
|
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
||||||
|
CMD ["node", "server.js"]
|
||||||
236
EMAIL_VERIFICATION.md
Normal file
236
EMAIL_VERIFICATION.md
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
# Email Doğrulama Sistemi
|
||||||
|
|
||||||
|
## Genel Bakış
|
||||||
|
|
||||||
|
AuthCentral'da kullanıcılar iki şekilde kayıt olabilir:
|
||||||
|
|
||||||
|
1. **Email/Password ile Kayıt**: Email doğrulaması gerektirir
|
||||||
|
2. **OAuth (Google/GitHub)**: Otomatik olarak doğrulanmış kabul edilir
|
||||||
|
|
||||||
|
## Email/Password ile Kayıt Akışı
|
||||||
|
|
||||||
|
### 1. Kullanıcı Kaydı
|
||||||
|
```bash
|
||||||
|
POST /v1/auth/register
|
||||||
|
{
|
||||||
|
"username": "johndoe",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"password": "securepass123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "User created. Please verify your email.",
|
||||||
|
"user_id": "...",
|
||||||
|
"username": "johndoe",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"email_verified": false,
|
||||||
|
"verification_token": "..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Not:** Kullanıcı oluşturulur ancak `email_verified: false` olarak ayarlanır.
|
||||||
|
|
||||||
|
### 2. Email Doğrulama
|
||||||
|
|
||||||
|
Kullanıcıya otomatik olarak doğrulama email'i gönderilir. Email'deki linke tıklayarak doğrulama yapılır:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /v1/auth/verify-email?token=VERIFICATION_TOKEN
|
||||||
|
```
|
||||||
|
|
||||||
|
**Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Email verified successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Login Denemesi (Email Doğrulanmadan)
|
||||||
|
|
||||||
|
Email doğrulanmadan login yapılamaz:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
POST /v1/auth/login
|
||||||
|
{
|
||||||
|
"email": "john@example.com",
|
||||||
|
"password": "securepass123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hata Yanıtı:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "email not verified"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Login (Email Doğrulandıktan Sonra)
|
||||||
|
|
||||||
|
Email doğrulandıktan sonra başarıyla login yapılabilir:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
POST /v1/auth/login
|
||||||
|
{
|
||||||
|
"email": "john@example.com",
|
||||||
|
"password": "securepass123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "...",
|
||||||
|
"refresh_token": "...",
|
||||||
|
"user_id": "...",
|
||||||
|
"username": "johndoe",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"avatar": "",
|
||||||
|
"roles": [...]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## OAuth (Google/GitHub) ile Kayıt
|
||||||
|
|
||||||
|
OAuth sağlayıcıları email'i zaten doğruladığı için, bu kullanıcılar otomatik olarak `email_verified: true` olarak kaydedilir.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /v1/auth/google
|
||||||
|
GET /v1/auth/github
|
||||||
|
```
|
||||||
|
|
||||||
|
OAuth callback'ten sonra kullanıcı otomatik olarak login edilir ve token'lar döndürülür.
|
||||||
|
|
||||||
|
## Veritabanı Yapısı
|
||||||
|
|
||||||
|
### Users Tablosu
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TABLE users (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
user_name TEXT NOT NULL,
|
||||||
|
email VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
password TEXT,
|
||||||
|
avatar VARCHAR(500),
|
||||||
|
email_verified BOOLEAN DEFAULT false,
|
||||||
|
email_verify_token TEXT,
|
||||||
|
email_verified_at TIMESTAMP,
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP,
|
||||||
|
deleted_at TIMESTAMP -- Soft delete için
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Email Verification Alanları
|
||||||
|
|
||||||
|
- `email_verified`: Boolean - Email doğrulandı mı? (Email/password için false, OAuth için true)
|
||||||
|
- `email_verify_token`: String - Doğrulama token'ı (email/password kayıt için)
|
||||||
|
- `email_verified_at`: Timestamp - Email ne zaman doğrulandı?
|
||||||
|
|
||||||
|
## Admin Kullanıcı Yönetimi
|
||||||
|
|
||||||
|
### Kullanıcı Silme
|
||||||
|
|
||||||
|
#### Soft Delete (Varsayılan)
|
||||||
|
```bash
|
||||||
|
DELETE /v1/admin/users/{user_id}
|
||||||
|
```
|
||||||
|
|
||||||
|
Kullanıcı `deleted_at` timestamp'i ile işaretlenir, veritabanından silinmez.
|
||||||
|
|
||||||
|
#### Hard Delete (Kalıcı Silme)
|
||||||
|
```bash
|
||||||
|
DELETE /v1/admin/users/{user_id}?hard=true
|
||||||
|
```
|
||||||
|
|
||||||
|
Kullanıcı ve tüm ilişkili kayıtları (user_roles, social_accounts) kalıcı olarak silinir.
|
||||||
|
|
||||||
|
**Not:** Kendi hesabınızı silemezsiniz.
|
||||||
|
|
||||||
|
## Email Ayarları
|
||||||
|
|
||||||
|
Email gönderimi için `.env` dosyasındaki ayarları yapılandırın:
|
||||||
|
|
||||||
|
```env
|
||||||
|
# Email Settings (Mailpit - Development)
|
||||||
|
EMAIL_HOST=212.64.215.243
|
||||||
|
EMAIL_PORT=1025
|
||||||
|
EMAIL_HOST_USER=""
|
||||||
|
EMAIL_HOST_PASSWORD=""
|
||||||
|
EMAIL_USE_TLS=false
|
||||||
|
EMAIL_USE_SSL=false
|
||||||
|
EMAIL_FROM=noreply@gauth.local
|
||||||
|
```
|
||||||
|
|
||||||
|
## Güvenlik Notları
|
||||||
|
|
||||||
|
1. **Verification Token**: 32 byte güvenli rastgele token oluşturulur
|
||||||
|
2. **Token Süresi**: Şu anda token'ların süresi dolmuyor (ileride eklenebilir)
|
||||||
|
3. **Rate Limiting**: Register endpoint'i için rate limit aktif
|
||||||
|
4. **Password Hashing**: bcrypt kullanılarak güvenli şekilde hash'lenir
|
||||||
|
|
||||||
|
## Geliştirme Notları
|
||||||
|
|
||||||
|
### Migration
|
||||||
|
|
||||||
|
Email verification özelliği sonradan eklendiği için, mevcut kullanıcılar otomatik olarak `email_verified: true` olarak işaretlenmiştir. Yeni kayıtlar `email_verified: false` ile başlar.
|
||||||
|
|
||||||
|
Migration fonksiyonu `internal/database/db.go` dosyasında devre dışı bırakılmıştır.
|
||||||
|
|
||||||
|
### Model Değişiklikleri
|
||||||
|
|
||||||
|
User model'de `EmailVerified` alanı `*bool` (pointer) olarak tanımlanmıştır. Bu, GORM'un false değerlerini doğru şekilde işlemesini sağlar.
|
||||||
|
|
||||||
|
```go
|
||||||
|
type User struct {
|
||||||
|
// ...
|
||||||
|
EmailVerified *bool `gorm:"default:false" json:"email_verified"`
|
||||||
|
EmailVerifyToken string `gorm:"index" json:"-"`
|
||||||
|
EmailVerifiedAt *time.Time `json:"email_verified_at,omitempty"`
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test Senaryosu
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Yeni kullanıcı kaydı
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"username": "testuser",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# 2. Email doğrulanmadan login dene (BAŞARISIZ)
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123"
|
||||||
|
}'
|
||||||
|
# Yanıt: {"error": "email not verified"}
|
||||||
|
|
||||||
|
# 3. Email'i doğrula
|
||||||
|
curl -X GET "http://localhost:8080/v1/auth/verify-email?token=VERIFICATION_TOKEN"
|
||||||
|
|
||||||
|
# 4. Login (BAŞARILI)
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123"
|
||||||
|
}'
|
||||||
|
# Yanıt: access_token, refresh_token, user bilgileri
|
||||||
|
```
|
||||||
|
|
||||||
|
## Özet
|
||||||
|
|
||||||
|
✅ Email/password ile kayıt olanlar email doğrulaması yapmalı
|
||||||
|
✅ Email doğrulanmadan login yapılamaz
|
||||||
|
✅ OAuth ile giriş yapanlar otomatik doğrulanmış kabul edilir
|
||||||
|
✅ Soft delete varsayılan, hard delete `?hard=true` ile yapılır
|
||||||
|
✅ Email doğrulama sistemi tam çalışır durumda
|
||||||
171
GEMINI.md
Normal file
171
GEMINI.md
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
# Genimi (AI) Kuralları
|
||||||
|
- **Dil:** Her zaman (kod blokları hariç) Türkçe cevap vermelisin.
|
||||||
|
|
||||||
|
# Go Backend Guidelines — JWT + OAuth + RBAC & Security
|
||||||
|
# Go Next Js Guidelines
|
||||||
|
Bu doküman Next frontend'e hizmet edecek Go (backend) uygulaması için güncel proje ve mimari rehberidir.
|
||||||
|
|
||||||
|
## Proje Backend Durumu ve Özellikler
|
||||||
|
|
||||||
|
- **Go Sürümü:** 1.25.6
|
||||||
|
- **Veritabanı:** PostgreSQL
|
||||||
|
- **Web Framework:** Gin
|
||||||
|
- **Mimari:** RESTful API
|
||||||
|
|
||||||
|
## Proje Frontend Durumu ve Özellikler
|
||||||
|
|
||||||
|
- **Next js:** 16.1.6
|
||||||
|
- **Next-auth":** 4.24.13
|
||||||
|
- **Radix-ui":** 1.4.3
|
||||||
|
- **Shadcn/ui":** Latest
|
||||||
|
- **Sweetalert2":** 11.26.18
|
||||||
|
- **Ioredis":** 5.9.2
|
||||||
|
- **Redux":** 1.4.3
|
||||||
|
- **Redux Toolkit":** 1.4.3
|
||||||
|
- **Zod":** 4.3.6
|
||||||
|
- **Tailwindcss":** 4
|
||||||
|
- **Tailwind-merge":** 3.4.0
|
||||||
|
- **Lucide-react":** 0.563.0
|
||||||
|
- **Tw-animate-css":** 1.4.0
|
||||||
|
- **server side rendering:** true
|
||||||
|
|
||||||
|
## API Uç Noktaları
|
||||||
|
|
||||||
|
-- Register Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/register
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**",
|
||||||
|
"username":"test yaptim"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJwZXJtaXNzaW9ucyI6WyJ1c2VyOnJlYWQiXSwiaXNzIjoiZ2F1dGgtY2VudHJhbCIsImV4cCI6MTc3MDEzMDQ2OCwiaWF0IjoxNzcwMTI5NTY4fQ.Qc5EnE2r-In7hm6-NjP6WX2TKm3MyuM68SwsHYUNJbI",
|
||||||
|
"email": "bexysshanod@beyhan.dev",
|
||||||
|
"message": "User created successfully",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwNzM0MzY4LCJpYXQiOjE3NzAxMjk1Njh9.JE2UZ6jJti2N2jbExx_TTY5VPSfXKvc2ZGB-Nw_toLQ",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "f05ee74f-ab83-4171-b277-fdc446a607b7",
|
||||||
|
"username": "test yaptim"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Login Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/login
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMwNjU3LCJpYXQiOjE3NzAxMjk3NTd9.QbsRFn5fr7L4Wc7HCxOs0_zOWWhuceWzPmt20TV5lNI",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ1NTcsImlhdCI6MTc3MDEyOTc1N30.wBML1pT9S9i9FtAw3PKmJBMdcobZexWVBTRV5remb_s",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Refresh Token
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/refresh
|
||||||
|
-- Gönderilen JSON
|
||||||
|
{
|
||||||
|
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ2NDUsImlhdCI6MTc3MDEyOTg0NX0.ACDDM20v1u6yjyNrqBnWafjXnrRAAT1-8CvfqSkjTsE"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMxMjYwLCJpYXQiOjE3NzAxMzAzNjB9.BKmZBkL6FPo208mYLeBFMkNOqJ2tsmGXJUN_0bdZFHQ",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzUxNjAsImlhdCI6MTc3MDEzMDM2MH0.tkpcbQ6QmVVXK-r0QgP333X_FrAktVOuh1AJhwvV1BQ"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Me (Kullanıcı Profili)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/me
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"created_at": "2026-02-03T17:03:07.863425+03:00",
|
||||||
|
"updated_at": "2026-02-03T17:03:07.880923+03:00",
|
||||||
|
"social_accounts": null,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Validate Token (Token Doğrulama)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/validate
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği, body gönderilmez)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"message": "Token is valid",
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373"
|
||||||
|
}
|
||||||
|
## Kurulum ve Çalıştırma
|
||||||
|
|
||||||
|
1. `.env.example` dosyasını `.env` olarak kopyalayın ve değerleri düzenleyin.
|
||||||
|
2. Docker ile veritabanını ve uygulamayı başlatmak için:
|
||||||
|
```bash
|
||||||
|
./scripts/run.sh
|
||||||
|
```
|
||||||
|
_(Bu script Docker konteynerini kontrol eder, yoksa başlatır ve ardından Go sunucusunu çalıştırır)_
|
||||||
|
|
||||||
|
## Geliştirme Notları
|
||||||
|
|
||||||
|
- **Env Değişkenleri:**
|
||||||
|
- `RATE_LIMIT_BLACKLIST_IPS=...`, `RATE_LIMIT_BLACKLIST_DOMAINS=...` ile yasaklama.
|
||||||
|
- `RATE_LIMIT_WHITELIST=...`, `RATE_LIMIT_WHITELIST_DOMAINS=...` ile muafiyet.
|
||||||
|
|
||||||
|
- **Migration Ekleme:** `internal/db/migrations` klasörüne `00000X_description.up.sql` formatında yeni dosya ekleyin.
|
||||||
|
- **Admin Kullanıcısı:** Sistem ilk açılışta `admin@example.com` / `admin123` kullanıcısını otomatik oluşturur.
|
||||||
|
- **Docker Volume:** `/uploads` klasörü `uploads_data` volume'ü ile kalıcı hale getirilmiştir.
|
||||||
|
- **Image Processing:** WebP desteği için Dockerfile `CGO_ENABLED=1` ve `build-base` içerir.
|
||||||
191
HARD_DELETE_GUIDE.md
Normal file
191
HARD_DELETE_GUIDE.md
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
# Hard Delete Hızlı Referans
|
||||||
|
|
||||||
|
## Tek Komutla Hard Delete
|
||||||
|
|
||||||
|
### 1. Kullanıcı ID ile Hard Delete
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Admin token al ve kullanıcıyı sil
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token') && \
|
||||||
|
curl -X DELETE "http://localhost:8080/v1/admin/users/USER_ID_BURAYA?hard=true" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
**USER_ID_BURAYA** yerine gerçek UUID'yi yazın.
|
||||||
|
|
||||||
|
### 2. Email ile Bul ve Hard Delete
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Token al
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# Email ile kullanıcı bul
|
||||||
|
USER_ID=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=test@example.com" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq -r '.users[0].id')
|
||||||
|
|
||||||
|
# Hard delete
|
||||||
|
curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. One-Liner (Tek Satırda)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login -H "Content-Type: application/json" -d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token') && USER_ID=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=EMAIL_BURAYA" -H "Authorization: Bearer $TOKEN" | jq -r '.users[0].id') && curl -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" -H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
**EMAIL_BURAYA** yerine silinecek email'i yazın.
|
||||||
|
|
||||||
|
## API Endpoint'leri
|
||||||
|
|
||||||
|
| İşlem | Method | Endpoint | Query Param |
|
||||||
|
|-------|--------|----------|-------------|
|
||||||
|
| Soft Delete | DELETE | `/v1/admin/users/{id}` | - |
|
||||||
|
| Hard Delete | DELETE | `/v1/admin/users/{id}` | `?hard=true` |
|
||||||
|
| Kullanıcı Ara | GET | `/v1/admin/users/search` | `?q=email` |
|
||||||
|
| Kullanıcı Listele | GET | `/v1/admin/users` | `?page=1&limit=10` |
|
||||||
|
|
||||||
|
## Örnek Yanıtlar
|
||||||
|
|
||||||
|
### Başarılı Hard Delete
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "User deleted permanently successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Başarılı Soft Delete
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "User deleted soft successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hata (Kullanıcı Bulunamadı)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Failed to delete user"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hata (Kendi Hesabını Silmeye Çalışma)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Cannot delete your own account"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## cURL ile POST Örnekleri
|
||||||
|
|
||||||
|
### Yeni Kullanıcı Oluştur (Hard Delete için)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# Form data ile (avatar ile)
|
||||||
|
curl -X POST http://localhost:8080/v1/admin/users \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "email=newuser@test.com" \
|
||||||
|
-F "password=password123" \
|
||||||
|
-F "user_name=New User" \
|
||||||
|
-F "email_verified=false" \
|
||||||
|
-F "roles=user"
|
||||||
|
|
||||||
|
# Yanıt - User ID'yi not edin
|
||||||
|
# {
|
||||||
|
# "id": "abc-123-def-456",
|
||||||
|
# "email": "newuser@test.com",
|
||||||
|
# ...
|
||||||
|
# }
|
||||||
|
|
||||||
|
# Hard delete
|
||||||
|
curl -X DELETE "http://localhost:8080/v1/admin/users/abc-123-def-456?hard=true" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pratik Scriptler
|
||||||
|
|
||||||
|
### test-hard-delete.sh
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Test kullanıcısı oluştur ve hemen hard delete yap
|
||||||
|
echo "Creating admin token..."
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
echo "Creating test user..."
|
||||||
|
CREATE_RESPONSE=$(curl -s -X POST http://localhost:8080/v1/admin/users \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "email=temp@test.com" \
|
||||||
|
-F "password=temp123" \
|
||||||
|
-F "user_name=Temp User" \
|
||||||
|
-F "email_verified=false" \
|
||||||
|
-F "roles=user")
|
||||||
|
|
||||||
|
USER_ID=$(echo $CREATE_RESPONSE | jq -r '.id')
|
||||||
|
echo "Created user: $USER_ID"
|
||||||
|
|
||||||
|
echo "Hard deleting user..."
|
||||||
|
DELETE_RESPONSE=$(curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \
|
||||||
|
-H "Authorization: Bearer $TOKEN")
|
||||||
|
|
||||||
|
echo "Result: $DELETE_RESPONSE"
|
||||||
|
```
|
||||||
|
|
||||||
|
### bulk-hard-delete.sh
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Belirli email pattern'e uyan tüm kullanıcıları hard delete yap
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# test içeren emailler
|
||||||
|
SEARCH_QUERY="test"
|
||||||
|
|
||||||
|
echo "Searching users with pattern: $SEARCH_QUERY"
|
||||||
|
USER_IDS=$(curl -s -X GET "http://localhost:8080/v1/admin/users/search?q=$SEARCH_QUERY" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq -r '.users[].id')
|
||||||
|
|
||||||
|
for USER_ID in $USER_IDS; do
|
||||||
|
echo "Hard deleting: $USER_ID"
|
||||||
|
curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID?hard=true" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.'
|
||||||
|
sleep 0.5 # Rate limiting için
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Bulk hard delete completed!"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Önemli Notlar
|
||||||
|
|
||||||
|
✅ **Kullanım Öncesi:**
|
||||||
|
- Admin token'ınızın geçerli olduğundan emin olun
|
||||||
|
- Silinecek kullanıcının ID'sini doğrulayın
|
||||||
|
- Soft delete yerine hard delete kullanmak istediğinizden emin olun
|
||||||
|
|
||||||
|
⚠️ **Dikkat:**
|
||||||
|
- Hard delete **GERİ ALINAMAZ**
|
||||||
|
- Kendi hesabınızı silemezsiniz
|
||||||
|
- Üretim ortamında dikkatli kullanın
|
||||||
|
- Yedek almadan hard delete yapmayın
|
||||||
|
|
||||||
|
🔧 **Debug:**
|
||||||
|
```bash
|
||||||
|
# Token geçerli mi kontrol et
|
||||||
|
curl -X GET http://localhost:8080/v1/auth/validate \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
|
||||||
|
# Kullanıcı var mı kontrol et
|
||||||
|
curl -X GET "http://localhost:8080/v1/admin/users/$USER_ID" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
35
Login.txt
Normal file
35
Login.txt
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
curl -X 'POST' \
|
||||||
|
'http://127.0.0.1:8080/v1/auth/login' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"password": "1923btO**"
|
||||||
|
}'
|
||||||
|
|
||||||
|
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1M2JmNGIwNS03ZDgzLTQ4ZjUtODQ3Ny1kODc4YTFkYjY3ZDkiLCJlbWFpbCI6ImJleWhhbkBiZXloYW4uZGV2IiwicGVybWlzc2lvbnMiOlsidXNlcjpyZWFkIl0sImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzAyMzc5NTksImlhdCI6MTc3MDIzNzA1OX0.I2z8n8G8kv3phvdv_IyL8CaY-LnYl9wpyleGQjTXmQc",
|
||||||
|
"avatar": "",
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1M2JmNGIwNS03ZDgzLTQ4ZjUtODQ3Ny1kODc4YTFkYjY3ZDkiLCJlbWFpbCI6ImJleWhhbkBiZXloYW4uZGV2IiwiaXNzIjoiZ2F1dGgtY2VudHJhbCIsImV4cCI6MTc3MDg0MTg1OSwiaWF0IjoxNzcwMjM3MDU5fQ.sHEQU1LWFSD9FJ2d1gj_GHjP35uzGm2NDvaqa_ckLHk",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "53bf4b05-7d83-48f5-8477-d878a1db67d9",
|
||||||
|
"username": "Beyhan Oğur"
|
||||||
|
}
|
||||||
36
README.md
Normal file
36
README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
First, run the development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
# or
|
||||||
|
yarn dev
|
||||||
|
# or
|
||||||
|
pnpm dev
|
||||||
|
# or
|
||||||
|
bun dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||||
|
|
||||||
|
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
To learn more about Next.js, take a look at the following resources:
|
||||||
|
|
||||||
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
|
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||||
|
|
||||||
|
## Deploy on Vercel
|
||||||
|
|
||||||
|
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||||
|
|
||||||
|
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||||
35
Register.txt
Normal file
35
Register.txt
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
curl -X 'POST' \
|
||||||
|
'http://127.0.0.1:8080/v1/auth/register' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"password": "1923btO**",
|
||||||
|
"username": "Beyhan Oğur"
|
||||||
|
}'
|
||||||
|
Response body
|
||||||
|
Download
|
||||||
|
|
||||||
|
{
|
||||||
|
"avatar": "",
|
||||||
|
"email": "beyhan@beyhan.dev",
|
||||||
|
"email_verified": false,
|
||||||
|
"message": "User created. Please verify your email.",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "53bf4b05-7d83-48f5-8477-d878a1db67d9",
|
||||||
|
"username": "Beyhan Oğur",
|
||||||
|
"verification_token": "25b6ea0d5f7376881d5f57b11305122431e8967a13ce66888f2312b22bca48ef"
|
||||||
|
}
|
||||||
414
SOFT_DELETE_MANAGEMENT.md
Normal file
414
SOFT_DELETE_MANAGEMENT.md
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
# Soft Delete Kullanıcı Yönetimi
|
||||||
|
|
||||||
|
## Genel Bakış
|
||||||
|
|
||||||
|
AuthCentral'da silinen kullanıcılar soft delete ile yönetilir. Bu, kullanıcıların veritabanından silinmeden sadece işaretlenerek pasif hale getirilmesi anlamına gelir.
|
||||||
|
|
||||||
|
## Yeni Endpoint'ler
|
||||||
|
|
||||||
|
### 1. Silinen Kullanıcıları Listele
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /v1/admin/users/deleted
|
||||||
|
```
|
||||||
|
|
||||||
|
**Query Parameters:**
|
||||||
|
- `page` (int, optional) - Sayfa numarası (default: 1)
|
||||||
|
- `limit` (int, optional) - Sayfa başına kayıt (default: 10, max: 100)
|
||||||
|
|
||||||
|
**Örnek:**
|
||||||
|
```bash
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
curl -X GET "http://localhost:8080/v1/admin/users/deleted?page=1&limit=10" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"users": [
|
||||||
|
{
|
||||||
|
"id": "ca567947-ef2a-49ad-b955-bf0ef6bbf136",
|
||||||
|
"username": "Delete Me",
|
||||||
|
"email": "deleteme@test.com",
|
||||||
|
"avatar": "",
|
||||||
|
"email_verified": true,
|
||||||
|
"created_at": "2026-02-05T00:03:08.360433+03:00",
|
||||||
|
"updated_at": "2026-02-05T00:03:08.38027+03:00",
|
||||||
|
"deleted_at": "2026-02-05T00:03:25.549299+03:00",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"social_accounts": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pagination": {
|
||||||
|
"page": 1,
|
||||||
|
"limit": 10,
|
||||||
|
"total": 12,
|
||||||
|
"totalPages": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Özellikler:**
|
||||||
|
- ✅ `deleted_at` field'ı görünür (normal endpoint'lerde gizli)
|
||||||
|
- ✅ Pagination desteği
|
||||||
|
- ✅ Sadece soft delete edilmiş kullanıcılar gösterilir
|
||||||
|
- ✅ En son silinen kullanıcılar önce gelir (deleted_at DESC)
|
||||||
|
|
||||||
|
### 2. Kullanıcıyı Geri Yükle (Restore)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
POST /v1/admin/users/{id}/restore
|
||||||
|
```
|
||||||
|
|
||||||
|
**Path Parameters:**
|
||||||
|
- `id` (uuid, required) - Kullanıcı ID
|
||||||
|
|
||||||
|
**Örnek:**
|
||||||
|
```bash
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
USER_ID="ca567947-ef2a-49ad-b955-bf0ef6bbf136"
|
||||||
|
|
||||||
|
curl -X POST "http://localhost:8080/v1/admin/users/$USER_ID/restore" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "User restored successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hata Yanıtları:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "deleted user not found"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Kullanım Senaryoları
|
||||||
|
|
||||||
|
### Senaryo 1: Silinen Kullanıcıları İnceleme
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Admin login
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# Tüm silinen kullanıcıları listele
|
||||||
|
echo "=== Deleted Users ==="
|
||||||
|
curl -s -X GET "http://localhost:8080/v1/admin/users/deleted" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.users[] | {id, email, username, deleted_at}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Senaryo 2: Kullanıcıyı Soft Delete ve Restore
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
USER_ID="abc-123-def-456"
|
||||||
|
|
||||||
|
# 1. Kullanıcıyı soft delete yap
|
||||||
|
echo "Step 1: Soft delete user"
|
||||||
|
curl -s -X DELETE "http://localhost:8080/v1/admin/users/$USER_ID" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.'
|
||||||
|
|
||||||
|
# 2. Silinen kullanıcılar listesinde kontrol et
|
||||||
|
echo -e "\nStep 2: Check deleted users"
|
||||||
|
curl -s -X GET "http://localhost:8080/v1/admin/users/deleted" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq ".users[] | select(.id==\"$USER_ID\")"
|
||||||
|
|
||||||
|
# 3. Kullanıcıyı geri yükle
|
||||||
|
echo -e "\nStep 3: Restore user"
|
||||||
|
curl -s -X POST "http://localhost:8080/v1/admin/users/$USER_ID/restore" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.'
|
||||||
|
|
||||||
|
# 4. Normal kullanıcı listesinde kontrol et
|
||||||
|
echo -e "\nStep 4: Verify user is restored"
|
||||||
|
curl -s -X GET "http://localhost:8080/v1/admin/users/$USER_ID" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '{id, email, username}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Senaryo 3: Frontend İçin Silinen Kullanıcılar Yönetimi
|
||||||
|
|
||||||
|
**Frontend JavaScript Örneği:**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// API Client
|
||||||
|
class AdminAPI {
|
||||||
|
constructor(baseURL, token) {
|
||||||
|
this.baseURL = baseURL;
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDeletedUsers(page = 1, limit = 10) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${this.baseURL}/v1/admin/users/deleted?page=${page}&limit=${limit}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async restoreUser(userId) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${this.baseURL}/v1/admin/users/${userId}/restore`,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async softDeleteUser(userId) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${this.baseURL}/v1/admin/users/${userId}`,
|
||||||
|
{
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async hardDeleteUser(userId) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${this.baseURL}/v1/admin/users/${userId}?hard=true`,
|
||||||
|
{
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kullanım
|
||||||
|
const admin = new AdminAPI('http://localhost:8080', YOUR_TOKEN);
|
||||||
|
|
||||||
|
// Silinen kullanıcıları getir
|
||||||
|
const deletedUsers = await admin.getDeletedUsers(1, 10);
|
||||||
|
console.log(deletedUsers);
|
||||||
|
|
||||||
|
// Kullanıcıyı geri yükle
|
||||||
|
const result = await admin.restoreUser('user-uuid-here');
|
||||||
|
console.log(result);
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Endpoint'leri Özeti
|
||||||
|
|
||||||
|
| Endpoint | Method | Açıklama | Query/Body |
|
||||||
|
|----------|--------|----------|------------|
|
||||||
|
| `/v1/admin/users` | GET | Aktif kullanıcılar | `?page=1&limit=10` |
|
||||||
|
| `/v1/admin/users/deleted` | GET | **Silinen kullanıcılar** | `?page=1&limit=10` |
|
||||||
|
| `/v1/admin/users/{id}` | DELETE | Soft delete | - |
|
||||||
|
| `/v1/admin/users/{id}?hard=true` | DELETE | Hard delete (kalıcı) | `?hard=true` |
|
||||||
|
| `/v1/admin/users/{id}/restore` | POST | **Kullanıcıyı geri yükle** | - |
|
||||||
|
|
||||||
|
## Soft Delete vs Hard Delete
|
||||||
|
|
||||||
|
| Özellik | Soft Delete | Hard Delete |
|
||||||
|
|---------|-------------|-------------|
|
||||||
|
| **Veritabanı** | `deleted_at` timestamp set edilir | Tamamen silinir |
|
||||||
|
| **Görünürlük** | `/deleted` endpoint'inde görünür | Hiçbir yerde görünmez |
|
||||||
|
| **Geri Getirme** | ✅ `/restore` ile mümkün | ❌ İmkansız |
|
||||||
|
| **İlişkiler** | Korunur | Silinir |
|
||||||
|
| **Kullanım** | Varsayılan, güvenli | Dikkatli kullanılmalı |
|
||||||
|
| **Komut** | `DELETE /users/{id}` | `DELETE /users/{id}?hard=true` |
|
||||||
|
|
||||||
|
## Frontend Entegrasyonu
|
||||||
|
|
||||||
|
### React Örneği
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
function DeletedUsersManager() {
|
||||||
|
const [deletedUsers, setDeletedUsers] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
|
||||||
|
const fetchDeletedUsers = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`http://localhost:8080/v1/admin/users/deleted?page=${page}&limit=10`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
setDeletedUsers(data.users);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching deleted users:', error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreUser = async (userId) => {
|
||||||
|
if (!confirm('Bu kullanıcıyı geri yüklemek istediğinize emin misiniz?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`http://localhost:8080/v1/admin/users/${userId}/restore`,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${localStorage.getItem('token')}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
alert('Kullanıcı başarıyla geri yüklendi!');
|
||||||
|
fetchDeletedUsers(); // Listeyi yenile
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error restoring user:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchDeletedUsers();
|
||||||
|
}, [page]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="deleted-users-manager">
|
||||||
|
<h2>Silinen Kullanıcılar</h2>
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<p>Yükleniyor...</p>
|
||||||
|
) : (
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Kullanıcı Adı</th>
|
||||||
|
<th>Silinme Tarihi</th>
|
||||||
|
<th>İşlemler</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{deletedUsers.map(user => (
|
||||||
|
<tr key={user.id}>
|
||||||
|
<td>{user.email}</td>
|
||||||
|
<td>{user.username}</td>
|
||||||
|
<td>{new Date(user.deleted_at).toLocaleString('tr-TR')}</td>
|
||||||
|
<td>
|
||||||
|
<button onClick={() => restoreUser(user.id)}>
|
||||||
|
Geri Yükle
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="pagination">
|
||||||
|
<button onClick={() => setPage(p => Math.max(1, p - 1))}>
|
||||||
|
Önceki
|
||||||
|
</button>
|
||||||
|
<span>Sayfa {page}</span>
|
||||||
|
<button onClick={() => setPage(p => p + 1)}>
|
||||||
|
Sonraki
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DeletedUsersManager;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Güvenlik Notları
|
||||||
|
|
||||||
|
✅ **İyi Pratikler:**
|
||||||
|
- Silinen kullanıcıları düzenli olarak gözden geçirin
|
||||||
|
- Restore işleminden önce kullanıcıyı doğrulayın
|
||||||
|
- Hard delete yapmadan önce soft delete kullanın
|
||||||
|
- Kritik kullanıcılar için restore geçmişi tutun
|
||||||
|
|
||||||
|
⚠️ **Dikkat Edilmesi Gerekenler:**
|
||||||
|
- Sadece admin rolündeki kullanıcılar bu endpoint'lere erişebilir
|
||||||
|
- Restore edilen kullanıcı önceki tüm rolleri ve ayarları ile geri gelir
|
||||||
|
- Soft delete edilmiş kullanıcılar login yapamaz
|
||||||
|
- Hard delete geri alınamaz, dikkatli kullanın
|
||||||
|
|
||||||
|
## Test Komutları
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Kullanıcı oluştur
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"admin@gauth.local","password":"Admin@123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
curl -X POST http://localhost:8080/v1/admin/users \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "email=test@example.com" \
|
||||||
|
-F "password=test123" \
|
||||||
|
-F "user_name=Test User" \
|
||||||
|
-F "roles=user"
|
||||||
|
|
||||||
|
# 2. Kullanıcıyı soft delete yap
|
||||||
|
curl -X DELETE "http://localhost:8080/v1/admin/users/USER_ID" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
|
||||||
|
# 3. Silinen kullanıcıları listele
|
||||||
|
curl -X GET "http://localhost:8080/v1/admin/users/deleted" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.'
|
||||||
|
|
||||||
|
# 4. Kullanıcıyı geri yükle
|
||||||
|
curl -X POST "http://localhost:8080/v1/admin/users/USER_ID/restore" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Özet
|
||||||
|
|
||||||
|
🎯 **Yeni Özellikler:**
|
||||||
|
- ✅ Silinen kullanıcıları listeleme
|
||||||
|
- ✅ Kullanıcıyı geri yükleme (restore)
|
||||||
|
- ✅ `deleted_at` field'ı görünürlüğü
|
||||||
|
- ✅ Pagination desteği
|
||||||
|
- ✅ Frontend entegrasyonu için hazır
|
||||||
|
|
||||||
|
📊 **Kullanım:**
|
||||||
|
- Soft delete varsayılan silme yöntemi
|
||||||
|
- Hard delete sadece kalıcı silme için
|
||||||
|
- Restore ile yanlışlıkla silinen kullanıcılar kurtarılabilir
|
||||||
|
- Frontend'de silinen kullanıcılar yönetilebilir
|
||||||
586
USER_PROFILE_API.md
Normal file
586
USER_PROFILE_API.md
Normal file
@@ -0,0 +1,586 @@
|
|||||||
|
# Kullanıcı Profil Yönetimi API
|
||||||
|
|
||||||
|
## Genel Bakış
|
||||||
|
|
||||||
|
AuthCentral kullanıcıları kendi profillerini yönetebilir. Bu dokümantasyon kullanıcı profil yönetimi endpoint'lerini açıklar.
|
||||||
|
|
||||||
|
## Endpoint'ler
|
||||||
|
|
||||||
|
### 1. Profil Bilgilerini Getir
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /v1/profile
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
- `Authorization: Bearer {access_token}`
|
||||||
|
|
||||||
|
**Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "7d8b023c-d5e4-4f62-8811-ddbf00d675bb",
|
||||||
|
"username": "admin",
|
||||||
|
"email": "admin@gauth.local",
|
||||||
|
"avatar": "/uploads/avatars/admin_avatar.png",
|
||||||
|
"email_verified": true,
|
||||||
|
"is_oauth_user": false,
|
||||||
|
"created_at": "2026-02-04T20:00:00Z",
|
||||||
|
"updated_at": "2026-02-05T10:00:00Z",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "admin",
|
||||||
|
"description": "Administrator role"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"social_accounts": []
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Yeni Field:**
|
||||||
|
- `is_oauth_user` (boolean) - Kullanıcı OAuth ile mi giriş yapmış (Google/GitHub)
|
||||||
|
|
||||||
|
**Örnek:**
|
||||||
|
```bash
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
curl -X GET "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. Profil Güncelle
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PUT /v1/profile
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
- `Authorization: Bearer {access_token}`
|
||||||
|
- `Content-Type: multipart/form-data` (avatar yüklemek için)
|
||||||
|
|
||||||
|
**Form Data:**
|
||||||
|
- `user_name` (string, optional) - Yeni kullanıcı adı
|
||||||
|
- `avatar` (file, optional) - Profil resmi (max 5MB)
|
||||||
|
|
||||||
|
**Örnek (Username Güncelleme):**
|
||||||
|
```bash
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "user_name=Beyhan Oğur"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Örnek (Avatar Yükleme):**
|
||||||
|
```bash
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "avatar=@/path/to/profile-picture.jpg"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Örnek (Username + Avatar):**
|
||||||
|
```bash
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "user_name=Beyhan Oğur" \
|
||||||
|
-F "avatar=@/path/to/profile-picture.jpg"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Profile updated successfully",
|
||||||
|
"user": {
|
||||||
|
"id": "7d8b023c-d5e4-4f62-8811-ddbf00d675bb",
|
||||||
|
"username": "Beyhan Oğur",
|
||||||
|
"email": "admin@gauth.local",
|
||||||
|
"avatar": "/uploads/avatars/7d8b023c_1770238858420987000.png",
|
||||||
|
"email_verified": true,
|
||||||
|
"roles": [...]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. Şifre Değiştir
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PUT /v1/profile/password
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
- `Authorization: Bearer {access_token}`
|
||||||
|
- `Content-Type: application/json`
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"current_password": "OldPassword123",
|
||||||
|
"new_password": "NewPassword123"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Örnek:**
|
||||||
|
```bash
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile/password" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"current_password": "OldPassword123",
|
||||||
|
"new_password": "NewPassword123"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Password changed successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hata Yanıtları:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Current password is incorrect"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Cannot change password for OAuth users (Google/GitHub login)"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Notlar:**
|
||||||
|
- ✅ Mevcut şifre doğrulanır
|
||||||
|
- ✅ Yeni şifre minimum 6 karakter olmalı
|
||||||
|
- ⚠️ **OAuth kullanıcıları (Google/GitHub) şifre değiştiremez**
|
||||||
|
- ⚠️ Şifre değiştirildikten sonra yeni şifre ile login yapılmalı
|
||||||
|
- 💡 `is_oauth_user: true` ise şifre değiştirme butonu gösterilmemeli
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. Email Adresi Değiştir
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PUT /v1/profile/email
|
||||||
|
```
|
||||||
|
|
||||||
|
**Headers:**
|
||||||
|
- `Authorization: Bearer {access_token}`
|
||||||
|
- `Content-Type: application/json`
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"new_email": "newemail@example.com",
|
||||||
|
"password": "YourCurrentPassword"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Örnek:**
|
||||||
|
```bash
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile/email" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"new_email": "newemail@example.com",
|
||||||
|
"password": "YourPassword123"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Başarılı Yanıt:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Email updated. Please verify your new email address.",
|
||||||
|
"new_email": "newemail@example.com",
|
||||||
|
"verification_token": "abc123def456..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hata Yanıtları:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Password is incorrect"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Email already in use"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Cannot change email for OAuth users (Google/GitHub login)"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Önemli Notlar:**
|
||||||
|
- ⚠️ **OAuth kullanıcıları (Google/GitHub) email değiştiremez**
|
||||||
|
- ⚠️ Email değiştirildiğinde `email_verified` false olur
|
||||||
|
- ⚠️ Yeni email adresine doğrulama email'i gönderilir
|
||||||
|
- ⚠️ Email doğrulanana kadar login yapılamaz
|
||||||
|
- ⚠️ Email doğrulama için `/v1/auth/verify-email?token=...` endpoint'i kullanılır
|
||||||
|
- 💡 `is_oauth_user: true` ise email değiştirme butonu gösterilmemeli
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Kullanım Senaryoları
|
||||||
|
|
||||||
|
### Senaryo 1: Tam Profil Güncelleme
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Login
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"user@example.com","password":"password123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# 1. Kullanıcı adını güncelle
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "user_name=Yeni İsim"
|
||||||
|
|
||||||
|
# 2. Avatar yükle
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "avatar=@./my-photo.jpg"
|
||||||
|
|
||||||
|
# 3. Şifre değiştir
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile/password" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"current_password": "password123",
|
||||||
|
"new_password": "newpassword456"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# 4. Profili kontrol et
|
||||||
|
curl -X GET "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Senaryo 2: Email Değiştirme ve Doğrulama
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Login
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"old@example.com","password":"password123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# 1. Email değiştir
|
||||||
|
RESPONSE=$(curl -s -X PUT "http://localhost:8080/v1/profile/email" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"new_email": "new@example.com",
|
||||||
|
"password": "password123"
|
||||||
|
}')
|
||||||
|
|
||||||
|
echo $RESPONSE | jq '.'
|
||||||
|
|
||||||
|
# 2. Verification token'ı al
|
||||||
|
VERIFY_TOKEN=$(echo $RESPONSE | jq -r '.verification_token')
|
||||||
|
|
||||||
|
# 3. Email'i doğrula
|
||||||
|
curl -X GET "http://localhost:8080/v1/auth/verify-email?token=$VERIFY_TOKEN"
|
||||||
|
|
||||||
|
# 4. Yeni email ile login
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "new@example.com",
|
||||||
|
"password": "password123"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Frontend Entegrasyonu
|
||||||
|
|
||||||
|
### React Örneği
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
function ProfilePage() {
|
||||||
|
const [user, setUser] = useState(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
|
||||||
|
// Profil bilgilerini yükle
|
||||||
|
const fetchProfile = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/profile', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
setUser(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching profile:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Username güncelle
|
||||||
|
const updateUsername = async (newUsername) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('user_name', newUsername);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/profile', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
},
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
fetchProfile(); // Profili yenile
|
||||||
|
alert('Username updated!');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating username:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Avatar yükle
|
||||||
|
const uploadAvatar = async (file) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('avatar', file);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/profile', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
},
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
fetchProfile(); // Profili yenile
|
||||||
|
alert('Avatar uploaded!');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error uploading avatar:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Şifre değiştir
|
||||||
|
const changePassword = async (currentPassword, newPassword) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/profile/password', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
current_password: currentPassword,
|
||||||
|
new_password: newPassword
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
alert('Password changed successfully!');
|
||||||
|
} else {
|
||||||
|
alert(data.error);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error changing password:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Email değiştir
|
||||||
|
const changeEmail = async (newEmail, password) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8080/v1/profile/email', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
new_email: newEmail,
|
||||||
|
password: password
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
alert('Email updated! Please check your email to verify.');
|
||||||
|
} else {
|
||||||
|
alert(data.error);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error changing email:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchProfile();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Profile</h1>
|
||||||
|
{user && (
|
||||||
|
<div>
|
||||||
|
<img src={`http://localhost:8080${user.avatar}`} alt="Avatar" />
|
||||||
|
<p>Username: {user.username}</p>
|
||||||
|
<p>Email: {user.email}</p>
|
||||||
|
<p>Verified: {user.email_verified ? 'Yes' : 'No'}</p>
|
||||||
|
|
||||||
|
{/* OAuth user indicator */}
|
||||||
|
{user.is_oauth_user && (
|
||||||
|
<p className="info">
|
||||||
|
ℹ️ Logged in with {user.social_accounts?.[0]?.provider || 'OAuth'}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Password change - only for non-OAuth users */}
|
||||||
|
{!user.is_oauth_user && (
|
||||||
|
<button onClick={() => {
|
||||||
|
const current = prompt('Current password:');
|
||||||
|
const newPass = prompt('New password:');
|
||||||
|
if (current && newPass) changePassword(current, newPass);
|
||||||
|
}}>
|
||||||
|
Change Password
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Email change - only for non-OAuth users */}
|
||||||
|
{!user.is_oauth_user && (
|
||||||
|
<button onClick={() => {
|
||||||
|
const newEmail = prompt('New email:');
|
||||||
|
const password = prompt('Your password:');
|
||||||
|
if (newEmail && password) changeEmail(newEmail, password);
|
||||||
|
}}>
|
||||||
|
Change Email
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API Özeti
|
||||||
|
|
||||||
|
| Endpoint | Method | Açıklama | Auth Required |
|
||||||
|
|----------|--------|----------|---------------|
|
||||||
|
| `/v1/profile` | GET | Profil bilgilerini getir | ✅ |
|
||||||
|
| `/v1/profile` | PUT | Profil güncelle (username, avatar) | ✅ |
|
||||||
|
| `/v1/profile/password` | PUT | Şifre değiştir | ✅ |
|
||||||
|
| `/v1/profile/email` | PUT | Email değiştir | ✅ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Güvenlik Notları
|
||||||
|
|
||||||
|
✅ **İyi Pratikler:**
|
||||||
|
- Şifre değiştirirken mevcut şifre doğrulanır
|
||||||
|
- Email değiştirirken doğrulama email'i gönderilir
|
||||||
|
- Avatar dosya boyutu sınırlandırılmıştır (max 5MB)
|
||||||
|
- Tüm endpoint'ler authentication gerektirir
|
||||||
|
|
||||||
|
⚠️ **Dikkat Edilmesi Gerekenler:**
|
||||||
|
- **OAuth kullanıcıları (Google/GitHub) şifre ve email değiştiremez**
|
||||||
|
- OAuth kullanıcıları sadece username ve avatar değiştirebilir
|
||||||
|
- Frontend'de `is_oauth_user` flag'ini kontrol edin
|
||||||
|
- Şifre değiştirme butonu OAuth kullanıcılarına gösterilmemeli
|
||||||
|
- Email değiştirme butonu OAuth kullanıcılarına gösterilmemeli
|
||||||
|
- Email değiştirildiğinde yeniden doğrulama gerekir
|
||||||
|
- Şifre minimum 6 karakter olmalı
|
||||||
|
- Avatar sadece resim formatları kabul edilir
|
||||||
|
|
||||||
|
## OAuth Kullanıcı Kısıtlamaları
|
||||||
|
|
||||||
|
| Özellik | Email/Password Kullanıcı | OAuth Kullanıcı (Google/GitHub) |
|
||||||
|
|---------|-------------------------|--------------------------------|
|
||||||
|
| Profil Görüntüleme | ✅ Evet | ✅ Evet |
|
||||||
|
| Username Değiştirme | ✅ Evet | ✅ Evet |
|
||||||
|
| Avatar Yükleme | ✅ Evet | ✅ Evet |
|
||||||
|
| **Şifre Değiştirme** | ✅ Evet | ❌ **Hayır** |
|
||||||
|
| **Email Değiştirme** | ✅ Evet | ❌ **Hayır** |
|
||||||
|
|
||||||
|
**Önemli:** Frontend'de `is_oauth_user` field'ını kontrol ederek UI'ı buna göre düzenleyin.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Test Komutları
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Login ve token al
|
||||||
|
TOKEN=$(curl -s -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"user@example.com","password":"password123"}' | jq -r '.access_token')
|
||||||
|
|
||||||
|
# Profil bilgilerini getir
|
||||||
|
curl -X GET "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" | jq '.'
|
||||||
|
|
||||||
|
# Username güncelle
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "user_name=New Name"
|
||||||
|
|
||||||
|
# Avatar yükle
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-F "avatar=@./photo.jpg"
|
||||||
|
|
||||||
|
# Şifre değiştir
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile/password" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"current_password":"old123","new_password":"new456"}'
|
||||||
|
|
||||||
|
# Email değiştir
|
||||||
|
curl -X PUT "http://localhost:8080/v1/profile/email" \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"new_email":"new@email.com","password":"password123"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Özet
|
||||||
|
|
||||||
|
🎯 **Özellikler:**
|
||||||
|
- ✅ Profil bilgilerini görüntüleme
|
||||||
|
- ✅ Kullanıcı adı güncelleme
|
||||||
|
- ✅ Avatar yükleme (max 5MB)
|
||||||
|
- ✅ Şifre değiştirme (mevcut şifre doğrulaması ile)
|
||||||
|
- ✅ Email değiştirme (yeniden doğrulama ile)
|
||||||
|
|
||||||
|
📊 **Kullanım:**
|
||||||
|
- Her kullanıcı kendi profilini yönetebilir
|
||||||
|
- OAuth kullanıcıları şifre değiştiremez
|
||||||
|
- Email değişikliği doğrulama gerektirir
|
||||||
|
- Avatar otomatik optimize edilir
|
||||||
178
app/(admin)/admin/cors/page.tsx
Normal file
178
app/(admin)/admin/cors/page.tsx
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import {
|
||||||
|
Breadcrumb,
|
||||||
|
BreadcrumbItem,
|
||||||
|
BreadcrumbLink,
|
||||||
|
BreadcrumbList,
|
||||||
|
BreadcrumbPage,
|
||||||
|
BreadcrumbSeparator,
|
||||||
|
} from "@/components/ui/breadcrumb";
|
||||||
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
||||||
|
import {
|
||||||
|
fetchWhitelists,
|
||||||
|
fetchBlacklists,
|
||||||
|
createWhitelist,
|
||||||
|
createBlacklist,
|
||||||
|
deleteWhitelist,
|
||||||
|
deleteBlacklist,
|
||||||
|
updateWhitelist,
|
||||||
|
updateBlacklist,
|
||||||
|
CorsEntry,
|
||||||
|
} from "@/lib/features/cors/corsSlice";
|
||||||
|
import { CorsTable } from "@/components/cors/cors-table";
|
||||||
|
import { CorsDialog } from "@/components/cors/cors-dialog";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Plus } from "lucide-react";
|
||||||
|
import Swal from "sweetalert2";
|
||||||
|
|
||||||
|
export default function CorsPage() {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { whitelist, blacklist } = useAppSelector((state) => state.cors);
|
||||||
|
const [activeTab, setActiveTab] = useState<"whitelist" | "blacklist">("whitelist");
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
|
||||||
|
// Dialog state
|
||||||
|
const [dialogOpen, setDialogOpen] = useState(false);
|
||||||
|
const [editingEntry, setEditingEntry] = useState<CorsEntry | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
dispatch(fetchWhitelists());
|
||||||
|
dispatch(fetchBlacklists());
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
|
if (!mounted) return null;
|
||||||
|
|
||||||
|
const handleDelete = (id: string) => {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Emin misiniz?',
|
||||||
|
text: "Bu kaydı silmek istediğinize emin misiniz?",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: '#3085d6',
|
||||||
|
cancelButtonColor: '#d33',
|
||||||
|
confirmButtonText: 'Evet, sil!',
|
||||||
|
cancelButtonText: 'İptal'
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
if (activeTab === "whitelist") {
|
||||||
|
dispatch(deleteWhitelist(id)).then(() => {
|
||||||
|
Swal.fire('Silindi!', 'Kayıt başarıyla silindi.', 'success');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch(deleteBlacklist(id)).then(() => {
|
||||||
|
Swal.fire('Silindi!', 'Kayıt başarıyla silindi.', 'success');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggleActive = (id: string, currentStatus: boolean) => {
|
||||||
|
const data = { is_active: !currentStatus };
|
||||||
|
if (activeTab === "whitelist") {
|
||||||
|
dispatch(updateWhitelist({ id, data }));
|
||||||
|
} else {
|
||||||
|
dispatch(updateBlacklist({ id, data }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEdit = (entry: CorsEntry) => {
|
||||||
|
setEditingEntry(entry);
|
||||||
|
setDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAddClick = () => {
|
||||||
|
setEditingEntry(null);
|
||||||
|
setDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDialogSubmit = async (origin: string, note: string) => {
|
||||||
|
if (editingEntry) {
|
||||||
|
// Update existing
|
||||||
|
const data: Partial<CorsEntry> = activeTab === "whitelist"
|
||||||
|
? { origin, description: note }
|
||||||
|
: { origin, reason: note };
|
||||||
|
|
||||||
|
if (activeTab === "whitelist") {
|
||||||
|
await dispatch(updateWhitelist({ id: editingEntry.id, data })).unwrap();
|
||||||
|
} else {
|
||||||
|
await dispatch(updateBlacklist({ id: editingEntry.id, data })).unwrap();
|
||||||
|
}
|
||||||
|
Swal.fire('Güncellendi!', 'Kayıt başarıyla güncellendi.', 'success');
|
||||||
|
} else {
|
||||||
|
// Create new
|
||||||
|
if (activeTab === "whitelist") {
|
||||||
|
await dispatch(createWhitelist({ origin, description: note })).unwrap();
|
||||||
|
} else {
|
||||||
|
await dispatch(createBlacklist({ origin, reason: note })).unwrap();
|
||||||
|
}
|
||||||
|
Swal.fire('Eklendi!', 'Yeni kayıt başarıyla eklendi.', 'success');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
{/* Header / Breadcrumb Section */}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Breadcrumb>
|
||||||
|
<BreadcrumbList>
|
||||||
|
<BreadcrumbItem className="hidden md:block">
|
||||||
|
<BreadcrumbLink href="/admin">Admin</BreadcrumbLink>
|
||||||
|
</BreadcrumbItem>
|
||||||
|
<BreadcrumbSeparator className="hidden md:block" />
|
||||||
|
<BreadcrumbItem>
|
||||||
|
<BreadcrumbPage>CORS Ayarları</BreadcrumbPage>
|
||||||
|
</BreadcrumbItem>
|
||||||
|
</BreadcrumbList>
|
||||||
|
</Breadcrumb>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
{/* Actions & Dialog */}
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div className="space-x-2">
|
||||||
|
<Button
|
||||||
|
variant={activeTab === "whitelist" ? "default" : "outline"}
|
||||||
|
onClick={() => setActiveTab("whitelist")}
|
||||||
|
>
|
||||||
|
Whitelist
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant={activeTab === "blacklist" ? "default" : "outline"}
|
||||||
|
onClick={() => setActiveTab("blacklist")}
|
||||||
|
>
|
||||||
|
Blacklist
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<Button onClick={handleAddClick}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
|
Yeni Ekle
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<CorsDialog
|
||||||
|
open={dialogOpen}
|
||||||
|
onOpenChange={setDialogOpen}
|
||||||
|
type={activeTab}
|
||||||
|
entry={editingEntry}
|
||||||
|
onSubmit={handleDialogSubmit}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Table */}
|
||||||
|
<div className="rounded-xl border bg-card">
|
||||||
|
<CorsTable
|
||||||
|
data={activeTab === "whitelist" ? whitelist : blacklist}
|
||||||
|
type={activeTab}
|
||||||
|
onDelete={handleDelete}
|
||||||
|
onEdit={handleEdit}
|
||||||
|
onToggleActive={handleToggleActive}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
61
app/(admin)/admin/page.tsx
Normal file
61
app/(admin)/admin/page.tsx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useAppSelector } from "@/lib/hooks";
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { getAvatarUrl } from "@/lib/utils";
|
||||||
|
|
||||||
|
export default function DashboardPage() {
|
||||||
|
const { user } = useAppSelector((state) => state.auth);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-medium">Hoşgeldin, {user?.username}</h3>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Admin paneli kontrol merkezi.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
|
<CardTitle className="text-sm font-medium">Toplam Kullanıcı</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">128</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
+4% geçen aydan beri
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
|
<CardTitle className="text-sm font-medium">Aktif Roller</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="text-2xl font-bold">
|
||||||
|
{user?.roles?.map(r => r.name).join(", ") || "Yok"}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Profil Bilgileri</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="flex items-center gap-4">
|
||||||
|
<Avatar className="h-20 w-20">
|
||||||
|
<AvatarImage src={getAvatarUrl(user?.avatar_url)} />
|
||||||
|
<AvatarFallback>{user?.username?.slice(0, 2).toUpperCase()}</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<div>
|
||||||
|
<div className="font-semibold text-lg">{user?.username}</div>
|
||||||
|
<div className="text-muted-foreground">{user?.email}</div>
|
||||||
|
<div className="text-xs text-muted-foreground mt-1">ID: {user?.id}</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
223
app/(admin)/admin/users/page.tsx
Normal file
223
app/(admin)/admin/users/page.tsx
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
||||||
|
import { fetchUsers, fetchDeletedUsers, createUser, updateUser, deleteUser, restoreUser, CreateUserRequest, UpdateUserRequest } from "@/lib/features/users/usersSlice";
|
||||||
|
import { UserTable } from "@/components/users/user-table";
|
||||||
|
import { DeletedUserTable } from "@/components/users/deleted-user-table";
|
||||||
|
import { UserDialog } from "@/components/users/user-dialog";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Plus, Trash, Trash2 } from "lucide-react";
|
||||||
|
import Swal from "sweetalert2";
|
||||||
|
import { User } from "@/lib/features/auth/authSlice";
|
||||||
|
|
||||||
|
export default function UsersPage() {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { users, deletedUsers, isLoading, error } = useAppSelector((state) => state.users);
|
||||||
|
const [dialogOpen, setDialogOpen] = useState(false);
|
||||||
|
const [selectedUser, setSelectedUser] = useState<User | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchUsers());
|
||||||
|
dispatch(fetchDeletedUsers());
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
|
const handleCreate = () => {
|
||||||
|
setSelectedUser(null);
|
||||||
|
setDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEdit = (user: User) => {
|
||||||
|
setSelectedUser(user);
|
||||||
|
setDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = (id: string) => {
|
||||||
|
Swal.fire({
|
||||||
|
title: "Soft Delete",
|
||||||
|
text: "Bu kullanıcı 'silindi' olarak işaretlenecek (Soft Delete). Geri alınabilir.",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#f97316", // Orange
|
||||||
|
cancelButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "Evet, Sil",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
dispatch(deleteUser(id))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
Swal.fire("Silindi!", "Kullanıcı başarıyla silindi (Soft).", "success");
|
||||||
|
// Refresh both lists because a user moved from active to deleted
|
||||||
|
dispatch(fetchUsers());
|
||||||
|
dispatch(fetchDeletedUsers());
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata!", err || "Silme işlemi başarısız.", "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleHardDelete = (id: string) => {
|
||||||
|
Swal.fire({
|
||||||
|
title: "KALICI OLARAK SİL?",
|
||||||
|
text: "Bu işlem GERİ ALINAMAZ! Kullanıcı ve tüm verileri veritabanından tamamen silinecek (Hard Delete).",
|
||||||
|
icon: "error", // Red
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#d33", // Red
|
||||||
|
cancelButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "Evet, KALICI SİL!",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
const isSoftDeleted = deletedUsers.some(u => u.id === id);
|
||||||
|
|
||||||
|
if (isSoftDeleted) {
|
||||||
|
// WORKAROUND: Backend soft-deleted kullanıcıları bulamıyor olabilir.
|
||||||
|
// Önce restore et, sonra hard delete yap.
|
||||||
|
dispatch(restoreUser(id))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
return dispatch(deleteUser({ id, hard: true })).unwrap();
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
Swal.fire("Silindi!", "Kullanıcı kalıcı olarak silindi.", "success");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata!", err || "Silme işlemi başarısız.", "error");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Normal Hard Delete (Aktif kullanıcı)
|
||||||
|
dispatch(deleteUser({ id, hard: true }))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
Swal.fire("Silindi!", "Kullanıcı kalıcı olarak silindi.", "success");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata!", err || "Silme işlemi başarısız.", "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRestore = (id: string) => {
|
||||||
|
Swal.fire({
|
||||||
|
title: "Geri Yükle?",
|
||||||
|
text: "Kullanıcı tekrar aktif edilecek.",
|
||||||
|
icon: "question",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#16a34a", // Green
|
||||||
|
cancelButtonColor: "#d33",
|
||||||
|
confirmButtonText: "Evet, Geri Yükle",
|
||||||
|
cancelButtonText: "İptal",
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
dispatch(restoreUser(id))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
Swal.fire("Başarılı!", "Kullanıcı geri yüklendi.", "success");
|
||||||
|
dispatch(fetchUsers());
|
||||||
|
dispatch(fetchDeletedUsers());
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata!", err || "Geri yükleme başarısız.", "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = (data: CreateUserRequest | UpdateUserRequest) => {
|
||||||
|
if ("id" in data) {
|
||||||
|
dispatch(updateUser(data as UpdateUserRequest))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
setDialogOpen(false);
|
||||||
|
Swal.fire("Başarılı", "Kullanıcı güncellendi.", "success");
|
||||||
|
dispatch(fetchUsers());
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata", err || "Güncelleme başarısız.", "error");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dispatch(createUser(data as CreateUserRequest))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
setDialogOpen(false);
|
||||||
|
Swal.fire("Başarılı", "Kullanıcı oluşturuldu.", "success");
|
||||||
|
dispatch(fetchUsers());
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata", err || "Oluşturma başarısız.", "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-12">
|
||||||
|
{/* Active Users Section */}
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-md font-bold tracking-tight">Kullanıcılar</h2>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Sistemdeki aktif kullanıcıları yönetin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button onClick={() => { setSelectedUser(null); setDialogOpen(true); }}>
|
||||||
|
<Plus className="mr-2 h-4 w-4" /> Yeni Kullanıcı
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="rounded-md bg-destructive/15 p-4 text-destructive">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<UserTable
|
||||||
|
users={users}
|
||||||
|
onEdit={(u) => { setSelectedUser(u); setDialogOpen(true); }}
|
||||||
|
onDelete={handleDelete}
|
||||||
|
onHardDelete={handleHardDelete}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Deleted Users Section */}
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-2xl font-bold tracking-tight text-destructive flex items-center gap-2">
|
||||||
|
<Trash2 className="h-6 w-6" /> Çöp Kutusu
|
||||||
|
</h2>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Silinmiş kullanıcıları geri yükleyin veya kalıcı olarak silin.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DeletedUserTable
|
||||||
|
users={deletedUsers}
|
||||||
|
onRestore={handleRestore}
|
||||||
|
onHardDelete={handleHardDelete}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UserDialog
|
||||||
|
open={dialogOpen}
|
||||||
|
onOpenChange={setDialogOpen}
|
||||||
|
user={selectedUser}
|
||||||
|
onSubmit={(data) => {
|
||||||
|
// Re-implementing handleSubmit logic inline or keep it separate as before if preferred,
|
||||||
|
// but for brevity I'll assume the previous handleSubmit function is available in scope
|
||||||
|
// or I should include it in replacement if I am replacing the whole return block.
|
||||||
|
// Ideally, I should keep the existing handleSubmit and just pass it.
|
||||||
|
// Since I am replacing the whole return, I must ensure handleSubmit is defined above or passed correctly.
|
||||||
|
// Wait, I am replacing a range that includes imports and component setup? No, just the function body?
|
||||||
|
// Let's modify the instruction to be safer.
|
||||||
|
handleSubmit(data);
|
||||||
|
}}
|
||||||
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
83
app/(admin)/layout.tsx
Normal file
83
app/(admin)/layout.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useAppSelector } from "@/lib/hooks";
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
|
import { SidebarProvider, SidebarInset, SidebarTrigger } from "@/components/ui/sidebar";
|
||||||
|
import { AppSidebar } from "@/components/app-sidebar";
|
||||||
|
|
||||||
|
export default function AdminLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const { isAuthenticated, isLoading, user } = useAppSelector((state) => state.auth);
|
||||||
|
const router = useRouter();
|
||||||
|
const [authorized, setAuthorized] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// If we're not loading and not authenticated, redirect
|
||||||
|
// We wait for initial restoration to complete (managed by StoreProvider and authSlice)
|
||||||
|
const checkAuth = () => {
|
||||||
|
const token = Cookies.get("access_token");
|
||||||
|
if (!token) {
|
||||||
|
router.push("/login");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get user from state or localStorage
|
||||||
|
let currentUser = user;
|
||||||
|
if (!currentUser && typeof window !== 'undefined') {
|
||||||
|
const userStr = localStorage.getItem("user");
|
||||||
|
if (userStr) {
|
||||||
|
try {
|
||||||
|
currentUser = JSON.parse(userStr);
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentUser) {
|
||||||
|
const isAdmin = currentUser.roles?.some((r: any) => r.name === "admin");
|
||||||
|
if (isAdmin) {
|
||||||
|
setAuthorized(true);
|
||||||
|
} else {
|
||||||
|
// Redirect non-admins to home page
|
||||||
|
router.push("/");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Token exists but user data is missing/loading.
|
||||||
|
// If strictly protected, redirect to login.
|
||||||
|
router.push("/login");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkAuth();
|
||||||
|
}, [isAuthenticated, user, router]);
|
||||||
|
|
||||||
|
if (!authorized) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen items-center justify-center">
|
||||||
|
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SidebarProvider style={{ "--sidebar-width": "16rem" } as React.CSSProperties}>
|
||||||
|
<AppSidebar />
|
||||||
|
<SidebarInset>
|
||||||
|
<header className="flex h-14 shrink-0 items-center gap-2 px-4">
|
||||||
|
<SidebarTrigger className="-ml-1" />
|
||||||
|
<div className="h-4 w-[1px] bg-slate-200 dark:bg-slate-800" />
|
||||||
|
<span className="text-sm font-medium">Yönetim Paneli</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="flex flex-1 flex-col gap-4 p-4 pt-0">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</SidebarInset>
|
||||||
|
</SidebarProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
11
app/(auth)/layout.tsx
Normal file
11
app/(auth)/layout.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export default function AuthLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-[calc(100vh-4rem)] items-center justify-center py-12 sm:px-6 lg:px-8">
|
||||||
|
<div className="w-full max-w-md space-y-8">{children}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
135
app/(auth)/login/page.tsx
Normal file
135
app/(auth)/login/page.tsx
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
||||||
|
import { login } from "@/lib/features/auth/authSlice";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { Turnstile } from "nextjs-turnstile";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { AlertCircle, Loader2 } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
|
||||||
|
import { loginSchema } from "@/lib/schemas/login";
|
||||||
|
|
||||||
|
export default function LoginPage() {
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [formErrors, setFormErrors] = useState<Record<string, string>>({});
|
||||||
|
const [turnstileToken, setTurnstileToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { isLoading, error } = useAppSelector((state) => state.auth);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setFormErrors({});
|
||||||
|
|
||||||
|
// Zod Validation
|
||||||
|
const result = loginSchema.safeParse({
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
const errors: Record<string, string> = {};
|
||||||
|
result.error.issues.forEach((issue) => {
|
||||||
|
const path = issue.path[0];
|
||||||
|
if (typeof path === 'string') {
|
||||||
|
errors[path] = issue.message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setFormErrors(errors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!turnstileToken) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Hata',
|
||||||
|
text: 'Lütfen doğrulamayı tamamlayın (Turnstile).',
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dispatchResult = await dispatch(login({ email, password }));
|
||||||
|
if (login.fulfilled.match(dispatchResult)) {
|
||||||
|
Swal.fire({
|
||||||
|
position: "center",
|
||||||
|
icon: "success",
|
||||||
|
title: "Giriş Başarılı",
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1500
|
||||||
|
});
|
||||||
|
router.push("/admin");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="w-full shadow-lg dark:shadow-slate-800/20">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="text-2xl font-bold text-center">Giriş Yap</CardTitle>
|
||||||
|
<CardDescription className="text-center">
|
||||||
|
Admin paneline erişmek için giriş yapın
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
placeholder="admin@example.com"
|
||||||
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
// required override by Zod
|
||||||
|
/>
|
||||||
|
{formErrors.email && <p className="text-destructive text-sm">{formErrors.email}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="password">Şifre</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
// required override by Zod
|
||||||
|
/>
|
||||||
|
{formErrors.password && <p className="text-destructive text-sm">{formErrors.password}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-center py-2">
|
||||||
|
<Turnstile
|
||||||
|
siteKey={process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY || "0x4AAAAAACHzHKvlEwMamxCM"}
|
||||||
|
onSuccess={(token) => setTurnstileToken(token)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="flex items-center gap-2 text-sm text-destructive bg-destructive/10 p-3 rounded-md">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<span>{error}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button type="submit" className="w-full" disabled={isLoading || !turnstileToken}>
|
||||||
|
{isLoading ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : "Giriş Yap"}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className="flex justify-center">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Hesabınız yok mu?{" "}
|
||||||
|
<Link href="/register" className="text-primary hover:underline">
|
||||||
|
Kayıt Ol
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
161
app/(auth)/register/page.tsx
Normal file
161
app/(auth)/register/page.tsx
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
||||||
|
import { register } from "@/lib/features/auth/authSlice";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { Turnstile } from "nextjs-turnstile";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { AlertCircle, Loader2 } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import Swal from 'sweetalert2'
|
||||||
|
|
||||||
|
import { registerSchema } from "@/lib/schemas/register";
|
||||||
|
|
||||||
|
export default function RegisterPage() {
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [confirmPassword, setConfirmPassword] = useState("");
|
||||||
|
const [formErrors, setFormErrors] = useState<Record<string, string>>({});
|
||||||
|
const [turnstileToken, setTurnstileToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { isLoading, error } = useAppSelector((state) => state.auth);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setFormErrors({});
|
||||||
|
|
||||||
|
// Zod Validation
|
||||||
|
const result = registerSchema.safeParse({
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
confirmPassword
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
const errors: Record<string, string> = {};
|
||||||
|
result.error.issues.forEach((issue) => {
|
||||||
|
const path = issue.path[0];
|
||||||
|
if (typeof path === 'string') {
|
||||||
|
errors[path] = issue.message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setFormErrors(errors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!turnstileToken) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Hata',
|
||||||
|
text: 'Lütfen doğrulamayı tamamlayın (Turnstile).',
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dispatchResult = await dispatch(register({ username, email, password }));
|
||||||
|
if (register.fulfilled.match(dispatchResult)) {
|
||||||
|
Swal.fire({
|
||||||
|
position: "center",
|
||||||
|
icon: "success",
|
||||||
|
title: "Kayıt Başarılı!",
|
||||||
|
text: "Lütfen email adresinize gönderilen doğrulama linkine tıklayarak hesabınızı aktif edin.",
|
||||||
|
showConfirmButton: true,
|
||||||
|
confirmButtonText: "Giriş Yap"
|
||||||
|
}).then(() => {
|
||||||
|
router.push("/login");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="w-full shadow-lg dark:shadow-slate-800/20">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="text-2xl font-bold text-center">Kayıt Ol</CardTitle>
|
||||||
|
<CardDescription className="text-center">
|
||||||
|
Yeni bir hesap oluşturun
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="username">Kullanıcı Adı</Label>
|
||||||
|
<Input
|
||||||
|
id="username"
|
||||||
|
type="text"
|
||||||
|
placeholder="kullaniciadi"
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
// required validation is now handled by Zod manually on submit
|
||||||
|
/>
|
||||||
|
{formErrors.username && <p className="text-destructive text-sm">{formErrors.username}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="email">Email</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
placeholder="ornek@email.com"
|
||||||
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
/>
|
||||||
|
{formErrors.email && <p className="text-destructive text-sm">{formErrors.email}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="password">Şifre</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
{formErrors.password && <p className="text-destructive text-sm">{formErrors.password}</p>}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="confirmPassword">Şifre Tekrar</Label>
|
||||||
|
<Input
|
||||||
|
id="confirmPassword"
|
||||||
|
type="password"
|
||||||
|
value={confirmPassword}
|
||||||
|
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
{formErrors.confirmPassword && <p className="text-destructive text-sm">{formErrors.confirmPassword}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-center py-2">
|
||||||
|
<Turnstile
|
||||||
|
siteKey={process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY || "0x4AAAAAACHzHKvlEwMamxCM"}
|
||||||
|
onSuccess={(token) => setTurnstileToken(token)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="flex items-center gap-2 text-sm text-destructive bg-destructive/10 p-3 rounded-md">
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<span>{error}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button type="submit" className="w-full" disabled={isLoading || !turnstileToken}>
|
||||||
|
{isLoading ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : "Kayıt Ol"}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter className="flex justify-center">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Zaten hesabınız var mı?{" "}
|
||||||
|
<Link href="/login" className="text-primary hover:underline">
|
||||||
|
Giriş Yap
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
13
app/(dashboard)/layout.tsx
Normal file
13
app/(dashboard)/layout.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export default function DashboardLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen flex-col">
|
||||||
|
<main className="flex-1 p-6 md:p-8 pt-6">
|
||||||
|
{children}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
309
app/(dashboard)/profile/page.tsx
Normal file
309
app/(dashboard)/profile/page.tsx
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useState, useRef } from "react";
|
||||||
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
||||||
|
import { fetchProfile, updateProfile, changePassword, changeEmail } from "@/lib/features/auth/authSlice";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { getAvatarUrl } from "@/lib/utils";
|
||||||
|
import Swal from "sweetalert2";
|
||||||
|
import { Loader2, Camera, Shield, Mail, User as UserIcon } from "lucide-react";
|
||||||
|
|
||||||
|
export default function ProfilePage() {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { user, isLoading } = useAppSelector((state) => state.auth);
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
// Form states
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
|
||||||
|
// Password change states
|
||||||
|
const [currentPassword, setCurrentPassword] = useState("");
|
||||||
|
const [newPassword, setNewPassword] = useState("");
|
||||||
|
|
||||||
|
// Email change states
|
||||||
|
const [newEmail, setNewEmail] = useState("");
|
||||||
|
const [emailPassword, setEmailPassword] = useState("");
|
||||||
|
const [isMounted, setIsMounted] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsMounted(true);
|
||||||
|
dispatch(fetchProfile());
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) {
|
||||||
|
setUsername(user.username);
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
|
const handleAvatarChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (e.target.files && e.target.files[0]) {
|
||||||
|
setFile(e.target.files[0]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleProfileUpdate = () => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("user_name", username);
|
||||||
|
if (file) {
|
||||||
|
formData.append("avatar", file);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(updateProfile(formData))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
Swal.fire("Başarılı", "Profil bilgileriniz güncellendi.", "success");
|
||||||
|
setFile(null);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata", err || "Profil güncellenemedi.", "error");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangePassword = () => {
|
||||||
|
if (!currentPassword || !newPassword) {
|
||||||
|
Swal.fire("Uyarı", "Lütfen tüm alanları doldurun.", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPassword.length < 6) {
|
||||||
|
Swal.fire("Uyarı", "Yeni şifre en az 6 karakter olmalıdır.", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(changePassword({ current_password: currentPassword, new_password: newPassword }))
|
||||||
|
.unwrap()
|
||||||
|
.then(() => {
|
||||||
|
Swal.fire("Başarılı", "Şifreniz değiştirildi. Lütfen yeni şifrenizle tekrar giriş yapın.", "success");
|
||||||
|
setCurrentPassword("");
|
||||||
|
setNewPassword("");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata", err || "Şifre değiştirilemedi.", "error");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeEmail = () => {
|
||||||
|
if (!newEmail || !emailPassword) {
|
||||||
|
Swal.fire("Uyarı", "Lütfen tüm alanları doldurun.", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(changeEmail({ new_email: newEmail, password: emailPassword }))
|
||||||
|
.unwrap()
|
||||||
|
.then((res: any) => {
|
||||||
|
Swal.fire({
|
||||||
|
title: "Başarılı",
|
||||||
|
text: `Email adresiniz güncellendi. Lütfen ${newEmail} adresine gönderilen doğrulama linkine tıklayın.`,
|
||||||
|
icon: "success"
|
||||||
|
});
|
||||||
|
setNewEmail("");
|
||||||
|
setEmailPassword("");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Swal.fire("Hata", err || "Email değiştirilemedi.", "error");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!isMounted) {
|
||||||
|
return <div className="flex justify-center pt-10"><Loader2 className="h-8 w-8 animate-spin" /></div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user && isLoading) {
|
||||||
|
return <div className="flex justify-center pt-10"><Loader2 className="h-8 w-8 animate-spin" /></div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return <div className="text-center pt-10">Kullanıcı bilgileri yüklenemedi.</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="max-w-4xl mx-auto space-y-8">
|
||||||
|
<h1 className="text-3xl font-bold tracking-tight">Profilim</h1>
|
||||||
|
|
||||||
|
{/* Profile Info & Edit */}
|
||||||
|
<div className="grid gap-6 md:grid-cols-2">
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Profil Bilgileri</CardTitle>
|
||||||
|
<CardDescription>Kişisel bilgilerinizi buradan güncelleyebilirsiniz.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-6">
|
||||||
|
<div className="flex flex-col items-center space-y-4">
|
||||||
|
<div className="relative">
|
||||||
|
<Avatar className="h-24 w-24 border-2 border-border">
|
||||||
|
<AvatarImage src={file ? URL.createObjectURL(file) : getAvatarUrl(user.avatar_url)} />
|
||||||
|
<AvatarFallback className="text-xl font-bold">
|
||||||
|
{user.username.slice(0, 2).toUpperCase()}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
variant="secondary"
|
||||||
|
className="absolute bottom-0 right-0 h-8 w-8 rounded-full shadow-md"
|
||||||
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
>
|
||||||
|
<Camera className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
ref={fileInputRef}
|
||||||
|
className="hidden"
|
||||||
|
accept="image/*"
|
||||||
|
onChange={handleAvatarChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="text-center">
|
||||||
|
<p className="font-semibold text-lg">{user.username}</p>
|
||||||
|
<p className="text-sm text-muted-foreground">{user.email}</p>
|
||||||
|
<div className="mt-2 flex items-center justify-center gap-2">
|
||||||
|
{user.roles.map(role => (
|
||||||
|
<span key={role.id} className="inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 border-transparent bg-primary text-primary-foreground hover:bg-primary/80">
|
||||||
|
{role.name}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
{user.is_oauth_user ? (
|
||||||
|
<span className="inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors border-transparent bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300">
|
||||||
|
OAuth
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
user.email_verified && <span className="inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors border-transparent bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300">
|
||||||
|
Email Onaylı
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="username">Kullanıcı Adı</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<UserIcon className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
|
||||||
|
<Input
|
||||||
|
id="username"
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
className="pl-9"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter>
|
||||||
|
<Button onClick={handleProfileUpdate} disabled={isLoading}>
|
||||||
|
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||||
|
Güncelle
|
||||||
|
</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Security Settings - Only for non-OAuth users */}
|
||||||
|
{!user.is_oauth_user && (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{/* Change Password */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<Shield className="h-5 w-5" /> Şifre Değiştir
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>Güvenliğiniz için güçlü bir şifre kullanın.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="current-password">Mevcut Şifre</Label>
|
||||||
|
<Input
|
||||||
|
id="current-password"
|
||||||
|
type="password"
|
||||||
|
value={currentPassword}
|
||||||
|
onChange={(e) => setCurrentPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="new-password">Yeni Şifre</Label>
|
||||||
|
<Input
|
||||||
|
id="new-password"
|
||||||
|
type="password"
|
||||||
|
value={newPassword}
|
||||||
|
onChange={(e) => setNewPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter>
|
||||||
|
<Button onClick={handleChangePassword} disabled={isLoading} variant="outline">
|
||||||
|
Şifreyi Değiştir
|
||||||
|
</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Change Email */}
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<Mail className="h-5 w-5" /> Email Değiştir
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>Email adresinizi değiştirirseniz yeniden doğrulama yapmanız gerekir.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="new-email">Yeni Email Adresi</Label>
|
||||||
|
<Input
|
||||||
|
id="new-email"
|
||||||
|
type="email"
|
||||||
|
value={newEmail}
|
||||||
|
onChange={(e) => setNewEmail(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="email-password">Şifreniz (Onay için)</Label>
|
||||||
|
<Input
|
||||||
|
id="email-password"
|
||||||
|
type="password"
|
||||||
|
value={emailPassword}
|
||||||
|
onChange={(e) => setEmailPassword(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
<CardFooter>
|
||||||
|
<Button onClick={handleChangeEmail} disabled={isLoading} variant="outline">
|
||||||
|
Email'i Güncelle
|
||||||
|
</Button>
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* OAuth Info - Only for OAuth users */}
|
||||||
|
{user.is_oauth_user && (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>Bağlı Hesaplar</CardTitle>
|
||||||
|
<CardDescription>Hesabınız aşağıdaki sosyal medya platformlarına bağlıdır.</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="flex gap-4">
|
||||||
|
{user.social_accounts?.map((account) => (
|
||||||
|
<div key={account.id} className="flex items-center gap-3 p-3 border rounded-lg bg-muted/50 w-full">
|
||||||
|
<div className="h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center">
|
||||||
|
{account.provider === 'google' ? 'G' : account.provider.charAt(0).toUpperCase()}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="font-medium capitalize">{account.provider}</p>
|
||||||
|
<p className="text-xs text-muted-foreground">{account.email}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
{(!user.social_accounts || user.social_accounts.length === 0) && (
|
||||||
|
<p className="text-sm text-muted-foreground">Bağlı hesap bilgisi bulunamadı (OAuth User flag true olmasına rağmen).</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
BIN
app/favicon.ico
Normal file
BIN
app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
125
app/globals.css
Normal file
125
app/globals.css
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
@import "tw-animate-css";
|
||||||
|
|
||||||
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--font-sans: var(--font-geist-sans);
|
||||||
|
--font-mono: var(--font-geist-mono);
|
||||||
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
|
--color-sidebar-accent: var(--sidebar-accent);
|
||||||
|
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||||
|
--color-sidebar-primary: var(--sidebar-primary);
|
||||||
|
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||||
|
--color-sidebar: var(--sidebar);
|
||||||
|
--color-chart-5: var(--chart-5);
|
||||||
|
--color-chart-4: var(--chart-4);
|
||||||
|
--color-chart-3: var(--chart-3);
|
||||||
|
--color-chart-2: var(--chart-2);
|
||||||
|
--color-chart-1: var(--chart-1);
|
||||||
|
--color-ring: var(--ring);
|
||||||
|
--color-input: var(--input);
|
||||||
|
--color-border: var(--border);
|
||||||
|
--color-destructive: var(--destructive);
|
||||||
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
|
--color-accent: var(--accent);
|
||||||
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
|
--color-muted: var(--muted);
|
||||||
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
|
--color-secondary: var(--secondary);
|
||||||
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
|
--color-primary: var(--primary);
|
||||||
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
|
--color-popover: var(--popover);
|
||||||
|
--color-card-foreground: var(--card-foreground);
|
||||||
|
--color-card: var(--card);
|
||||||
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
|
--radius-lg: var(--radius);
|
||||||
|
--radius-xl: calc(var(--radius) + 4px);
|
||||||
|
--radius-2xl: calc(var(--radius) + 8px);
|
||||||
|
--radius-3xl: calc(var(--radius) + 12px);
|
||||||
|
--radius-4xl: calc(var(--radius) + 16px);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--radius: 0.625rem;
|
||||||
|
--background: oklch(1 0 0);
|
||||||
|
--foreground: oklch(0.145 0 0);
|
||||||
|
--card: oklch(1 0 0);
|
||||||
|
--card-foreground: oklch(0.145 0 0);
|
||||||
|
--popover: oklch(1 0 0);
|
||||||
|
--popover-foreground: oklch(0.145 0 0);
|
||||||
|
--primary: oklch(0.205 0 0);
|
||||||
|
--primary-foreground: oklch(0.985 0 0);
|
||||||
|
--secondary: oklch(0.97 0 0);
|
||||||
|
--secondary-foreground: oklch(0.205 0 0);
|
||||||
|
--muted: oklch(0.97 0 0);
|
||||||
|
--muted-foreground: oklch(0.556 0 0);
|
||||||
|
--accent: oklch(0.97 0 0);
|
||||||
|
--accent-foreground: oklch(0.205 0 0);
|
||||||
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
|
--border: oklch(0.922 0 0);
|
||||||
|
--input: oklch(0.922 0 0);
|
||||||
|
--ring: oklch(0.708 0 0);
|
||||||
|
--chart-1: oklch(0.646 0.222 41.116);
|
||||||
|
--chart-2: oklch(0.6 0.118 184.704);
|
||||||
|
--chart-3: oklch(0.398 0.07 227.392);
|
||||||
|
--chart-4: oklch(0.828 0.189 84.429);
|
||||||
|
--chart-5: oklch(0.769 0.188 70.08);
|
||||||
|
--sidebar: oklch(0.985 0 0);
|
||||||
|
--sidebar-foreground: oklch(0.145 0 0);
|
||||||
|
--sidebar-primary: oklch(0.205 0 0);
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-accent: oklch(0.97 0 0);
|
||||||
|
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||||
|
--sidebar-border: oklch(0.922 0 0);
|
||||||
|
--sidebar-ring: oklch(0.708 0 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
--background: oklch(0.145 0 0);
|
||||||
|
--foreground: oklch(0.985 0 0);
|
||||||
|
--card: oklch(0.205 0 0);
|
||||||
|
--card-foreground: oklch(0.985 0 0);
|
||||||
|
--popover: oklch(0.205 0 0);
|
||||||
|
--popover-foreground: oklch(0.985 0 0);
|
||||||
|
--primary: oklch(0.922 0 0);
|
||||||
|
--primary-foreground: oklch(0.205 0 0);
|
||||||
|
--secondary: oklch(0.269 0 0);
|
||||||
|
--secondary-foreground: oklch(0.985 0 0);
|
||||||
|
--muted: oklch(0.269 0 0);
|
||||||
|
--muted-foreground: oklch(0.708 0 0);
|
||||||
|
--accent: oklch(0.269 0 0);
|
||||||
|
--accent-foreground: oklch(0.985 0 0);
|
||||||
|
--destructive: oklch(0.704 0.191 22.216);
|
||||||
|
--border: oklch(1 0 0 / 10%);
|
||||||
|
--input: oklch(1 0 0 / 15%);
|
||||||
|
--ring: oklch(0.556 0 0);
|
||||||
|
--chart-1: oklch(0.488 0.243 264.376);
|
||||||
|
--chart-2: oklch(0.696 0.17 162.48);
|
||||||
|
--chart-3: oklch(0.769 0.188 70.08);
|
||||||
|
--chart-4: oklch(0.627 0.265 303.9);
|
||||||
|
--chart-5: oklch(0.645 0.246 16.439);
|
||||||
|
--sidebar: oklch(0.205 0 0);
|
||||||
|
--sidebar-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-accent: oklch(0.269 0 0);
|
||||||
|
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||||
|
--sidebar-border: oklch(1 0 0 / 10%);
|
||||||
|
--sidebar-ring: oklch(0.556 0 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
* {
|
||||||
|
@apply border-border outline-ring/50;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
@apply bg-background text-foreground;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/layout.tsx
Normal file
37
app/layout.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import { Inter } from "next/font/google";
|
||||||
|
import "./globals.css";
|
||||||
|
import StoreProvider from "@/components/StoreProvider";
|
||||||
|
import { ThemeProvider } from "@/components/theme-provider";
|
||||||
|
import { Header } from "@/components/header/header";
|
||||||
|
|
||||||
|
const inter = Inter({ subsets: ["latin"] });
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Next Go Blog",
|
||||||
|
description: "Advanced blog application",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html lang="en" suppressHydrationWarning>
|
||||||
|
<body className={`${inter.className} antialiased`}>
|
||||||
|
<StoreProvider>
|
||||||
|
<ThemeProvider
|
||||||
|
attribute="class"
|
||||||
|
defaultTheme="system"
|
||||||
|
enableSystem
|
||||||
|
disableTransitionOnChange
|
||||||
|
>
|
||||||
|
<Header />
|
||||||
|
<main className="min-h-screen bg-background">{children}</main>
|
||||||
|
</ThemeProvider>
|
||||||
|
</StoreProvider>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
65
app/page.tsx
Normal file
65
app/page.tsx
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||||
|
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||||
|
<Image
|
||||||
|
className="dark:invert"
|
||||||
|
src="/next.svg"
|
||||||
|
alt="Next.js logo"
|
||||||
|
width={100}
|
||||||
|
height={20}
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
||||||
|
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
||||||
|
To get started, edit the page.tsx file.
|
||||||
|
</h1>
|
||||||
|
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
||||||
|
Looking for a starting point or more instructions? Head over to{" "}
|
||||||
|
<a
|
||||||
|
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||||
|
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||||
|
>
|
||||||
|
Templates
|
||||||
|
</a>{" "}
|
||||||
|
or the{" "}
|
||||||
|
<a
|
||||||
|
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||||
|
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||||
|
>
|
||||||
|
Learning
|
||||||
|
</a>{" "}
|
||||||
|
center.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
||||||
|
<a
|
||||||
|
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
||||||
|
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
className="dark:invert"
|
||||||
|
src="/vercel.svg"
|
||||||
|
alt="Vercel logomark"
|
||||||
|
width={16}
|
||||||
|
height={16}
|
||||||
|
/>
|
||||||
|
Deploy Now
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||||
|
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
Documentation
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
23
components.json
Normal file
23
components.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://ui.shadcn.com/schema.json",
|
||||||
|
"style": "new-york",
|
||||||
|
"rsc": true,
|
||||||
|
"tsx": true,
|
||||||
|
"tailwind": {
|
||||||
|
"config": "",
|
||||||
|
"css": "app/globals.css",
|
||||||
|
"baseColor": "neutral",
|
||||||
|
"cssVariables": true,
|
||||||
|
"prefix": ""
|
||||||
|
},
|
||||||
|
"iconLibrary": "lucide",
|
||||||
|
"rtl": false,
|
||||||
|
"aliases": {
|
||||||
|
"components": "@/components",
|
||||||
|
"utils": "@/lib/utils",
|
||||||
|
"ui": "@/components/ui",
|
||||||
|
"lib": "@/lib",
|
||||||
|
"hooks": "@/hooks"
|
||||||
|
},
|
||||||
|
"registries": {}
|
||||||
|
}
|
||||||
21
components/StoreProvider.tsx
Normal file
21
components/StoreProvider.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
"use client";
|
||||||
|
import { useRef } from "react";
|
||||||
|
import { Provider } from "react-redux";
|
||||||
|
import { makeStore, AppStore } from "@/lib/store";
|
||||||
|
import { restoreSession } from "@/lib/features/auth/authSlice";
|
||||||
|
|
||||||
|
export default function StoreProvider({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const storeRef = useRef<AppStore>(null);
|
||||||
|
if (!storeRef.current) {
|
||||||
|
// Create the store instance the first time this renders
|
||||||
|
storeRef.current = makeStore();
|
||||||
|
// Restore session from localStorage
|
||||||
|
storeRef.current.dispatch(restoreSession());
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Provider store={storeRef.current}>{children}</Provider>;
|
||||||
|
}
|
||||||
106
components/app-sidebar.tsx
Normal file
106
components/app-sidebar.tsx
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { Home, Users, Settings, LogOut, Shield } from "lucide-react"
|
||||||
|
import Link from "next/link"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
|
||||||
|
import {
|
||||||
|
Sidebar,
|
||||||
|
SidebarContent,
|
||||||
|
SidebarFooter,
|
||||||
|
SidebarGroup,
|
||||||
|
SidebarGroupContent,
|
||||||
|
SidebarGroupLabel,
|
||||||
|
SidebarMenu,
|
||||||
|
SidebarMenuButton,
|
||||||
|
SidebarMenuItem,
|
||||||
|
SidebarHeader,
|
||||||
|
} from "@/components/ui/sidebar"
|
||||||
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks"
|
||||||
|
import { logout } from "@/lib/features/auth/authSlice"
|
||||||
|
|
||||||
|
// Menu items.
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
|
title: "Genel Bakış",
|
||||||
|
url: "/admin",
|
||||||
|
icon: Home,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Kullanıcılar",
|
||||||
|
url: "/admin/users",
|
||||||
|
icon: Users,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Ayarlar",
|
||||||
|
url: "/admin/settings",
|
||||||
|
icon: Settings,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "CORS Ayarları",
|
||||||
|
url: "/admin/cors",
|
||||||
|
icon: Shield,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export function AppSidebar() {
|
||||||
|
const pathname = usePathname()
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
const user = useAppSelector((state) => state.auth.user)
|
||||||
|
const isAdmin = user?.roles?.some((r: any) => r.name === "admin")
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sidebar className="top-14 h-[calc(100svh-3.5rem)]">
|
||||||
|
<SidebarHeader className="p-4 md:hidden">
|
||||||
|
<Link href="/" className="font-bold text-lg">NextGoBlog</Link>
|
||||||
|
</SidebarHeader>
|
||||||
|
<SidebarContent>
|
||||||
|
{isAdmin && (
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupLabel>Admin Panel</SidebarGroupLabel>
|
||||||
|
<SidebarGroupContent>
|
||||||
|
<SidebarMenu>
|
||||||
|
{items.map((item) => (
|
||||||
|
<SidebarMenuItem key={item.title}>
|
||||||
|
<SidebarMenuButton asChild isActive={pathname === item.url}>
|
||||||
|
<Link href={item.url}>
|
||||||
|
<item.icon />
|
||||||
|
<span>{item.title}</span>
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
))}
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarGroupContent>
|
||||||
|
</SidebarGroup>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupLabel>Hesabım</SidebarGroupLabel>
|
||||||
|
<SidebarGroupContent>
|
||||||
|
<SidebarMenu>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton asChild isActive={pathname === "/profile"}>
|
||||||
|
<Link href="/profile">
|
||||||
|
<Users className="h-4 w-4" />
|
||||||
|
<span>Profilim</span>
|
||||||
|
</Link>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarGroupContent>
|
||||||
|
</SidebarGroup>
|
||||||
|
</SidebarContent>
|
||||||
|
<SidebarFooter>
|
||||||
|
<SidebarMenu>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton onClick={() => dispatch(logout())}>
|
||||||
|
<LogOut />
|
||||||
|
<span>Çıkış Yap</span>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarFooter>
|
||||||
|
</Sidebar>
|
||||||
|
)
|
||||||
|
}
|
||||||
107
components/cors/cors-dialog.tsx
Normal file
107
components/cors/cors-dialog.tsx
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { CorsEntry } from "@/lib/features/cors/corsSlice";
|
||||||
|
|
||||||
|
interface CorsDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
type: "whitelist" | "blacklist";
|
||||||
|
entry: CorsEntry | null;
|
||||||
|
onSubmit: (origin: string, note: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CorsDialog({ open, onOpenChange, type, entry, onSubmit }: CorsDialogProps) {
|
||||||
|
const [origin, setOrigin] = useState("");
|
||||||
|
const [note, setNote] = useState(""); // Description or Reason
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
if (entry) {
|
||||||
|
setOrigin(entry.origin);
|
||||||
|
setNote(type === "whitelist" ? (entry.description || "") : (entry.reason || ""));
|
||||||
|
} else {
|
||||||
|
setOrigin("");
|
||||||
|
setNote("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [open, entry, type]);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
await onSubmit(origin, note);
|
||||||
|
onOpenChange(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const isEdit = !!entry;
|
||||||
|
const typeLabel = type === "whitelist" ? "Whitelist" : "Blacklist";
|
||||||
|
const noteLabel = type === "whitelist" ? "Açıklama" : "Sebep";
|
||||||
|
const title = `${typeLabel} ${isEdit ? "Düzenle" : "Ekle"}`;
|
||||||
|
const description = isEdit
|
||||||
|
? "Mevcut kaydı düzenleyin."
|
||||||
|
: "Listeye yeni bir domain ekleyin.";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{title}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
{description}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="grid gap-4 py-4">
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="origin" className="text-right">
|
||||||
|
Origin
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="origin"
|
||||||
|
placeholder="https://example.com"
|
||||||
|
className="col-span-3"
|
||||||
|
value={origin}
|
||||||
|
onChange={(e) => setOrigin(e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="note" className="text-right">
|
||||||
|
{noteLabel}
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="note"
|
||||||
|
placeholder={noteLabel}
|
||||||
|
className="col-span-3"
|
||||||
|
value={note}
|
||||||
|
onChange={(e) => setNote(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
99
components/cors/cors-edit-dialog.tsx
Normal file
99
components/cors/cors-edit-dialog.tsx
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { CorsEntry } from "@/lib/features/cors/corsSlice";
|
||||||
|
|
||||||
|
interface CorsEditDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
entry: CorsEntry | null;
|
||||||
|
type: "whitelist" | "blacklist";
|
||||||
|
onUpdate: (id: string, origin: string, note: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CorsEditDialog({ open, onOpenChange, entry, type, onUpdate }: CorsEditDialogProps) {
|
||||||
|
const [origin, setOrigin] = useState("");
|
||||||
|
const [note, setNote] = useState(""); // Description or Reason
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (entry) {
|
||||||
|
setOrigin(entry.origin);
|
||||||
|
setNote(entry.description || entry.reason || "");
|
||||||
|
}
|
||||||
|
}, [entry]);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!entry) return;
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
await onUpdate(entry.id, origin, note);
|
||||||
|
onOpenChange(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const typeLabel = type === "whitelist" ? "Whitelist" : "Blacklist";
|
||||||
|
const noteLabel = type === "whitelist" ? "Açıklama" : "Sebep";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{typeLabel} Güncelle</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Mevcut kaydı düzenleyin.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="grid gap-4 py-4">
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="edit-origin" className="text-right">
|
||||||
|
Origin
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="edit-origin"
|
||||||
|
placeholder="https://example.com"
|
||||||
|
className="col-span-3"
|
||||||
|
value={origin}
|
||||||
|
onChange={(e) => setOrigin(e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="edit-note" className="text-right">
|
||||||
|
{noteLabel}
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="edit-note"
|
||||||
|
placeholder={noteLabel}
|
||||||
|
className="col-span-3"
|
||||||
|
value={note}
|
||||||
|
onChange={(e) => setNote(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Güncelleniyor..." : "Güncelle"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
93
components/cors/cors-table.tsx
Normal file
93
components/cors/cors-table.tsx
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Switch } from "@/components/ui/switch";
|
||||||
|
import { Trash2, Edit } from "lucide-react";
|
||||||
|
import { CorsEntry } from "@/lib/features/cors/corsSlice";
|
||||||
|
|
||||||
|
interface CorsTableProps {
|
||||||
|
data: CorsEntry[];
|
||||||
|
type: "whitelist" | "blacklist";
|
||||||
|
onDelete: (id: string) => void;
|
||||||
|
onEdit: (entry: CorsEntry) => void;
|
||||||
|
onToggleActive: (id: string, currentStatus: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CorsTable({ data, type, onDelete, onEdit, onToggleActive }: CorsTableProps) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Origin</TableHead>
|
||||||
|
<TableHead>{type === "whitelist" ? "Açıklama" : "Sebep"}</TableHead>
|
||||||
|
<TableHead>Durum</TableHead>
|
||||||
|
<TableHead>Oluşturan</TableHead>
|
||||||
|
<TableHead className="text-right">İşlemler</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{data.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} className="h-24 text-center text-muted-foreground">
|
||||||
|
Kayıt bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
data.map((entry) => (
|
||||||
|
<TableRow key={entry.id}>
|
||||||
|
<TableCell className="font-medium">{entry.origin}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{type === "whitelist" ? entry.description : entry.reason}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Switch
|
||||||
|
checked={entry.is_active}
|
||||||
|
onCheckedChange={() => onToggleActive(entry.id, entry.is_active)}
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{entry.is_active ? "Aktif" : "Pasif"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-muted-foreground text-sm">
|
||||||
|
{entry.created_by}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right space-x-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8"
|
||||||
|
onClick={() => onEdit(entry)}
|
||||||
|
title="Düzenle"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Düzenle</span>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||||
|
onClick={() => onDelete(entry.id)}
|
||||||
|
title="Sil"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Sil</span>
|
||||||
|
</Button>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
172
components/header/header.tsx
Normal file
172
components/header/header.tsx
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useTheme } from "next-themes";
|
||||||
|
import { useAppSelector, useAppDispatch } from "@/lib/hooks";
|
||||||
|
import { logout } from "@/lib/features/auth/authSlice";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { Sun, Moon, LogOut, User, LayoutDashboard, Menu } from "lucide-react";
|
||||||
|
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { getAvatarUrl } from "@/lib/utils";
|
||||||
|
|
||||||
|
export function Header() {
|
||||||
|
const { setTheme, theme } = useTheme();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { isAuthenticated, user } = useAppSelector((state) => state.auth);
|
||||||
|
const [mounted, setMounted] = useState(false);
|
||||||
|
|
||||||
|
// Prevent hydration mismatch
|
||||||
|
useEffect(() => {
|
||||||
|
setMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
dispatch(logout());
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!mounted) {
|
||||||
|
return (
|
||||||
|
<header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
||||||
|
<div className="container flex h-14 items-center pl-10 pr-10">
|
||||||
|
<div className="mr-4 hidden md:flex">
|
||||||
|
<Link href="/" className="mr-6 flex items-center space-x-2">
|
||||||
|
<span className="hidden font-bold sm:inline-block">
|
||||||
|
NextGoBlog
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
<nav className="flex items-center space-x-6 text-sm font-medium">
|
||||||
|
<Link href="/blog">Blog</Link>
|
||||||
|
<Link href="/about">Hakkında</Link>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-1 items-center justify-end space-x-2">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button variant="ghost" asChild>
|
||||||
|
<Link href="/login">Giriş Yap</Link>
|
||||||
|
</Button>
|
||||||
|
<Button asChild>
|
||||||
|
<Link href="/register">Kayıt Ol</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
||||||
|
<div className="container flex h-14 items-center pl-10 pr-10">
|
||||||
|
{/* Desktop Interface */}
|
||||||
|
<div className="mr-4 hidden md:flex">
|
||||||
|
<Link href="/" className="mr-6 flex items-center space-x-2">
|
||||||
|
<span className="hidden font-bold sm:inline-block">
|
||||||
|
NextGoBlog
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
<nav className="flex items-center space-x-6 text-sm font-medium">
|
||||||
|
<Link href="/blog">Blog</Link>
|
||||||
|
<Link href="/about">Hakkında</Link>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile Interface */}
|
||||||
|
<Sheet>
|
||||||
|
<SheetTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
className="mr-2 px-0 text-base hover:bg-transparent focus-visible:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 md:hidden"
|
||||||
|
>
|
||||||
|
<Menu className="h-5 w-5" />
|
||||||
|
<span className="sr-only">Toggle Menu</span>
|
||||||
|
</Button>
|
||||||
|
</SheetTrigger>
|
||||||
|
<SheetContent side="left" className="pr-0">
|
||||||
|
<Link href="/" className="flex items-center">
|
||||||
|
<span className="font-bold">NextGoBlog</span>
|
||||||
|
</Link>
|
||||||
|
<nav className="mt-8 flex flex-col gap-4">
|
||||||
|
<Link href="/blog">Blog</Link>
|
||||||
|
<Link href="/about">Hakkında</Link>
|
||||||
|
</nav>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
|
||||||
|
{/* Right Side */}
|
||||||
|
<div className="flex flex-1 items-center justify-end space-x-2">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
|
||||||
|
>
|
||||||
|
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||||
|
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||||
|
<span className="sr-only">Toggle theme</span>
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{isAuthenticated ? (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="relative h-8 w-8 rounded-full">
|
||||||
|
<Avatar className="h-8 w-8">
|
||||||
|
<AvatarImage src={getAvatarUrl(user?.avatar_url)} alt={user?.username} />
|
||||||
|
<AvatarFallback>{user?.username?.slice(0, 2).toUpperCase()}</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent className="w-56" align="end" forceMount>
|
||||||
|
<DropdownMenuLabel className="font-normal">
|
||||||
|
<div className="flex flex-col space-y-1">
|
||||||
|
<p className="text-sm font-medium leading-none">{user?.username}</p>
|
||||||
|
<p className="text-xs leading-none text-muted-foreground">
|
||||||
|
{user?.email}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
{user?.roles?.some((r: any) => r.name === "admin") && (
|
||||||
|
<DropdownMenuItem asChild>
|
||||||
|
<Link href="/admin">
|
||||||
|
<LayoutDashboard className="mr-2 h-4 w-4" />
|
||||||
|
<span>Admin Panel</span>
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
<DropdownMenuItem asChild>
|
||||||
|
<Link href="/profile">
|
||||||
|
<User className="mr-2 h-4 w-4" />
|
||||||
|
<span>Profil</span>
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem onClick={handleLogout}>
|
||||||
|
<LogOut className="mr-2 h-4 w-4" />
|
||||||
|
<span>Çıkış Yap</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Button variant="ghost" asChild>
|
||||||
|
<Link href="/login">Giriş Yap</Link>
|
||||||
|
</Button>
|
||||||
|
<Button asChild>
|
||||||
|
<Link href="/register">Kayıt Ol</Link>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
11
components/theme-provider.tsx
Normal file
11
components/theme-provider.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
||||||
|
|
||||||
|
export function ThemeProvider({
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof NextThemesProvider>) {
|
||||||
|
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
|
||||||
|
}
|
||||||
109
components/ui/avatar.tsx
Normal file
109
components/ui/avatar.tsx
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Avatar as AvatarPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Avatar({
|
||||||
|
className,
|
||||||
|
size = "default",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AvatarPrimitive.Root> & {
|
||||||
|
size?: "default" | "sm" | "lg"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<AvatarPrimitive.Root
|
||||||
|
data-slot="avatar"
|
||||||
|
data-size={size}
|
||||||
|
className={cn(
|
||||||
|
"group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AvatarImage({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||||
|
return (
|
||||||
|
<AvatarPrimitive.Image
|
||||||
|
data-slot="avatar-image"
|
||||||
|
className={cn("aspect-square size-full", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AvatarFallback({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||||
|
return (
|
||||||
|
<AvatarPrimitive.Fallback
|
||||||
|
data-slot="avatar-fallback"
|
||||||
|
className={cn(
|
||||||
|
"bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-slot="avatar-badge"
|
||||||
|
className={cn(
|
||||||
|
"bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full ring-2 select-none",
|
||||||
|
"group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
|
||||||
|
"group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
|
||||||
|
"group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="avatar-group"
|
||||||
|
className={cn(
|
||||||
|
"*:data-[slot=avatar]:ring-background group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AvatarGroupCount({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="avatar-group-count"
|
||||||
|
className={cn(
|
||||||
|
"bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Avatar,
|
||||||
|
AvatarImage,
|
||||||
|
AvatarFallback,
|
||||||
|
AvatarBadge,
|
||||||
|
AvatarGroup,
|
||||||
|
AvatarGroupCount,
|
||||||
|
}
|
||||||
36
components/ui/badge.tsx
Normal file
36
components/ui/badge.tsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const badgeVariants = cva(
|
||||||
|
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default:
|
||||||
|
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
||||||
|
secondary:
|
||||||
|
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
|
destructive:
|
||||||
|
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
||||||
|
outline: "text-foreground",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export interface BadgeProps
|
||||||
|
extends React.HTMLAttributes<HTMLDivElement>,
|
||||||
|
VariantProps<typeof badgeVariants> { }
|
||||||
|
|
||||||
|
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Badge, badgeVariants }
|
||||||
115
components/ui/breadcrumb.tsx
Normal file
115
components/ui/breadcrumb.tsx
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { ChevronRight, MoreHorizontal } from "lucide-react"
|
||||||
|
import { Slot } from "@radix-ui/react-slot"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Breadcrumb = React.forwardRef<
|
||||||
|
HTMLElement,
|
||||||
|
React.ComponentPropsWithoutRef<"nav"> & {
|
||||||
|
separator?: React.ReactNode
|
||||||
|
}
|
||||||
|
>(({ ...props }, ref) => <nav ref={ref} aria-label="breadcrumb" {...props} />)
|
||||||
|
Breadcrumb.displayName = "Breadcrumb"
|
||||||
|
|
||||||
|
const BreadcrumbList = React.forwardRef<
|
||||||
|
HTMLOListElement,
|
||||||
|
React.ComponentPropsWithoutRef<"ol">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<ol
|
||||||
|
ref={ref}
|
||||||
|
className={cn(
|
||||||
|
"flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
BreadcrumbList.displayName = "BreadcrumbList"
|
||||||
|
|
||||||
|
const BreadcrumbItem = React.forwardRef<
|
||||||
|
HTMLLIElement,
|
||||||
|
React.ComponentPropsWithoutRef<"li">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<li
|
||||||
|
ref={ref}
|
||||||
|
className={cn("inline-flex items-center gap-1.5", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
BreadcrumbItem.displayName = "BreadcrumbItem"
|
||||||
|
|
||||||
|
const BreadcrumbLink = React.forwardRef<
|
||||||
|
HTMLAnchorElement,
|
||||||
|
React.ComponentPropsWithoutRef<"a"> & {
|
||||||
|
asChild?: boolean
|
||||||
|
}
|
||||||
|
>(({ asChild, className, ...props }, ref) => {
|
||||||
|
const Comp = asChild ? Slot : "a"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
ref={ref}
|
||||||
|
className={cn("transition-colors hover:text-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
BreadcrumbLink.displayName = "BreadcrumbLink"
|
||||||
|
|
||||||
|
const BreadcrumbPage = React.forwardRef<
|
||||||
|
HTMLSpanElement,
|
||||||
|
React.ComponentPropsWithoutRef<"span">
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<span
|
||||||
|
ref={ref}
|
||||||
|
role="link"
|
||||||
|
aria-disabled="true"
|
||||||
|
aria-current="page"
|
||||||
|
className={cn("font-normal text-foreground", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
BreadcrumbPage.displayName = "BreadcrumbPage"
|
||||||
|
|
||||||
|
const BreadcrumbSeparator = ({
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"li">) => (
|
||||||
|
<li
|
||||||
|
role="presentation"
|
||||||
|
aria-hidden="true"
|
||||||
|
className={cn("[&>svg]:size-3.5", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children ?? <ChevronRight />}
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
BreadcrumbSeparator.displayName = "BreadcrumbSeparator"
|
||||||
|
|
||||||
|
const BreadcrumbEllipsis = ({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) => (
|
||||||
|
<span
|
||||||
|
role="presentation"
|
||||||
|
aria-hidden="true"
|
||||||
|
className={cn("flex h-9 w-9 items-center justify-center", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
<span className="sr-only">More</span>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
BreadcrumbEllipsis.displayName = "BreadcrumbEllipsis"
|
||||||
|
|
||||||
|
export {
|
||||||
|
Breadcrumb,
|
||||||
|
BreadcrumbList,
|
||||||
|
BreadcrumbItem,
|
||||||
|
BreadcrumbLink,
|
||||||
|
BreadcrumbPage,
|
||||||
|
BreadcrumbSeparator,
|
||||||
|
BreadcrumbEllipsis,
|
||||||
|
}
|
||||||
64
components/ui/button.tsx
Normal file
64
components/ui/button.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
import { Slot } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const buttonVariants = cva(
|
||||||
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
|
destructive:
|
||||||
|
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
|
outline:
|
||||||
|
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||||
|
secondary:
|
||||||
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
|
ghost:
|
||||||
|
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||||
|
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||||
|
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||||
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||||
|
icon: "size-9",
|
||||||
|
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
||||||
|
"icon-sm": "size-8",
|
||||||
|
"icon-lg": "size-10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function Button({
|
||||||
|
className,
|
||||||
|
variant = "default",
|
||||||
|
size = "default",
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> &
|
||||||
|
VariantProps<typeof buttonVariants> & {
|
||||||
|
asChild?: boolean
|
||||||
|
}) {
|
||||||
|
const Comp = asChild ? Slot.Root : "button"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="button"
|
||||||
|
data-variant={variant}
|
||||||
|
data-size={size}
|
||||||
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Button, buttonVariants }
|
||||||
92
components/ui/card.tsx
Normal file
92
components/ui/card.tsx
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card"
|
||||||
|
className={cn(
|
||||||
|
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-header"
|
||||||
|
className={cn(
|
||||||
|
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-title"
|
||||||
|
className={cn("leading-none font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-description"
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-action"
|
||||||
|
className={cn(
|
||||||
|
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-content"
|
||||||
|
className={cn("px-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-footer"
|
||||||
|
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Card,
|
||||||
|
CardHeader,
|
||||||
|
CardFooter,
|
||||||
|
CardTitle,
|
||||||
|
CardAction,
|
||||||
|
CardDescription,
|
||||||
|
CardContent,
|
||||||
|
}
|
||||||
158
components/ui/dialog.tsx
Normal file
158
components/ui/dialog.tsx
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { XIcon } from "lucide-react"
|
||||||
|
import { Dialog as DialogPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
|
function Dialog({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||||
|
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||||
|
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||||
|
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogClose({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||||
|
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogOverlay({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Overlay
|
||||||
|
data-slot="dialog-overlay"
|
||||||
|
className={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
showCloseButton = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DialogPortal data-slot="dialog-portal">
|
||||||
|
<DialogOverlay />
|
||||||
|
<DialogPrimitive.Content
|
||||||
|
data-slot="dialog-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showCloseButton && (
|
||||||
|
<DialogPrimitive.Close
|
||||||
|
data-slot="dialog-close"
|
||||||
|
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||||
|
>
|
||||||
|
<XIcon />
|
||||||
|
<span className="sr-only">Close</span>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</DialogPrimitive.Content>
|
||||||
|
</DialogPortal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="dialog-header"
|
||||||
|
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogFooter({
|
||||||
|
className,
|
||||||
|
showCloseButton = false,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & {
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="dialog-footer"
|
||||||
|
className={cn(
|
||||||
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showCloseButton && (
|
||||||
|
<DialogPrimitive.Close asChild>
|
||||||
|
<Button variant="outline">Close</Button>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Title
|
||||||
|
data-slot="dialog-title"
|
||||||
|
className={cn("text-lg leading-none font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DialogDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||||
|
return (
|
||||||
|
<DialogPrimitive.Description
|
||||||
|
data-slot="dialog-description"
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogOverlay,
|
||||||
|
DialogPortal,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
}
|
||||||
257
components/ui/dropdown-menu.tsx
Normal file
257
components/ui/dropdown-menu.tsx
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||||
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function DropdownMenu({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||||
|
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Trigger
|
||||||
|
data-slot="dropdown-menu-trigger"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuContent({
|
||||||
|
className,
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.Content
|
||||||
|
data-slot="dropdown-menu-content"
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuItem({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
variant = "default",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||||
|
inset?: boolean
|
||||||
|
variant?: "default" | "destructive"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Item
|
||||||
|
data-slot="dropdown-menu-item"
|
||||||
|
data-inset={inset}
|
||||||
|
data-variant={variant}
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuCheckboxItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
checked,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
|
data-slot="dropdown-menu-checkbox-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
checked={checked}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioGroup
|
||||||
|
data-slot="dropdown-menu-radio-group"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioItem
|
||||||
|
data-slot="dropdown-menu-radio-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CircleIcon className="size-2 fill-current" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuLabel({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||||
|
inset?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Label
|
||||||
|
data-slot="dropdown-menu-label"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Separator
|
||||||
|
data-slot="dropdown-menu-separator"
|
||||||
|
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuShortcut({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-slot="dropdown-menu-shortcut"
|
||||||
|
className={cn(
|
||||||
|
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSub({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||||
|
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubTrigger({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||||
|
inset?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
data-slot="dropdown-menu-sub-trigger"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronRightIcon className="ml-auto size-4" />
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
data-slot="dropdown-menu-sub-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuPortal,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
|
DropdownMenuRadioItem,
|
||||||
|
DropdownMenuSeparator,
|
||||||
|
DropdownMenuShortcut,
|
||||||
|
DropdownMenuSub,
|
||||||
|
DropdownMenuSubTrigger,
|
||||||
|
DropdownMenuSubContent,
|
||||||
|
}
|
||||||
21
components/ui/input.tsx
Normal file
21
components/ui/input.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type={type}
|
||||||
|
data-slot="input"
|
||||||
|
className={cn(
|
||||||
|
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
|
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||||
|
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Input }
|
||||||
24
components/ui/label.tsx
Normal file
24
components/ui/label.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Label as LabelPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Label({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<LabelPrimitive.Root
|
||||||
|
data-slot="label"
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Label }
|
||||||
190
components/ui/select.tsx
Normal file
190
components/ui/select.tsx
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||||
|
import { Select as SelectPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Select({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||||
|
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||||
|
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectValue({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||||
|
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectTrigger({
|
||||||
|
className,
|
||||||
|
size = "default",
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||||
|
size?: "sm" | "default"
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
data-slot="select-trigger"
|
||||||
|
data-size={size}
|
||||||
|
className={cn(
|
||||||
|
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<SelectPrimitive.Icon asChild>
|
||||||
|
<ChevronDownIcon className="size-4 opacity-50" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
position = "item-aligned",
|
||||||
|
align = "center",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
data-slot="select-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||||
|
position === "popper" &&
|
||||||
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
position={position}
|
||||||
|
align={align}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectPrimitive.Viewport
|
||||||
|
className={cn(
|
||||||
|
"p-1",
|
||||||
|
position === "popper" &&
|
||||||
|
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Label
|
||||||
|
data-slot="select-label"
|
||||||
|
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
data-slot="select-item"
|
||||||
|
className={cn(
|
||||||
|
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
data-slot="select-item-indicator"
|
||||||
|
className="absolute right-2 flex size-3.5 items-center justify-center"
|
||||||
|
>
|
||||||
|
<SelectPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Separator
|
||||||
|
data-slot="select-separator"
|
||||||
|
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollUpButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollUpButton
|
||||||
|
data-slot="select-scroll-up-button"
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronUpIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectScrollDownButton({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.ScrollDownButton
|
||||||
|
data-slot="select-scroll-down-button"
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center justify-center py-1",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<ChevronDownIcon className="size-4" />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
|
SelectScrollDownButton,
|
||||||
|
SelectScrollUpButton,
|
||||||
|
SelectSeparator,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
}
|
||||||
28
components/ui/separator.tsx
Normal file
28
components/ui/separator.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Separator as SeparatorPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Separator({
|
||||||
|
className,
|
||||||
|
orientation = "horizontal",
|
||||||
|
decorative = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<SeparatorPrimitive.Root
|
||||||
|
data-slot="separator"
|
||||||
|
decorative={decorative}
|
||||||
|
orientation={orientation}
|
||||||
|
className={cn(
|
||||||
|
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Separator }
|
||||||
143
components/ui/sheet.tsx
Normal file
143
components/ui/sheet.tsx
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { XIcon } from "lucide-react"
|
||||||
|
import { Dialog as SheetPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
||||||
|
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
||||||
|
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetClose({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
||||||
|
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
||||||
|
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetOverlay({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
|
||||||
|
return (
|
||||||
|
<SheetPrimitive.Overlay
|
||||||
|
data-slot="sheet-overlay"
|
||||||
|
className={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetContent({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
side = "right",
|
||||||
|
showCloseButton = true,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||||
|
side?: "top" | "right" | "bottom" | "left"
|
||||||
|
showCloseButton?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SheetPortal>
|
||||||
|
<SheetOverlay />
|
||||||
|
<SheetPrimitive.Content
|
||||||
|
data-slot="sheet-content"
|
||||||
|
className={cn(
|
||||||
|
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
|
||||||
|
side === "right" &&
|
||||||
|
"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
|
||||||
|
side === "left" &&
|
||||||
|
"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
|
||||||
|
side === "top" &&
|
||||||
|
"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",
|
||||||
|
side === "bottom" &&
|
||||||
|
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showCloseButton && (
|
||||||
|
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none">
|
||||||
|
<XIcon className="size-4" />
|
||||||
|
<span className="sr-only">Close</span>
|
||||||
|
</SheetPrimitive.Close>
|
||||||
|
)}
|
||||||
|
</SheetPrimitive.Content>
|
||||||
|
</SheetPortal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sheet-header"
|
||||||
|
className={cn("flex flex-col gap-1.5 p-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sheet-footer"
|
||||||
|
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Title>) {
|
||||||
|
return (
|
||||||
|
<SheetPrimitive.Title
|
||||||
|
data-slot="sheet-title"
|
||||||
|
className={cn("text-foreground font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SheetDescription({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Description>) {
|
||||||
|
return (
|
||||||
|
<SheetPrimitive.Description
|
||||||
|
data-slot="sheet-description"
|
||||||
|
className={cn("text-muted-foreground text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Sheet,
|
||||||
|
SheetTrigger,
|
||||||
|
SheetClose,
|
||||||
|
SheetContent,
|
||||||
|
SheetHeader,
|
||||||
|
SheetFooter,
|
||||||
|
SheetTitle,
|
||||||
|
SheetDescription,
|
||||||
|
}
|
||||||
726
components/ui/sidebar.tsx
Normal file
726
components/ui/sidebar.tsx
Normal file
@@ -0,0 +1,726 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
import { PanelLeftIcon } from "lucide-react"
|
||||||
|
import { Slot } from "radix-ui"
|
||||||
|
|
||||||
|
import { useIsMobile } from "@/hooks/use-mobile"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import {
|
||||||
|
Sheet,
|
||||||
|
SheetContent,
|
||||||
|
SheetDescription,
|
||||||
|
SheetHeader,
|
||||||
|
SheetTitle,
|
||||||
|
} from "@/components/ui/sheet"
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip"
|
||||||
|
|
||||||
|
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
||||||
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||||
|
const SIDEBAR_WIDTH = "16rem"
|
||||||
|
const SIDEBAR_WIDTH_MOBILE = "18rem"
|
||||||
|
const SIDEBAR_WIDTH_ICON = "3rem"
|
||||||
|
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
||||||
|
|
||||||
|
type SidebarContextProps = {
|
||||||
|
state: "expanded" | "collapsed"
|
||||||
|
open: boolean
|
||||||
|
setOpen: (open: boolean) => void
|
||||||
|
openMobile: boolean
|
||||||
|
setOpenMobile: (open: boolean) => void
|
||||||
|
isMobile: boolean
|
||||||
|
toggleSidebar: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
||||||
|
|
||||||
|
function useSidebar() {
|
||||||
|
const context = React.useContext(SidebarContext)
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useSidebar must be used within a SidebarProvider.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarProvider({
|
||||||
|
defaultOpen = true,
|
||||||
|
open: openProp,
|
||||||
|
onOpenChange: setOpenProp,
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & {
|
||||||
|
defaultOpen?: boolean
|
||||||
|
open?: boolean
|
||||||
|
onOpenChange?: (open: boolean) => void
|
||||||
|
}) {
|
||||||
|
const isMobile = useIsMobile()
|
||||||
|
const [openMobile, setOpenMobile] = React.useState(false)
|
||||||
|
|
||||||
|
// This is the internal state of the sidebar.
|
||||||
|
// We use openProp and setOpenProp for control from outside the component.
|
||||||
|
const [_open, _setOpen] = React.useState(defaultOpen)
|
||||||
|
const open = openProp ?? _open
|
||||||
|
const setOpen = React.useCallback(
|
||||||
|
(value: boolean | ((value: boolean) => boolean)) => {
|
||||||
|
const openState = typeof value === "function" ? value(open) : value
|
||||||
|
if (setOpenProp) {
|
||||||
|
setOpenProp(openState)
|
||||||
|
} else {
|
||||||
|
_setOpen(openState)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This sets the cookie to keep the sidebar state.
|
||||||
|
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
||||||
|
},
|
||||||
|
[setOpenProp, open]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Helper to toggle the sidebar.
|
||||||
|
const toggleSidebar = React.useCallback(() => {
|
||||||
|
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
|
||||||
|
}, [isMobile, setOpen, setOpenMobile])
|
||||||
|
|
||||||
|
// Adds a keyboard shortcut to toggle the sidebar.
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (
|
||||||
|
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
||||||
|
(event.metaKey || event.ctrlKey)
|
||||||
|
) {
|
||||||
|
event.preventDefault()
|
||||||
|
toggleSidebar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown)
|
||||||
|
return () => window.removeEventListener("keydown", handleKeyDown)
|
||||||
|
}, [toggleSidebar])
|
||||||
|
|
||||||
|
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||||
|
// This makes it easier to style the sidebar with Tailwind classes.
|
||||||
|
const state = open ? "expanded" : "collapsed"
|
||||||
|
|
||||||
|
const contextValue = React.useMemo<SidebarContextProps>(
|
||||||
|
() => ({
|
||||||
|
state,
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
isMobile,
|
||||||
|
openMobile,
|
||||||
|
setOpenMobile,
|
||||||
|
toggleSidebar,
|
||||||
|
}),
|
||||||
|
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SidebarContext.Provider value={contextValue}>
|
||||||
|
<TooltipProvider delayDuration={0}>
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-wrapper"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--sidebar-width": SIDEBAR_WIDTH,
|
||||||
|
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||||
|
...style,
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
className={cn(
|
||||||
|
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</TooltipProvider>
|
||||||
|
</SidebarContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Sidebar({
|
||||||
|
side = "left",
|
||||||
|
variant = "sidebar",
|
||||||
|
collapsible = "offcanvas",
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & {
|
||||||
|
side?: "left" | "right"
|
||||||
|
variant?: "sidebar" | "floating" | "inset"
|
||||||
|
collapsible?: "offcanvas" | "icon" | "none"
|
||||||
|
}) {
|
||||||
|
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
||||||
|
|
||||||
|
if (collapsible === "none") {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar"
|
||||||
|
className={cn(
|
||||||
|
"bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
return (
|
||||||
|
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||||
|
<SheetContent
|
||||||
|
data-sidebar="sidebar"
|
||||||
|
data-slot="sidebar"
|
||||||
|
data-mobile="true"
|
||||||
|
className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
side={side}
|
||||||
|
>
|
||||||
|
<SheetHeader className="sr-only">
|
||||||
|
<SheetTitle>Sidebar</SheetTitle>
|
||||||
|
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||||
|
</SheetHeader>
|
||||||
|
<div className="flex h-full w-full flex-col">{children}</div>
|
||||||
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="group peer text-sidebar-foreground hidden md:block"
|
||||||
|
data-state={state}
|
||||||
|
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||||
|
data-variant={variant}
|
||||||
|
data-side={side}
|
||||||
|
data-slot="sidebar"
|
||||||
|
>
|
||||||
|
{/* This is what handles the sidebar gap on desktop */}
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-gap"
|
||||||
|
className={cn(
|
||||||
|
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||||
|
"group-data-[collapsible=offcanvas]:w-0",
|
||||||
|
"group-data-[side=right]:rotate-180",
|
||||||
|
variant === "floating" || variant === "inset"
|
||||||
|
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||||
|
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-container"
|
||||||
|
className={cn(
|
||||||
|
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
|
||||||
|
side === "left"
|
||||||
|
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||||
|
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||||
|
// Adjust the padding for floating and inset variants.
|
||||||
|
variant === "floating" || variant === "inset"
|
||||||
|
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||||
|
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
data-sidebar="sidebar"
|
||||||
|
data-slot="sidebar-inner"
|
||||||
|
className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarTrigger({
|
||||||
|
className,
|
||||||
|
onClick,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof Button>) {
|
||||||
|
const { toggleSidebar } = useSidebar()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
data-sidebar="trigger"
|
||||||
|
data-slot="sidebar-trigger"
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className={cn("size-7", className)}
|
||||||
|
onClick={(event) => {
|
||||||
|
onClick?.(event)
|
||||||
|
toggleSidebar()
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<PanelLeftIcon />
|
||||||
|
<span className="sr-only">Toggle Sidebar</span>
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||||
|
const { toggleSidebar } = useSidebar()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
data-sidebar="rail"
|
||||||
|
data-slot="sidebar-rail"
|
||||||
|
aria-label="Toggle Sidebar"
|
||||||
|
tabIndex={-1}
|
||||||
|
onClick={toggleSidebar}
|
||||||
|
title="Toggle Sidebar"
|
||||||
|
className={cn(
|
||||||
|
"hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
|
||||||
|
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||||
|
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||||
|
"hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
|
||||||
|
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||||
|
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||||
|
return (
|
||||||
|
<main
|
||||||
|
data-slot="sidebar-inset"
|
||||||
|
className={cn(
|
||||||
|
"bg-background relative flex w-full flex-1 flex-col",
|
||||||
|
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarInput({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof Input>) {
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
data-slot="sidebar-input"
|
||||||
|
data-sidebar="input"
|
||||||
|
className={cn("bg-background h-8 w-full shadow-none", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-header"
|
||||||
|
data-sidebar="header"
|
||||||
|
className={cn("flex flex-col gap-2 p-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-footer"
|
||||||
|
data-sidebar="footer"
|
||||||
|
className={cn("flex flex-col gap-2 p-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof Separator>) {
|
||||||
|
return (
|
||||||
|
<Separator
|
||||||
|
data-slot="sidebar-separator"
|
||||||
|
data-sidebar="separator"
|
||||||
|
className={cn("bg-sidebar-border mx-2 w-auto", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-content"
|
||||||
|
data-sidebar="content"
|
||||||
|
className={cn(
|
||||||
|
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-group"
|
||||||
|
data-sidebar="group"
|
||||||
|
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarGroupLabel({
|
||||||
|
className,
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||||
|
const Comp = asChild ? Slot.Root : "div"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="sidebar-group-label"
|
||||||
|
data-sidebar="group-label"
|
||||||
|
className={cn(
|
||||||
|
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarGroupAction({
|
||||||
|
className,
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||||
|
const Comp = asChild ? Slot.Root : "button"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="sidebar-group-action"
|
||||||
|
data-sidebar="group-action"
|
||||||
|
className={cn(
|
||||||
|
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
// Increases the hit area of the button on mobile.
|
||||||
|
"after:absolute after:-inset-2 md:after:hidden",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarGroupContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-group-content"
|
||||||
|
data-sidebar="group-content"
|
||||||
|
className={cn("w-full text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||||
|
return (
|
||||||
|
<ul
|
||||||
|
data-slot="sidebar-menu"
|
||||||
|
data-sidebar="menu"
|
||||||
|
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
data-slot="sidebar-menu-item"
|
||||||
|
data-sidebar="menu-item"
|
||||||
|
className={cn("group/menu-item relative", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const sidebarMenuButtonVariants = cva(
|
||||||
|
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||||
|
outline:
|
||||||
|
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-8 text-sm",
|
||||||
|
sm: "h-7 text-xs",
|
||||||
|
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function SidebarMenuButton({
|
||||||
|
asChild = false,
|
||||||
|
isActive = false,
|
||||||
|
variant = "default",
|
||||||
|
size = "default",
|
||||||
|
tooltip,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> & {
|
||||||
|
asChild?: boolean
|
||||||
|
isActive?: boolean
|
||||||
|
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
||||||
|
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||||
|
const Comp = asChild ? Slot.Root : "button"
|
||||||
|
const { isMobile, state } = useSidebar()
|
||||||
|
|
||||||
|
const button = (
|
||||||
|
<Comp
|
||||||
|
data-slot="sidebar-menu-button"
|
||||||
|
data-sidebar="menu-button"
|
||||||
|
data-size={size}
|
||||||
|
data-active={isActive}
|
||||||
|
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!tooltip) {
|
||||||
|
return button
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof tooltip === "string") {
|
||||||
|
tooltip = {
|
||||||
|
children: tooltip,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
side="right"
|
||||||
|
align="center"
|
||||||
|
hidden={state !== "collapsed" || isMobile}
|
||||||
|
{...tooltip}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuAction({
|
||||||
|
className,
|
||||||
|
asChild = false,
|
||||||
|
showOnHover = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> & {
|
||||||
|
asChild?: boolean
|
||||||
|
showOnHover?: boolean
|
||||||
|
}) {
|
||||||
|
const Comp = asChild ? Slot.Root : "button"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="sidebar-menu-action"
|
||||||
|
data-sidebar="menu-action"
|
||||||
|
className={cn(
|
||||||
|
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
// Increases the hit area of the button on mobile.
|
||||||
|
"after:absolute after:-inset-2 md:after:hidden",
|
||||||
|
"peer-data-[size=sm]/menu-button:top-1",
|
||||||
|
"peer-data-[size=default]/menu-button:top-1.5",
|
||||||
|
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
showOnHover &&
|
||||||
|
"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuBadge({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-menu-badge"
|
||||||
|
data-sidebar="menu-badge"
|
||||||
|
className={cn(
|
||||||
|
"text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
|
||||||
|
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||||
|
"peer-data-[size=sm]/menu-button:top-1",
|
||||||
|
"peer-data-[size=default]/menu-button:top-1.5",
|
||||||
|
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuSkeleton({
|
||||||
|
className,
|
||||||
|
showIcon = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & {
|
||||||
|
showIcon?: boolean
|
||||||
|
}) {
|
||||||
|
// Random width between 50 to 90%.
|
||||||
|
const width = React.useMemo(() => {
|
||||||
|
return `${Math.floor(Math.random() * 40) + 50}%`
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="sidebar-menu-skeleton"
|
||||||
|
data-sidebar="menu-skeleton"
|
||||||
|
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{showIcon && (
|
||||||
|
<Skeleton
|
||||||
|
className="size-4 rounded-md"
|
||||||
|
data-sidebar="menu-skeleton-icon"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Skeleton
|
||||||
|
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||||
|
data-sidebar="menu-skeleton-text"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--skeleton-width": width,
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||||
|
return (
|
||||||
|
<ul
|
||||||
|
data-slot="sidebar-menu-sub"
|
||||||
|
data-sidebar="menu-sub"
|
||||||
|
className={cn(
|
||||||
|
"border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuSubItem({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"li">) {
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
data-slot="sidebar-menu-sub-item"
|
||||||
|
data-sidebar="menu-sub-item"
|
||||||
|
className={cn("group/menu-sub-item relative", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function SidebarMenuSubButton({
|
||||||
|
asChild = false,
|
||||||
|
size = "md",
|
||||||
|
isActive = false,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"a"> & {
|
||||||
|
asChild?: boolean
|
||||||
|
size?: "sm" | "md"
|
||||||
|
isActive?: boolean
|
||||||
|
}) {
|
||||||
|
const Comp = asChild ? Slot.Root : "a"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Comp
|
||||||
|
data-slot="sidebar-menu-sub-button"
|
||||||
|
data-sidebar="menu-sub-button"
|
||||||
|
data-size={size}
|
||||||
|
data-active={isActive}
|
||||||
|
className={cn(
|
||||||
|
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||||
|
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||||
|
size === "sm" && "text-xs",
|
||||||
|
size === "md" && "text-sm",
|
||||||
|
"group-data-[collapsible=icon]:hidden",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Sidebar,
|
||||||
|
SidebarContent,
|
||||||
|
SidebarFooter,
|
||||||
|
SidebarGroup,
|
||||||
|
SidebarGroupAction,
|
||||||
|
SidebarGroupContent,
|
||||||
|
SidebarGroupLabel,
|
||||||
|
SidebarHeader,
|
||||||
|
SidebarInput,
|
||||||
|
SidebarInset,
|
||||||
|
SidebarMenu,
|
||||||
|
SidebarMenuAction,
|
||||||
|
SidebarMenuBadge,
|
||||||
|
SidebarMenuButton,
|
||||||
|
SidebarMenuItem,
|
||||||
|
SidebarMenuSkeleton,
|
||||||
|
SidebarMenuSub,
|
||||||
|
SidebarMenuSubButton,
|
||||||
|
SidebarMenuSubItem,
|
||||||
|
SidebarProvider,
|
||||||
|
SidebarRail,
|
||||||
|
SidebarSeparator,
|
||||||
|
SidebarTrigger,
|
||||||
|
useSidebar,
|
||||||
|
}
|
||||||
13
components/ui/skeleton.tsx
Normal file
13
components/ui/skeleton.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="skeleton"
|
||||||
|
className={cn("bg-accent animate-pulse rounded-md", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Skeleton }
|
||||||
29
components/ui/switch.tsx
Normal file
29
components/ui/switch.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import * as SwitchPrimitives from "@radix-ui/react-switch"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
const Switch = React.forwardRef<
|
||||||
|
React.ElementRef<typeof SwitchPrimitives.Root>,
|
||||||
|
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
||||||
|
>(({ className, ...props }, ref) => (
|
||||||
|
<SwitchPrimitives.Root
|
||||||
|
className={cn(
|
||||||
|
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
ref={ref}
|
||||||
|
>
|
||||||
|
<SwitchPrimitives.Thumb
|
||||||
|
className={cn(
|
||||||
|
"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</SwitchPrimitives.Root>
|
||||||
|
))
|
||||||
|
Switch.displayName = SwitchPrimitives.Root.displayName
|
||||||
|
|
||||||
|
export { Switch }
|
||||||
116
components/ui/table.tsx
Normal file
116
components/ui/table.tsx
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="table-container"
|
||||||
|
className="relative w-full overflow-x-auto"
|
||||||
|
>
|
||||||
|
<table
|
||||||
|
data-slot="table"
|
||||||
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||||
|
return (
|
||||||
|
<thead
|
||||||
|
data-slot="table-header"
|
||||||
|
className={cn("[&_tr]:border-b", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||||
|
return (
|
||||||
|
<tbody
|
||||||
|
data-slot="table-body"
|
||||||
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||||
|
return (
|
||||||
|
<tfoot
|
||||||
|
data-slot="table-footer"
|
||||||
|
className={cn(
|
||||||
|
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
data-slot="table-row"
|
||||||
|
className={cn(
|
||||||
|
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||||
|
return (
|
||||||
|
<th
|
||||||
|
data-slot="table-head"
|
||||||
|
className={cn(
|
||||||
|
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||||
|
return (
|
||||||
|
<td
|
||||||
|
data-slot="table-cell"
|
||||||
|
className={cn(
|
||||||
|
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableCaption({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"caption">) {
|
||||||
|
return (
|
||||||
|
<caption
|
||||||
|
data-slot="table-caption"
|
||||||
|
className={cn("text-muted-foreground mt-4 text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableBody,
|
||||||
|
TableFooter,
|
||||||
|
TableHead,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
TableCaption,
|
||||||
|
}
|
||||||
61
components/ui/tooltip.tsx
Normal file
61
components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Tooltip as TooltipPrimitive } from "radix-ui"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function TooltipProvider({
|
||||||
|
delayDuration = 0,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||||
|
return (
|
||||||
|
<TooltipPrimitive.Provider
|
||||||
|
data-slot="tooltip-provider"
|
||||||
|
delayDuration={delayDuration}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Tooltip({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<TooltipProvider>
|
||||||
|
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||||
|
</TooltipProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TooltipTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||||
|
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function TooltipContent({
|
||||||
|
className,
|
||||||
|
sideOffset = 0,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<TooltipPrimitive.Portal>
|
||||||
|
<TooltipPrimitive.Content
|
||||||
|
data-slot="tooltip-content"
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<TooltipPrimitive.Arrow className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
||||||
|
</TooltipPrimitive.Content>
|
||||||
|
</TooltipPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||||
90
components/users/deleted-user-table.tsx
Normal file
90
components/users/deleted-user-table.tsx
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { RefreshCcw, ShieldAlert } from "lucide-react";
|
||||||
|
import { User } from "@/lib/features/auth/authSlice";
|
||||||
|
import { getAvatarUrl } from "@/lib/utils";
|
||||||
|
|
||||||
|
interface DeletedUserTableProps {
|
||||||
|
users: (User & { deleted_at?: string })[];
|
||||||
|
onRestore: (id: string) => void;
|
||||||
|
onHardDelete: (id: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DeletedUserTable({ users, onRestore, onHardDelete }: DeletedUserTableProps) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border border-destructive/20 bg-destructive/5">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead className="w-14">Avatar</TableHead>
|
||||||
|
<TableHead>Username (Silinmiş)</TableHead>
|
||||||
|
<TableHead>Email</TableHead>
|
||||||
|
<TableHead>Silinme Tarihi</TableHead>
|
||||||
|
<TableHead className="text-right">İşlemler</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{users.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} className="h-24 text-center text-muted-foreground">
|
||||||
|
Çöp kutusu boş.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
users.map((user) => (
|
||||||
|
<TableRow key={user.id}>
|
||||||
|
<TableCell>
|
||||||
|
<Avatar className="h-9 w-9 grayscale opacity-50">
|
||||||
|
<AvatarImage src={getAvatarUrl(user.avatar_url)} alt={user.username} />
|
||||||
|
<AvatarFallback className="text-xs">
|
||||||
|
{user.username?.slice(0, 2).toUpperCase() || "?"}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="font-medium text-muted-foreground line-through">
|
||||||
|
{user.username}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-muted-foreground">{user.email}</TableCell>
|
||||||
|
<TableCell className="text-muted-foreground text-sm">
|
||||||
|
{user.deleted_at ? new Date(user.deleted_at).toLocaleString('tr-TR') : "-"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<div className="inline-flex rounded-md border border-input bg-background [&>button]:rounded-none [&>button:first-child]:rounded-l-md [&>button:last-child]:rounded-r-md [&>button:first-child]:border-r [&>button:first-child]:border-input">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-9 w-9 text-green-600 hover:text-green-700 hover:bg-green-100 dark:hover:bg-green-900/20"
|
||||||
|
onClick={() => onRestore(user.id)}
|
||||||
|
title="Geri Yükle"
|
||||||
|
>
|
||||||
|
<RefreshCcw className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Geri Yükle</span>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||||
|
onClick={() => onHardDelete(user.id)}
|
||||||
|
title="Kalıcı Sil (Hard)"
|
||||||
|
>
|
||||||
|
<ShieldAlert className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Kalıcı Sil</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
190
components/users/user-dialog.tsx
Normal file
190
components/users/user-dialog.tsx
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { CreateUserRequest, UpdateUserRequest } from "@/lib/features/users/usersSlice";
|
||||||
|
import { User } from "@/lib/features/auth/authSlice";
|
||||||
|
import { getAvatarUrl } from "@/lib/utils";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
interface UserDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
user?: User | null;
|
||||||
|
onSubmit: (data: CreateUserRequest | UpdateUserRequest) => void;
|
||||||
|
isLoading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UserDialog({ open, onOpenChange, user, onSubmit, isLoading }: UserDialogProps) {
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [role, setRole] = useState("user");
|
||||||
|
const [avatar, setAvatar] = useState<File | null>(null);
|
||||||
|
const [avatarPreview, setAvatarPreview] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user) {
|
||||||
|
setUsername(user.username);
|
||||||
|
setEmail(user.email);
|
||||||
|
setPassword("");
|
||||||
|
setRole(user.roles?.[0]?.name || "user");
|
||||||
|
setAvatar(null);
|
||||||
|
setAvatarPreview(null);
|
||||||
|
} else {
|
||||||
|
setUsername("");
|
||||||
|
setEmail("");
|
||||||
|
setPassword("");
|
||||||
|
setRole("user");
|
||||||
|
setAvatar(null);
|
||||||
|
setAvatarPreview(null);
|
||||||
|
}
|
||||||
|
}, [user, open]);
|
||||||
|
|
||||||
|
const onAvatarChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = e.target.files?.[0] || null;
|
||||||
|
setAvatar(file);
|
||||||
|
if (avatarPreview) URL.revokeObjectURL(avatarPreview);
|
||||||
|
setAvatarPreview(file ? URL.createObjectURL(file) : null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const roles = [role];
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
const updateData: UpdateUserRequest = {
|
||||||
|
id: user.id,
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
roles
|
||||||
|
};
|
||||||
|
if (password) updateData.password = password;
|
||||||
|
if (avatar) updateData.avatar = avatar;
|
||||||
|
onSubmit(updateData);
|
||||||
|
} else {
|
||||||
|
const createData: CreateUserRequest = {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
roles,
|
||||||
|
avatar: avatar || undefined
|
||||||
|
};
|
||||||
|
onSubmit(createData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{user ? "Kullanıcıyı Düzenle" : "Yeni Kullanıcı Ekle"}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
{user ? "Kullanıcı bilgilerini güncelleyin." : "Yeni bir kullanıcı oluşturun."}
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<div className="grid gap-4 py-4">
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="username" className="text-right">
|
||||||
|
Username
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="username"
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
className="col-span-3"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="email" className="text-right">
|
||||||
|
Email
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="email"
|
||||||
|
type="email"
|
||||||
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
className="col-span-3"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="password" className="text-right">
|
||||||
|
Şifre
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
className="col-span-3"
|
||||||
|
placeholder={user ? "Değiştirmek için girin" : "Şifre"}
|
||||||
|
required={!user}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="role" className="text-right">
|
||||||
|
Rol
|
||||||
|
</Label>
|
||||||
|
<Select onValueChange={setRole} value={role}>
|
||||||
|
<SelectTrigger className="w-[180px]">
|
||||||
|
<SelectValue placeholder="Rol Seçin" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="user">User</SelectItem>
|
||||||
|
<SelectItem value="admin">Admin</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="avatar" className="text-right">
|
||||||
|
Avatar
|
||||||
|
</Label>
|
||||||
|
<div className="col-span-3 flex items-center gap-4">
|
||||||
|
<Avatar className="h-14 w-14">
|
||||||
|
<AvatarImage
|
||||||
|
src={avatarPreview ?? (user ? getAvatarUrl(user.avatar_url) : undefined)}
|
||||||
|
alt={username || "Avatar"}
|
||||||
|
/>
|
||||||
|
<AvatarFallback className="text-lg">
|
||||||
|
{username?.slice(0, 2).toUpperCase() || "?"}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<Input
|
||||||
|
id="avatar"
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
onChange={onAvatarChange}
|
||||||
|
className="cursor-pointer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading ? "Kaydediliyor..." : "Kaydet"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
99
components/users/user-table.tsx
Normal file
99
components/users/user-table.tsx
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from "@/components/ui/table";
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Edit, Trash2, ShieldAlert } from "lucide-react";
|
||||||
|
import { User } from "@/lib/features/auth/authSlice";
|
||||||
|
import { getAvatarUrl } from "@/lib/utils";
|
||||||
|
|
||||||
|
interface UserTableProps {
|
||||||
|
users: User[];
|
||||||
|
onEdit: (user: User) => void;
|
||||||
|
onDelete: (id: string) => void;
|
||||||
|
onHardDelete: (id: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UserTable({ users, onEdit, onDelete, onHardDelete }: UserTableProps) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead className="w-14">Avatar</TableHead>
|
||||||
|
<TableHead>Username</TableHead>
|
||||||
|
<TableHead>Email</TableHead>
|
||||||
|
<TableHead>Roller</TableHead>
|
||||||
|
<TableHead className="text-right">İşlemler</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{users.length === 0 ? (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell colSpan={5} className="h-24 text-center">
|
||||||
|
Kullanıcı bulunamadı.
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
) : (
|
||||||
|
users.map((user) => (
|
||||||
|
<TableRow key={user.id}>
|
||||||
|
<TableCell>
|
||||||
|
<Avatar className="h-9 w-9">
|
||||||
|
<AvatarImage src={getAvatarUrl(user.avatar_url)} alt={user.username} />
|
||||||
|
<AvatarFallback className="text-xs">
|
||||||
|
{user.username?.slice(0, 2).toUpperCase() || "?"}
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="font-medium">{user.username}</TableCell>
|
||||||
|
<TableCell>{user.email}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{user.roles?.map((r) => r.name).join(", ") || "-"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<div className="inline-flex rounded-md border border-input bg-background [&>button]:rounded-none [&>button:first-child]:rounded-l-md [&>button:last-child]:rounded-r-md [&>button]:border-r [&>button:last-child]:border-r-0 [&>button]:border-input">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => onEdit(user)}
|
||||||
|
className="h-9 w-9"
|
||||||
|
title="Düzenle"
|
||||||
|
>
|
||||||
|
<Edit className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Düzenle</span>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-9 w-9 text-orange-500 hover:text-orange-600 hover:bg-orange-100 dark:hover:bg-orange-900/20"
|
||||||
|
onClick={() => onDelete(user.id)}
|
||||||
|
title="Sil (Soft)"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Sil</span>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-9 w-9 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||||
|
onClick={() => onHardDelete(user.id)}
|
||||||
|
title="Kalıcı Sil (Hard)"
|
||||||
|
>
|
||||||
|
<ShieldAlert className="h-4 w-4" />
|
||||||
|
<span className="sr-only">Kalıcı Sil</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
27
docker-compose.yml
Normal file
27
docker-compose.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
services:
|
||||||
|
next-go-blog:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
NEXT_PUBLIC_API_BASE: ${NEXT_PUBLIC_API_BASE}
|
||||||
|
container_name: next-go-blog
|
||||||
|
restart: always
|
||||||
|
#ports:
|
||||||
|
# - "${PORT:-3000}:3000"
|
||||||
|
#env_file:
|
||||||
|
# - .env
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "wget", "-q", "--spider", "http://127.0.0.1:3000" ]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
networks:
|
||||||
|
- dokploy-network
|
||||||
|
|
||||||
|
networks:
|
||||||
|
dokploy-network:
|
||||||
|
external: true
|
||||||
590
docs/API_ENDPOINTS.md
Normal file
590
docs/API_ENDPOINTS.md
Normal file
@@ -0,0 +1,590 @@
|
|||||||
|
# 🌐 GAuth-Central API Endpoints
|
||||||
|
|
||||||
|
## Base URL
|
||||||
|
|
||||||
|
```
|
||||||
|
Local Development: http://localhost:8080
|
||||||
|
Production: http://your-domain.com
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Version: v1
|
||||||
|
|
||||||
|
Base Path: `/v1`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📍 Endpoints
|
||||||
|
|
||||||
|
### Public Endpoints (No Authentication Required)
|
||||||
|
|
||||||
|
#### 1. Homepage
|
||||||
|
```
|
||||||
|
GET /
|
||||||
|
Content-Type: text/html
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:** HTML homepage
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 2. Swagger Documentation
|
||||||
|
```
|
||||||
|
GET /docs/index.html
|
||||||
|
Content-Type: text/html
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:** Swagger UI
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Authentication Endpoints
|
||||||
|
|
||||||
|
#### 3. Register User
|
||||||
|
```
|
||||||
|
POST /v1/auth/register
|
||||||
|
Content-Type: application/json
|
||||||
|
Rate Limit: 3 requests / 5 minutes
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"email": "user@example.com",
|
||||||
|
"password": "SecurePass123!",
|
||||||
|
"user_name": "username"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (201):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "User created successfully. Please verify your email.",
|
||||||
|
"user": {
|
||||||
|
"id": "uuid",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"user_name": "username"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**cURL Example:**
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "user@example.com",
|
||||||
|
"password": "SecurePass123!",
|
||||||
|
"user_name": "username"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 4. Login
|
||||||
|
```
|
||||||
|
POST /v1/auth/login
|
||||||
|
Content-Type: application/json
|
||||||
|
Rate Limit: 5 requests / 1 minute
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"email": "user@example.com",
|
||||||
|
"password": "SecurePass123!"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIs...",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
|
||||||
|
"user": {
|
||||||
|
"id": "uuid",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"user_name": "username"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**cURL Example:**
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "user@example.com",
|
||||||
|
"password": "SecurePass123!"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 5. Email Verification
|
||||||
|
```
|
||||||
|
GET /v1/auth/verify-email?token={verification_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Query Parameters:**
|
||||||
|
- `token` (required): Email verification token
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Email verified successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**cURL Example:**
|
||||||
|
```bash
|
||||||
|
curl -X GET "http://localhost:8080/v1/auth/verify-email?token=abc123xyz"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 6. OAuth Login (Google/GitHub)
|
||||||
|
```
|
||||||
|
GET /v1/auth/{provider}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
- `provider`: `google` or `github`
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
```
|
||||||
|
http://localhost:8080/v1/auth/google
|
||||||
|
http://localhost:8080/v1/auth/github
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:** Redirects to OAuth provider
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 7. OAuth Callback
|
||||||
|
```
|
||||||
|
GET /v1/auth/{provider}/callback
|
||||||
|
```
|
||||||
|
|
||||||
|
**Parameters:**
|
||||||
|
- `provider`: `google` or `github`
|
||||||
|
|
||||||
|
**Query Parameters:** (Provided by OAuth provider)
|
||||||
|
- `code`
|
||||||
|
- `state`
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIs...",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
|
||||||
|
"user": {
|
||||||
|
"id": "uuid",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"user_name": "username"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 8. Refresh Token
|
||||||
|
```
|
||||||
|
POST /v1/auth/refresh
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIs..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIs...",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIs..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**cURL Example:**
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/refresh \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"refresh_token": "your_refresh_token_here"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Protected Endpoints (Authentication Required)
|
||||||
|
|
||||||
|
**Note:** All protected endpoints require the `Authorization` header:
|
||||||
|
```
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 9. Get Current User
|
||||||
|
```
|
||||||
|
GET /v1/auth/me
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"user_name": "username",
|
||||||
|
"email_verified": true,
|
||||||
|
"created_at": "2026-02-04T00:00:00Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**cURL Example:**
|
||||||
|
```bash
|
||||||
|
curl -X GET http://localhost:8080/v1/auth/me \
|
||||||
|
-H "Authorization: Bearer your_access_token_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 10. Validate Token
|
||||||
|
```
|
||||||
|
GET /v1/auth/validate
|
||||||
|
Authorization: Bearer {access_token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Token is valid",
|
||||||
|
"user_id": "uuid",
|
||||||
|
"email": "user@example.com"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**cURL Example:**
|
||||||
|
```bash
|
||||||
|
curl -X GET http://localhost:8080/v1/auth/validate \
|
||||||
|
-H "Authorization: Bearer your_access_token_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 Authentication Flow
|
||||||
|
|
||||||
|
### Standard Email/Password Flow
|
||||||
|
|
||||||
|
```
|
||||||
|
1. Register
|
||||||
|
POST /v1/auth/register
|
||||||
|
↓
|
||||||
|
2. Verify Email
|
||||||
|
GET /v1/auth/verify-email?token=...
|
||||||
|
↓
|
||||||
|
3. Login
|
||||||
|
POST /v1/auth/login
|
||||||
|
↓
|
||||||
|
4. Access Protected Resources
|
||||||
|
GET /v1/auth/me (with Bearer token)
|
||||||
|
```
|
||||||
|
|
||||||
|
### OAuth Flow
|
||||||
|
|
||||||
|
```
|
||||||
|
1. Initiate OAuth
|
||||||
|
GET /v1/auth/google (or /github)
|
||||||
|
↓
|
||||||
|
2. User authorizes on OAuth provider
|
||||||
|
↓
|
||||||
|
3. Callback with code
|
||||||
|
GET /v1/auth/google/callback?code=...
|
||||||
|
↓
|
||||||
|
4. Access Protected Resources
|
||||||
|
GET /v1/auth/me (with Bearer token)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 Error Responses
|
||||||
|
|
||||||
|
### Standard Error Format
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Error message description"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common Error Codes
|
||||||
|
|
||||||
|
| Status Code | Meaning |
|
||||||
|
|------------|---------|
|
||||||
|
| 400 | Bad Request - Invalid input |
|
||||||
|
| 401 | Unauthorized - Invalid or missing token |
|
||||||
|
| 403 | Forbidden - Valid token but insufficient permissions |
|
||||||
|
| 404 | Not Found - Resource not found |
|
||||||
|
| 429 | Too Many Requests - Rate limit exceeded |
|
||||||
|
| 500 | Internal Server Error |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚦 Rate Limits
|
||||||
|
|
||||||
|
| Endpoint | Limit | Time Window |
|
||||||
|
|----------|-------|-------------|
|
||||||
|
| POST /v1/auth/register | 3 requests | 5 minutes |
|
||||||
|
| POST /v1/auth/login | 5 requests | 1 minute |
|
||||||
|
| All API endpoints | 100 requests | 1 minute |
|
||||||
|
|
||||||
|
**Rate Limit Headers:**
|
||||||
|
```
|
||||||
|
X-RateLimit-Limit: 100
|
||||||
|
X-RateLimit-Remaining: 95
|
||||||
|
X-RateLimit-Reset: 1643980800
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔑 Authentication Headers
|
||||||
|
|
||||||
|
### Access Token
|
||||||
|
```
|
||||||
|
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
|
||||||
|
```
|
||||||
|
|
||||||
|
### CORS Headers
|
||||||
|
```
|
||||||
|
Origin: http://localhost:3000
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌍 CORS Configuration
|
||||||
|
|
||||||
|
**Allowed Origins:**
|
||||||
|
- `http://localhost:3000` (development)
|
||||||
|
|
||||||
|
**Allowed Methods:**
|
||||||
|
- GET, POST, PUT, PATCH, DELETE, OPTIONS
|
||||||
|
|
||||||
|
**Allowed Headers:**
|
||||||
|
- Origin, Content-Type, Accept, Authorization
|
||||||
|
|
||||||
|
**Credentials:**
|
||||||
|
- Enabled (`Access-Control-Allow-Credentials: true`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Response Examples
|
||||||
|
|
||||||
|
### Successful Response
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Operation successful",
|
||||||
|
"data": { ... }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Error Response
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Invalid credentials"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Validation Error
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": "Validation failed: email is required"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔗 Frontend Integration
|
||||||
|
|
||||||
|
### JavaScript/TypeScript Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Base URL
|
||||||
|
const API_BASE_URL = 'http://localhost:8080';
|
||||||
|
|
||||||
|
// Login
|
||||||
|
async function login(email, password) {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/v1/auth/login`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({ email, password })
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
localStorage.setItem('access_token', data.access_token);
|
||||||
|
localStorage.setItem('refresh_token', data.refresh_token);
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
|
throw new Error(data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Current User (Protected)
|
||||||
|
async function getCurrentUser() {
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
|
||||||
|
const response = await fetch(`${API_BASE_URL}/v1/auth/me`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
|
throw new Error(data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register
|
||||||
|
async function register(email, password, username) {
|
||||||
|
const response = await fetch(`${API_BASE_URL}/v1/auth/register`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
user_name: username
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(data.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Axios Example
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const api = axios.create({
|
||||||
|
baseURL: 'http://localhost:8080/v1',
|
||||||
|
withCredentials: true,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add token to requests
|
||||||
|
api.interceptors.request.use((config) => {
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
if (token) {
|
||||||
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Login
|
||||||
|
export const login = (email, password) =>
|
||||||
|
api.post('/auth/login', { email, password });
|
||||||
|
|
||||||
|
// Register
|
||||||
|
export const register = (email, password, user_name) =>
|
||||||
|
api.post('/auth/register', { email, password, user_name });
|
||||||
|
|
||||||
|
// Get current user
|
||||||
|
export const getCurrentUser = () =>
|
||||||
|
api.get('/auth/me');
|
||||||
|
|
||||||
|
// Refresh token
|
||||||
|
export const refreshToken = (refresh_token) =>
|
||||||
|
api.post('/auth/refresh', { refresh_token });
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 Postman Collection
|
||||||
|
|
||||||
|
You can import these endpoints into Postman:
|
||||||
|
|
||||||
|
**Environment Variables:**
|
||||||
|
```
|
||||||
|
base_url: http://localhost:8080
|
||||||
|
access_token: {{access_token}}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Collection Structure:**
|
||||||
|
```
|
||||||
|
GAuth-Central API
|
||||||
|
├── Public
|
||||||
|
│ ├── Register
|
||||||
|
│ ├── Login
|
||||||
|
│ ├── Verify Email
|
||||||
|
│ ├── Refresh Token
|
||||||
|
│ ├── OAuth Google
|
||||||
|
│ └── OAuth GitHub
|
||||||
|
└── Protected (Auth Required)
|
||||||
|
├── Get Current User
|
||||||
|
└── Validate Token
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 Additional Resources
|
||||||
|
|
||||||
|
- **Swagger Documentation**: http://localhost:8080/docs/index.html
|
||||||
|
- **API Version**: v1.0
|
||||||
|
- **Last Updated**: February 4, 2026
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚡ Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Start the server
|
||||||
|
go run main.go
|
||||||
|
|
||||||
|
# 2. Test with curl
|
||||||
|
curl http://localhost:8080/
|
||||||
|
|
||||||
|
# 3. Register a user
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Test123!","user_name":"testuser"}'
|
||||||
|
|
||||||
|
# 4. Login
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Test123!"}'
|
||||||
|
|
||||||
|
# 5. Use the token from login response
|
||||||
|
curl http://localhost:8080/v1/auth/me \
|
||||||
|
-H "Authorization: Bearer YOUR_TOKEN_HERE"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
💡 **Tip**: Use the Swagger UI at http://localhost:8080/docs/index.html for interactive API testing!
|
||||||
119
docs/BACKEND_ENDPOINT.mb
Normal file
119
docs/BACKEND_ENDPOINT.mb
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
-- Register Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/register
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**",
|
||||||
|
"username":"test yaptim"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJwZXJtaXNzaW9ucyI6WyJ1c2VyOnJlYWQiXSwiaXNzIjoiZ2F1dGgtY2VudHJhbCIsImV4cCI6MTc3MDEzMDQ2OCwiaWF0IjoxNzcwMTI5NTY4fQ.Qc5EnE2r-In7hm6-NjP6WX2TKm3MyuM68SwsHYUNJbI",
|
||||||
|
"email": "bexysshanod@beyhan.dev",
|
||||||
|
"message": "User created successfully",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmMDVlZTc0Zi1hYjgzLTQxNzEtYjI3Ny1mZGM0NDZhNjA3YjciLCJlbWFpbCI6ImJleHlzc2hhbm9kQGJleWhhbi5kZXYiLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwNzM0MzY4LCJpYXQiOjE3NzAxMjk1Njh9.JE2UZ6jJti2N2jbExx_TTY5VPSfXKvc2ZGB-Nw_toLQ",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "f05ee74f-ab83-4171-b277-fdc446a607b7",
|
||||||
|
"username": "test yaptim"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Login Yeni Kullanıcı
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/login
|
||||||
|
-- Gönderrilen JSON
|
||||||
|
{
|
||||||
|
"email":"beyhanod@beyhan.dev",
|
||||||
|
"password":"1923btO**"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMwNjU3LCJpYXQiOjE3NzAxMjk3NTd9.QbsRFn5fr7L4Wc7HCxOs0_zOWWhuceWzPmt20TV5lNI",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ1NTcsImlhdCI6MTc3MDEyOTc1N30.wBML1pT9S9i9FtAw3PKmJBMdcobZexWVBTRV5remb_s",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Refresh Token
|
||||||
|
POST
|
||||||
|
http://localhost:8080/v1/auth/refresh
|
||||||
|
-- Gönderilen JSON
|
||||||
|
{
|
||||||
|
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzQ2NDUsImlhdCI6MTc3MDEyOTg0NX0.ACDDM20v1u6yjyNrqBnWafjXnrRAAT1-8CvfqSkjTsE"
|
||||||
|
}
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCJdLCJpc3MiOiJnYXV0aC1jZW50cmFsIiwiZXhwIjoxNzcwMTMxMjYwLCJpYXQiOjE3NzAxMzAzNjB9.BKmZBkL6FPo208mYLeBFMkNOqJ2tsmGXJUN_0bdZFHQ",
|
||||||
|
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5MWNmMDg2OC1kZjI0LTRiOGYtYjQ5MS03MGQ5ZWI3YTQzNzMiLCJlbWFpbCI6ImJleWhhbm9AYmV5aGFuLmRldiIsImlzcyI6ImdhdXRoLWNlbnRyYWwiLCJleHAiOjE3NzA3MzUxNjAsImlhdCI6MTc3MDEzMDM2MH0.tkpcbQ6QmVVXK-r0QgP333X_FrAktVOuh1AJhwvV1BQ"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Me (Kullanıcı Profili)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/me
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"id": "91cf0868-df24-4b8f-b491-70d9eb7a4373",
|
||||||
|
"username": "user_91cf0868",
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"created_at": "2026-02-03T17:03:07.863425+03:00",
|
||||||
|
"updated_at": "2026-02-03T17:03:07.880923+03:00",
|
||||||
|
"social_accounts": null,
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "user",
|
||||||
|
"description": "Default user role",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "user:read",
|
||||||
|
"description": "Can read user data"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Validate Token (Token Doğrulama)
|
||||||
|
GET
|
||||||
|
http://localhost:8080/v1/auth/validate
|
||||||
|
-- Header
|
||||||
|
Authorization: Bearer ACCESS_TOKEN_BURAYA
|
||||||
|
-- Body: YOK (GET isteği, body gönderilmez)
|
||||||
|
-- Cevap
|
||||||
|
{
|
||||||
|
"email": "beyhano@beyhan.dev",
|
||||||
|
"message": "Token is valid",
|
||||||
|
"user_id": "91cf0868-df24-4b8f-b491-70d9eb7a4373"
|
||||||
|
}
|
||||||
237
docs/BACKEND_URLS.md
Normal file
237
docs/BACKEND_URLS.md
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
🔗 Backend URL Yönetimi
|
||||||
|
API Endpoint Listesi
|
||||||
|
Base URL
|
||||||
|
Local: http://localhost:8080
|
||||||
|
Production: https://api.yourdomain.com
|
||||||
|
API Version
|
||||||
|
v1
|
||||||
|
📋 Tüm Endpoint'ler
|
||||||
|
Method Endpoint Auth Rate Limit Açıklama
|
||||||
|
GET / ❌ - Homepage
|
||||||
|
GET /docs/index.html ❌ - Swagger UI
|
||||||
|
POST /v1/auth/register ❌ 3/5min Kullanıcı kaydı
|
||||||
|
POST /v1/auth/login ❌ 5/1min Giriş
|
||||||
|
GET /v1/auth/verify-email ❌ - Email doğrulama
|
||||||
|
GET /v1/auth/:provider ❌ - OAuth başlat
|
||||||
|
GET /v1/auth/:provider/callback ❌ - OAuth callback
|
||||||
|
POST /v1/auth/refresh ❌ - Token yenile
|
||||||
|
GET /v1/auth/me ✅ - Kullanıcı bilgileri
|
||||||
|
GET /v1/auth/validate ✅ - Token doğrula
|
||||||
|
Admin - User Management (Admin rolü gerekli)
|
||||||
|
Method Endpoint Auth Açıklama
|
||||||
|
GET /v1/admin/users ✅ Admin Tüm kullanıcıları listele
|
||||||
|
GET /v1/admin/users/search?q={query} ✅ Admin Kullanıcı ara
|
||||||
|
GET /v1/admin/users/:id ✅ Admin Kullanıcı detayı
|
||||||
|
POST /v1/admin/users ✅ Admin Yeni kullanıcı oluştur
|
||||||
|
PUT /v1/admin/users/:id ✅ Admin Kullanıcı güncelle
|
||||||
|
DELETE /v1/admin/users/:id ✅ Admin Kullanıcı sil
|
||||||
|
POST /v1/admin/users/:id/roles ✅ Admin Rol ata
|
||||||
|
DELETE /v1/admin/users/:id/roles/:role ✅ Admin Rol kaldır
|
||||||
|
Admin - Settings (Admin rolü gerekli)
|
||||||
|
Method Endpoint Auth Açıklama
|
||||||
|
GET /v1/settings/cors/whitelist ✅ Admin CORS whitelist listele
|
||||||
|
POST /v1/settings/cors/whitelist ✅ Admin CORS whitelist ekle
|
||||||
|
PUT /v1/settings/cors/whitelist/:id ✅ Admin CORS whitelist güncelle
|
||||||
|
DELETE /v1/settings/cors/whitelist/:id ✅ Admin CORS whitelist sil
|
||||||
|
GET /v1/settings/cors/blacklist ✅ Admin CORS blacklist listele
|
||||||
|
POST /v1/settings/cors/blacklist ✅ Admin CORS blacklist ekle
|
||||||
|
PUT /v1/settings/cors/blacklist/:id ✅ Admin CORS blacklist güncelle
|
||||||
|
DELETE /v1/settings/cors/blacklist/:id ✅ Admin CORS blacklist sil
|
||||||
|
GET /v1/settings/ratelimit ✅ Admin Rate limit ayarları
|
||||||
|
PUT /v1/settings/ratelimit/:id ✅ Admin Rate limit güncelle
|
||||||
|
🎯 Frontend için URL Yapısı
|
||||||
|
JavaScript/TypeScript Constants
|
||||||
|
// config/api.js
|
||||||
|
export const API_CONFIG = {
|
||||||
|
BASE_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080',
|
||||||
|
API_VERSION: 'v1',
|
||||||
|
ENDPOINTS: {
|
||||||
|
// Auth endpoints
|
||||||
|
REGISTER: '/auth/register',
|
||||||
|
LOGIN: '/auth/login',
|
||||||
|
LOGOUT: '/auth/logout',
|
||||||
|
REFRESH: '/auth/refresh',
|
||||||
|
VERIFY_EMAIL: '/auth/verify-email',
|
||||||
|
ME: '/auth/me',
|
||||||
|
VALIDATE: '/auth/validate',
|
||||||
|
|
||||||
|
// OAuth endpoints
|
||||||
|
OAUTH_GOOGLE: '/auth/google',
|
||||||
|
OAUTH_GITHUB: '/auth/github',
|
||||||
|
OAUTH_GOOGLE_CALLBACK: '/auth/google/callback',
|
||||||
|
OAUTH_GITHUB_CALLBACK: '/auth/github/callback',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function
|
||||||
|
export function getApiUrl(endpoint) {
|
||||||
|
return `${API_CONFIG.BASE_URL}/${API_CONFIG.API_VERSION}${endpoint}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage
|
||||||
|
const loginUrl = getApiUrl(API_CONFIG.ENDPOINTS.LOGIN);
|
||||||
|
// Result: http://localhost:8080/v1/auth/login
|
||||||
|
📦 Kullanım Örnekleri
|
||||||
|
1. React/Next.js
|
||||||
|
// lib/api.js
|
||||||
|
const API_BASE = 'http://localhost:8080/v1';
|
||||||
|
|
||||||
|
export const authAPI = {
|
||||||
|
register: (data) =>
|
||||||
|
fetch(`${API_BASE}/auth/register`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
}),
|
||||||
|
|
||||||
|
login: (data) =>
|
||||||
|
fetch(`${API_BASE}/auth/login`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
}),
|
||||||
|
|
||||||
|
getCurrentUser: (token) =>
|
||||||
|
fetch(`${API_BASE}/auth/me`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
};
|
||||||
|
2. Vue.js/Nuxt
|
||||||
|
// plugins/api.js
|
||||||
|
export default defineNuxtPlugin(() => {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
const baseURL = config.public.apiBase || 'http://localhost:8080/v1';
|
||||||
|
|
||||||
|
return {
|
||||||
|
provide: {
|
||||||
|
api: {
|
||||||
|
auth: {
|
||||||
|
register: (data) => $fetch(`${baseURL}/auth/register`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: data,
|
||||||
|
credentials: 'include'
|
||||||
|
}),
|
||||||
|
login: (data) => $fetch(`${baseURL}/auth/login`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: data,
|
||||||
|
credentials: 'include'
|
||||||
|
}),
|
||||||
|
me: () => $fetch(`${baseURL}/auth/me`, {
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
3. Axios Instance
|
||||||
|
// lib/axios.js
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const api = axios.create({
|
||||||
|
baseURL: 'http://localhost:8080/v1',
|
||||||
|
withCredentials: true,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add auth token to requests
|
||||||
|
api.interceptors.request.use((config) => {
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
if (token) {
|
||||||
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle 401 errors
|
||||||
|
api.interceptors.response.use(
|
||||||
|
(response) => response,
|
||||||
|
async (error) => {
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
// Try to refresh token
|
||||||
|
const refreshToken = localStorage.getItem('refresh_token');
|
||||||
|
if (refreshToken) {
|
||||||
|
try {
|
||||||
|
const { data } = await api.post('/auth/refresh', {
|
||||||
|
refresh_token: refreshToken
|
||||||
|
});
|
||||||
|
localStorage.setItem('access_token', data.access_token);
|
||||||
|
// Retry original request
|
||||||
|
error.config.headers.Authorization = `Bearer ${data.access_token}`;
|
||||||
|
return api.request(error.config);
|
||||||
|
} catch {
|
||||||
|
// Refresh failed, logout
|
||||||
|
localStorage.clear();
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default api;
|
||||||
|
🔐 Environment Variables
|
||||||
|
.env.local (Frontend)
|
||||||
|
# Development
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:8080
|
||||||
|
NEXT_PUBLIC_API_VERSION=v1
|
||||||
|
|
||||||
|
# Production
|
||||||
|
# NEXT_PUBLIC_API_URL=https://api.yourdomain.com
|
||||||
|
# NEXT_PUBLIC_API_VERSION=v1
|
||||||
|
.env (Backend)
|
||||||
|
PORT=8080
|
||||||
|
CLIENT_CALLBACK_URL=http://localhost:8080/v1/auth
|
||||||
|
APP_URL=http://localhost:8080
|
||||||
|
🧪 Test Komutları
|
||||||
|
# Register
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Test123!","user_name":"test"}'
|
||||||
|
|
||||||
|
# Login
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Test123!"}'
|
||||||
|
|
||||||
|
# Get user (with token)
|
||||||
|
curl http://localhost:8080/v1/auth/me \
|
||||||
|
-H "Authorization: Bearer YOUR_TOKEN"
|
||||||
|
|
||||||
|
# Admin - Update user
|
||||||
|
curl -X PUT http://localhost:8080/v1/admin/users/54687716-1aed-41ff-aa13-bb05dd7f34e7 \
|
||||||
|
-H "Authorization: Bearer ADMIN_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "newemail@example.com",
|
||||||
|
"user_name": "newusername",
|
||||||
|
"email_verified": true
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Admin - Get all users
|
||||||
|
curl -X GET http://localhost:8080/v1/admin/users?page=1&limit=10 \
|
||||||
|
-H "Authorization: Bearer ADMIN_TOKEN"
|
||||||
|
|
||||||
|
# Admin - Search users
|
||||||
|
curl -X GET "http://localhost:8080/v1/admin/users/search?q=test" \
|
||||||
|
-H "Authorization: Bearer ADMIN_TOKEN"
|
||||||
|
📚 Swagger Dokümantasyonu
|
||||||
|
Tüm endpoint'lerin detaylı dokümantasyonu için:
|
||||||
|
|
||||||
|
http://localhost:8080/docs/index.html
|
||||||
|
✅ Hazır Kullanım
|
||||||
|
API endpoint'leri hazır ve çalışıyor! Frontend'inizde kullanmaya başlayabilirsiniz:
|
||||||
|
|
||||||
|
API_ENDPOINTS.md - Detaylı endpoint dokümantasyonu
|
||||||
|
Swagger UI - İnteraktif API testi: http://localhost:8080/docs/index.html
|
||||||
|
Yukarıdaki örnekleri projenize kopyalayıp kullanabilirsiniz
|
||||||
|
Önemli: CORS zaten http://localhost:3000 için yapılandırılmış durumda! ✅
|
||||||
119
docs/CHANGELOG.md
Normal file
119
docs/CHANGELOG.md
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [1.1.0] - 2026-02-04
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- ✅ **Redis Integration**: Full Redis caching and session management
|
||||||
|
- Session storage with Redis
|
||||||
|
- User data caching
|
||||||
|
- Token blacklist for logout
|
||||||
|
- Email verification token cache
|
||||||
|
- Password reset token cache
|
||||||
|
|
||||||
|
- ✅ **Cache Service**: New dedicated cache service (`internal/services/cache_service.go`)
|
||||||
|
- SetUser/GetUser/DeleteUser for user caching
|
||||||
|
- Session management methods
|
||||||
|
- Rate limiting support
|
||||||
|
- Token blacklist operations
|
||||||
|
- Email verification and password reset token management
|
||||||
|
|
||||||
|
- ✅ **Rate Limiting**: API rate limiting with Redis backend
|
||||||
|
- Login rate limiting: 5 attempts per minute
|
||||||
|
- Registration rate limiting: 3 attempts per 5 minutes
|
||||||
|
- General API rate limiting: 100 requests per minute
|
||||||
|
- Graceful degradation when Redis is unavailable
|
||||||
|
|
||||||
|
- ✅ **CORS Configuration**: Cross-Origin Resource Sharing support
|
||||||
|
- Configurable allowed origins
|
||||||
|
- Credentials support
|
||||||
|
- Multiple HTTP methods allowed
|
||||||
|
|
||||||
|
- ✅ **Docker Compose**: Complete Docker setup with 3 services
|
||||||
|
- PostgreSQL 17 Alpine
|
||||||
|
- Redis 7 Alpine with persistence
|
||||||
|
- Application service with auto-restart
|
||||||
|
|
||||||
|
- ✅ **Documentation**:
|
||||||
|
- README.md with comprehensive project documentation
|
||||||
|
- SETUP.md with detailed setup instructions
|
||||||
|
- .env.example template file
|
||||||
|
- Quick start script (start-with-docker.sh)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- 🔄 Updated `main.go` to initialize Redis connection
|
||||||
|
- 🔄 Updated routes to include rate limiting middlewares
|
||||||
|
- 🔄 Enhanced docker-compose.yml with Redis service
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
- **Redis Client**: go-redis/v9
|
||||||
|
- **CORS Middleware**: gin-contrib/cors
|
||||||
|
- **Default CORS Origin**: http://localhost:3000
|
||||||
|
- **Redis Connection**: Gracefully handles unavailability
|
||||||
|
|
||||||
|
## [1.0.0] - Initial Release
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- JWT-based authentication
|
||||||
|
- OAuth2 integration (Google, GitHub)
|
||||||
|
- Email verification
|
||||||
|
- PostgreSQL database with GORM
|
||||||
|
- Swagger/OpenAPI documentation
|
||||||
|
- User roles and permissions
|
||||||
|
- Password hashing with bcrypt
|
||||||
|
- Protected routes with middleware
|
||||||
|
- Auto-migration and seeding
|
||||||
|
|
||||||
|
### Database Models
|
||||||
|
- Users table with email verification
|
||||||
|
- Social accounts for OAuth
|
||||||
|
- Roles and permissions system
|
||||||
|
- User-Role relationships
|
||||||
|
|
||||||
|
### API Endpoints
|
||||||
|
- POST /v1/auth/register - User registration
|
||||||
|
- POST /v1/auth/login - User login
|
||||||
|
- GET /v1/auth/verify-email - Email verification
|
||||||
|
- POST /v1/auth/refresh - Token refresh
|
||||||
|
- GET /v1/auth/:provider - OAuth login
|
||||||
|
- GET /v1/auth/:provider/callback - OAuth callback
|
||||||
|
- GET /v1/auth/me - Get current user (protected)
|
||||||
|
- GET /v1/auth/validate - Validate token (protected)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Future Roadmap
|
||||||
|
|
||||||
|
### Planned Features
|
||||||
|
- [ ] Email service integration (SMTP)
|
||||||
|
- [ ] Password reset functionality
|
||||||
|
- [ ] 2FA (Two-Factor Authentication)
|
||||||
|
- [ ] User profile management
|
||||||
|
- [ ] Admin dashboard
|
||||||
|
- [ ] Audit logging
|
||||||
|
- [ ] Metrics and monitoring (Prometheus)
|
||||||
|
- [ ] API versioning
|
||||||
|
- [ ] Webhook support
|
||||||
|
- [ ] Multi-tenancy support
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
- [ ] Database query optimization
|
||||||
|
- [ ] Redis clustering support
|
||||||
|
- [ ] Connection pooling enhancements
|
||||||
|
- [ ] Response compression
|
||||||
|
|
||||||
|
### Security Enhancements
|
||||||
|
- [ ] IP whitelisting
|
||||||
|
- [ ] Advanced rate limiting (per user, per endpoint)
|
||||||
|
- [ ] Brute force protection
|
||||||
|
- [ ] Session management dashboard
|
||||||
|
- [ ] Security headers middleware
|
||||||
|
- [ ] CSP (Content Security Policy)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Version History
|
||||||
|
|
||||||
|
- **v1.1.0** - Redis integration, CORS, Rate limiting, Complete documentation
|
||||||
|
- **v1.0.0** - Initial release with basic authentication and OAuth
|
||||||
406
docs/DEPLOYMENT.md
Normal file
406
docs/DEPLOYMENT.md
Normal file
@@ -0,0 +1,406 @@
|
|||||||
|
# 🚀 GAuth-Central Deployment Rehberi
|
||||||
|
|
||||||
|
## 📋 Deployment Senaryoları
|
||||||
|
|
||||||
|
### Senaryo 1: Standalone Deployment (Mevcut Sunucularla)
|
||||||
|
|
||||||
|
Bu senaryoda mevcut PostgreSQL ve Redis sunucularınızı kullanıyorsunuz.
|
||||||
|
|
||||||
|
#### Ön Gereksinimler
|
||||||
|
- ✅ PostgreSQL 17+ sunucusu çalışıyor
|
||||||
|
- ✅ Redis 7+ sunucusu çalışıyor
|
||||||
|
- ✅ Go 1.23+ yüklü
|
||||||
|
- ✅ Sunuculara network erişimi var
|
||||||
|
|
||||||
|
#### Adımlar
|
||||||
|
|
||||||
|
1. **Repository'yi klonlayın**
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd AuthCentral
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **.env dosyasını yapılandırın**
|
||||||
|
```bash
|
||||||
|
# .env dosyasını oluşturun
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Düzenleyin
|
||||||
|
nano .env
|
||||||
|
```
|
||||||
|
|
||||||
|
**.env içeriği:**
|
||||||
|
```env
|
||||||
|
PORT=8080
|
||||||
|
|
||||||
|
# Mevcut PostgreSQL sunucunuz
|
||||||
|
DB_URL="host=10.80.80.70 user=cloud password=xxx dbname=go_gauth port=5432 sslmode=disable TimeZone=Europe/Istanbul"
|
||||||
|
DB_USER=cloud
|
||||||
|
DB_PASSWORD=xxx
|
||||||
|
DB_NAME=go_gauth
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_HOST=10.80.80.70
|
||||||
|
|
||||||
|
# Mevcut Redis sunucunuz
|
||||||
|
REDIS_HOST=10.80.80.70
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_USER=default
|
||||||
|
REDIS_PASSWORD=xxx
|
||||||
|
REDIS_URL=redis://default:xxx@10.80.80.70:6379/0
|
||||||
|
|
||||||
|
# JWT Secret (production için güçlü bir değer)
|
||||||
|
JWT_SECRET=super_secure_production_secret_key_change_this
|
||||||
|
|
||||||
|
# OAuth Credentials
|
||||||
|
GOOGLE_CLIENT_ID=your_client_id
|
||||||
|
GOOGLE_CLIENT_SECRET=your_client_secret
|
||||||
|
GITHUB_CLIENT_ID=your_client_id
|
||||||
|
GITHUB_CLIENT_SECRET=your_client_secret
|
||||||
|
CLIENT_CALLBACK_URL=http://your-domain.com/v1/auth
|
||||||
|
APP_URL=http://your-domain.com
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Bağımlılıkları yükleyin**
|
||||||
|
```bash
|
||||||
|
go mod download
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Bağlantıları test edin**
|
||||||
|
```bash
|
||||||
|
# PostgreSQL bağlantısı
|
||||||
|
PGPASSWORD=xxx psql -h 10.80.80.70 -U cloud -d go_gauth -c "SELECT version();"
|
||||||
|
|
||||||
|
# Redis bağlantısı
|
||||||
|
redis-cli -h 10.80.80.70 -p 6379 -a xxx --no-auth-warning PING
|
||||||
|
```
|
||||||
|
|
||||||
|
5. **Uygulamayı başlatın**
|
||||||
|
```bash
|
||||||
|
# Quick start script ile
|
||||||
|
./start.sh
|
||||||
|
|
||||||
|
# veya systemd service olarak (aşağıya bakın)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Senaryo 2: Docker Compose Deployment
|
||||||
|
|
||||||
|
Tüm servisleri (PostgreSQL, Redis, App) Docker ile çalıştırma.
|
||||||
|
|
||||||
|
#### Adımlar
|
||||||
|
|
||||||
|
1. **Repository'yi klonlayın**
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd AuthCentral
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **.env dosyasını yapılandırın**
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
nano .env
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Docker Compose ile başlatın**
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Logları kontrol edin**
|
||||||
|
```bash
|
||||||
|
docker-compose logs -f app
|
||||||
|
```
|
||||||
|
|
||||||
|
5. **Durum kontrolü**
|
||||||
|
```bash
|
||||||
|
docker-compose ps
|
||||||
|
curl http://localhost:8080/
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Senaryo 3: Production Deployment (Systemd)
|
||||||
|
|
||||||
|
Production ortamında systemd ile çalıştırma.
|
||||||
|
|
||||||
|
#### 1. Systemd Service Dosyası Oluşturun
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nano /etc/systemd/system/gauth-central.service
|
||||||
|
```
|
||||||
|
|
||||||
|
**gauth-central.service:**
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=GAuth-Central Authentication Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=www-data
|
||||||
|
Group=www-data
|
||||||
|
WorkingDirectory=/opt/gauth-central
|
||||||
|
EnvironmentFile=/opt/gauth-central/.env
|
||||||
|
ExecStart=/opt/gauth-central/main
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StandardOutput=append:/var/log/gauth-central/app.log
|
||||||
|
StandardError=append:/var/log/gauth-central/error.log
|
||||||
|
|
||||||
|
# Security
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. Log Dizinini Oluşturun
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mkdir -p /var/log/gauth-central
|
||||||
|
sudo chown www-data:www-data /var/log/gauth-central
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. Uygulamayı Deploy Edin
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Deployment dizinine kopyalayın
|
||||||
|
sudo mkdir -p /opt/gauth-central
|
||||||
|
sudo cp -r . /opt/gauth-central/
|
||||||
|
cd /opt/gauth-central
|
||||||
|
|
||||||
|
# Build edin
|
||||||
|
go build -o main .
|
||||||
|
|
||||||
|
# İzinleri ayarlayın
|
||||||
|
sudo chown -R www-data:www-data /opt/gauth-central
|
||||||
|
sudo chmod +x /opt/gauth-central/main
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4. Service'i Başlatın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable gauth-central
|
||||||
|
sudo systemctl start gauth-central
|
||||||
|
sudo systemctl status gauth-central
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5. Logları İzleyin
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Real-time logs
|
||||||
|
sudo journalctl -u gauth-central -f
|
||||||
|
|
||||||
|
# Son 100 satır
|
||||||
|
sudo journalctl -u gauth-central -n 100
|
||||||
|
|
||||||
|
# Application logs
|
||||||
|
tail -f /var/log/gauth-central/app.log
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 Production Checklist
|
||||||
|
|
||||||
|
### Güvenlik
|
||||||
|
|
||||||
|
- [ ] JWT_SECRET güçlü bir değer olarak ayarlandı
|
||||||
|
- [ ] PostgreSQL şifreleri güçlü
|
||||||
|
- [ ] Redis şifre koruması aktif
|
||||||
|
- [ ] SSL/TLS sertifikaları yapılandırıldı (Nginx/Caddy ile)
|
||||||
|
- [ ] CORS AllowOrigins production domain'lere güncellendi
|
||||||
|
- [ ] Firewall kuralları ayarlandı
|
||||||
|
- [ ] PostgreSQL sslmode=require (production)
|
||||||
|
- [ ] Rate limiting limitleri gözden geçirildi
|
||||||
|
|
||||||
|
### Performance
|
||||||
|
|
||||||
|
- [ ] PostgreSQL connection pooling ayarları
|
||||||
|
- [ ] Redis max memory policy ayarlandı
|
||||||
|
- [ ] Log rotation yapılandırıldı
|
||||||
|
- [ ] Monitoring kuruldu (Prometheus/Grafana)
|
||||||
|
- [ ] Health check endpoint'i aktif
|
||||||
|
|
||||||
|
### Backup
|
||||||
|
|
||||||
|
- [ ] PostgreSQL otomatik backup
|
||||||
|
- [ ] Redis persistence yapılandırması
|
||||||
|
- [ ] Backup restore testi yapıldı
|
||||||
|
|
||||||
|
### Monitoring
|
||||||
|
|
||||||
|
- [ ] Application logs toplanıyor
|
||||||
|
- [ ] Error tracking (Sentry vb.)
|
||||||
|
- [ ] Uptime monitoring
|
||||||
|
- [ ] Resource monitoring (CPU, RAM, Disk)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌐 Nginx Reverse Proxy
|
||||||
|
|
||||||
|
Production'da Nginx kullanarak SSL termination:
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name api.yourdomain.com;
|
||||||
|
return 301 https://$server_name$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
server_name api.yourdomain.com;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/api.yourdomain.com/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/api.yourdomain.com/privkey.pem;
|
||||||
|
|
||||||
|
# Security headers
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-XSS-Protection "1; mode=block" always;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:8080;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 Health Checks
|
||||||
|
|
||||||
|
### Application Health Check
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl http://localhost:8080/
|
||||||
|
```
|
||||||
|
|
||||||
|
### PostgreSQL Health
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PGPASSWORD=xxx psql -h 10.80.80.70 -U cloud -d go_gauth -c "SELECT 1;"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Redis Health
|
||||||
|
|
||||||
|
```bash
|
||||||
|
redis-cli -h 10.80.80.70 -p 6379 -a xxx --no-auth-warning PING
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 Update/Rollback Prosedürü
|
||||||
|
|
||||||
|
### Update
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/gauth-central
|
||||||
|
|
||||||
|
# Backup
|
||||||
|
sudo cp main main.backup
|
||||||
|
|
||||||
|
# Pull updates
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# Build
|
||||||
|
go build -o main .
|
||||||
|
|
||||||
|
# Restart service
|
||||||
|
sudo systemctl restart gauth-central
|
||||||
|
|
||||||
|
# Check status
|
||||||
|
sudo systemctl status gauth-central
|
||||||
|
|
||||||
|
# Check logs
|
||||||
|
sudo journalctl -u gauth-central -f
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rollback
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/gauth-central
|
||||||
|
|
||||||
|
# Restore backup
|
||||||
|
sudo cp main.backup main
|
||||||
|
|
||||||
|
# Restart
|
||||||
|
sudo systemctl restart gauth-central
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### Service başlamıyor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Logs kontrol
|
||||||
|
sudo journalctl -u gauth-central -n 50
|
||||||
|
|
||||||
|
# Config kontrol
|
||||||
|
cat /opt/gauth-central/.env
|
||||||
|
|
||||||
|
# Permissions kontrol
|
||||||
|
ls -la /opt/gauth-central/main
|
||||||
|
```
|
||||||
|
|
||||||
|
### PostgreSQL bağlantı hatası
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Bağlantı testi
|
||||||
|
PGPASSWORD=xxx psql -h HOST -U USER -d DB -c "SELECT 1;"
|
||||||
|
|
||||||
|
# Network kontrolü
|
||||||
|
telnet HOST 5432
|
||||||
|
```
|
||||||
|
|
||||||
|
### Redis bağlantı hatası
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Redis testi
|
||||||
|
redis-cli -h HOST -p PORT -a PASSWORD PING
|
||||||
|
|
||||||
|
# Network kontrolü
|
||||||
|
telnet HOST 6379
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 Environment Variables Reference
|
||||||
|
|
||||||
|
| Variable | Required | Example | Description |
|
||||||
|
|----------|----------|---------|-------------|
|
||||||
|
| `PORT` | Yes | `8080` | Application port |
|
||||||
|
| `DB_URL` | Yes | `host=...` | PostgreSQL connection string |
|
||||||
|
| `REDIS_URL` | Yes | `redis://...` | Redis connection URL |
|
||||||
|
| `JWT_SECRET` | Yes | `secret123` | JWT signing key |
|
||||||
|
| `GOOGLE_CLIENT_ID` | No | `xxx.apps.googleusercontent.com` | Google OAuth |
|
||||||
|
| `GITHUB_CLIENT_ID` | No | `Ov23li...` | GitHub OAuth |
|
||||||
|
| `CLIENT_CALLBACK_URL` | Yes | `http://localhost:8080/v1/auth` | OAuth callback base URL |
|
||||||
|
| `APP_URL` | Yes | `http://localhost:8080` | Application URL |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 Next Steps
|
||||||
|
|
||||||
|
1. Setup monitoring (Prometheus + Grafana)
|
||||||
|
2. Configure log aggregation (ELK Stack)
|
||||||
|
3. Setup automated backups
|
||||||
|
4. Configure CI/CD pipeline
|
||||||
|
5. Setup staging environment
|
||||||
|
6. Configure load balancing (if needed)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
💡 **Pro Tip**: Her deployment öncesi staging ortamında test edin!
|
||||||
166
docs/QUICKSTART.txt
Normal file
166
docs/QUICKSTART.txt
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
╔═══════════════════════════════════════════════════════════════════════╗
|
||||||
|
║ 🚀 GAuth-Central Quick Start ║
|
||||||
|
╚═══════════════════════════════════════════════════════════════════════╝
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🎯 HIZLI BAŞLATMA │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
Standalone Mode (Mevcut Sunucularla):
|
||||||
|
────────────────────────────────────────
|
||||||
|
$ ./start.sh
|
||||||
|
|
||||||
|
Docker Mode (Tüm Servisler):
|
||||||
|
────────────────────────────
|
||||||
|
$ ./start-with-docker.sh
|
||||||
|
|
||||||
|
Manuel:
|
||||||
|
───────
|
||||||
|
$ go run main.go
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🌐 ERİŞİM NOKTALARI │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
API: http://localhost:8080
|
||||||
|
Swagger: http://localhost:8080/docs/index.html
|
||||||
|
Frontend: http://localhost:3000 (CORS enabled)
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🔧 MEVCUT YAPILANDIRMA │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
PostgreSQL: 10.80.80.70:5432/go_gauth (user: cloud)
|
||||||
|
Redis: 10.80.80.70:6379 (user: default)
|
||||||
|
Backend: localhost:8080
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🧪 TEST KOMUTLARI │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
Sağlık Kontrolü:
|
||||||
|
────────────────
|
||||||
|
$ curl http://localhost:8080/
|
||||||
|
|
||||||
|
PostgreSQL Test:
|
||||||
|
────────────────
|
||||||
|
$ PGPASSWORD=gg7678290 psql -h 10.80.80.70 -U cloud \
|
||||||
|
-d go_gauth -c "SELECT 1;"
|
||||||
|
|
||||||
|
Redis Test:
|
||||||
|
───────────
|
||||||
|
$ redis-cli -h 10.80.80.70 -p 6379 -a gg7678290 \
|
||||||
|
--no-auth-warning PING
|
||||||
|
|
||||||
|
Kullanıcı Kaydı:
|
||||||
|
────────────────
|
||||||
|
$ curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Pass123!",
|
||||||
|
"user_name":"test"}'
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 📚 DOKÜMANTASYON │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
README.md - Genel bilgiler ve özellikler
|
||||||
|
SETUP.md - Detaylı kurulum rehberi (4 seçenek)
|
||||||
|
DEPLOYMENT.md - Production deployment rehberi
|
||||||
|
QUICK_REFERENCE.md - Komutlar ve örnekler
|
||||||
|
CHANGELOG.md - Versiyon geçmişi
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ ✨ ÖNE ÇIKAN ÖZELLİKLER │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
✅ CORS yapılandırması (localhost:3000)
|
||||||
|
✅ Redis cache & session management
|
||||||
|
✅ Rate limiting (Login: 5/min, Register: 3/5min)
|
||||||
|
✅ JWT authentication
|
||||||
|
✅ OAuth2 (Google, GitHub)
|
||||||
|
✅ Email verification
|
||||||
|
✅ PostgreSQL + GORM
|
||||||
|
✅ Swagger documentation
|
||||||
|
✅ Docker support
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🔐 GÜVENLİK ÖZELLİKLERİ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
• Bcrypt password hashing
|
||||||
|
• JWT token authentication
|
||||||
|
• Rate limiting (brute force protection)
|
||||||
|
• Token blacklist (logout)
|
||||||
|
• CORS policy
|
||||||
|
• Session management with Redis
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 📊 API ENDPOINTS │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
POST /v1/auth/register - Kayıt (rate limited)
|
||||||
|
POST /v1/auth/login - Giriş (rate limited)
|
||||||
|
GET /v1/auth/verify-email - Email doğrulama
|
||||||
|
POST /v1/auth/refresh - Token yenileme
|
||||||
|
GET /v1/auth/me [Auth] - Kullanıcı bilgileri
|
||||||
|
GET /v1/auth/validate [Auth] - Token doğrulama
|
||||||
|
GET /v1/auth/:provider - OAuth (google/github)
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🛠️ YARARLI KOMUTLAR │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
Build: go build -o main .
|
||||||
|
Run: ./main
|
||||||
|
Dev Mode: go run main.go
|
||||||
|
Swagger Update: swag init -g main.go
|
||||||
|
Dependencies: go mod tidy
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 📦 SİSTEM GEREKSİNİMLERİ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
• Go 1.23+
|
||||||
|
• PostgreSQL 17+ erişimi (10.80.80.70:5432)
|
||||||
|
• Redis 7+ erişimi (10.80.80.70:6379)
|
||||||
|
• Network bağlantısı
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 🚨 SORUN GİDERME │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
PostgreSQL bağlanamıyor:
|
||||||
|
────────────────────────
|
||||||
|
• .env dosyasında DB_URL kontrol edin
|
||||||
|
• Network erişimini test edin: telnet 10.80.80.70 5432
|
||||||
|
• Kullanıcı adı/şifre doğru mu kontrol edin
|
||||||
|
|
||||||
|
Redis bağlanamıyor:
|
||||||
|
──────────────────
|
||||||
|
• REDIS_URL doğru mu kontrol edin
|
||||||
|
• Network erişimi: telnet 10.80.80.70 6379
|
||||||
|
• Redis şifresini kontrol edin
|
||||||
|
|
||||||
|
CORS hatası:
|
||||||
|
────────────
|
||||||
|
• main.go'da AllowOrigins kontrol edin
|
||||||
|
• Frontend URL'i http://localhost:3000 mi?
|
||||||
|
|
||||||
|
Rate limit:
|
||||||
|
───────────
|
||||||
|
• api/middlewares/rate_limit_middleware.go'da
|
||||||
|
limit değerlerini artırın
|
||||||
|
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ 📞 DAHA FAZLA BİLGİ │
|
||||||
|
└─────────────────────────────────────────────────────────────────────┘
|
||||||
|
|
||||||
|
Tüm detaylar için dokümantasyon dosyalarına bakın:
|
||||||
|
|
||||||
|
$ cat README.md
|
||||||
|
$ cat SETUP.md
|
||||||
|
$ cat DEPLOYMENT.md
|
||||||
|
|
||||||
|
╔═══════════════════════════════════════════════════════════════════════╗
|
||||||
|
║ 🎉 Başarılı çalışmalar! Sorularınız için dokümantasyona bakın. ║
|
||||||
|
╚═══════════════════════════════════════════════════════════════════════╝
|
||||||
267
docs/QUICK_REFERENCE.md
Normal file
267
docs/QUICK_REFERENCE.md
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
# 🚀 GAuth-Central - Quick Reference
|
||||||
|
|
||||||
|
## 🏃 Hızlı Başlatma
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Standalone Mode (Mevcut PostgreSQL & Redis ile)
|
||||||
|
./start.sh
|
||||||
|
|
||||||
|
# Docker ile (Tüm servisler)
|
||||||
|
./start-with-docker.sh
|
||||||
|
|
||||||
|
# Manuel
|
||||||
|
go run main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔗 Önemli URL'ler
|
||||||
|
|
||||||
|
| Servis | URL | Açıklama |
|
||||||
|
|--------|-----|----------|
|
||||||
|
| API | http://localhost:8080 | Ana API |
|
||||||
|
| Swagger | http://localhost:8080/docs/index.html | API Dokümantasyonu |
|
||||||
|
| PostgreSQL | localhost:5432 | Database |
|
||||||
|
| Redis | localhost:6379 | Cache |
|
||||||
|
|
||||||
|
## 📝 Temel Komutlar
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Docker Servisleri
|
||||||
|
docker-compose up -d # Başlat
|
||||||
|
docker-compose down # Durdur
|
||||||
|
docker-compose down -v # Durdur + Volume'ları sil
|
||||||
|
docker-compose logs -f app # Logları izle
|
||||||
|
docker-compose ps # Servis durumları
|
||||||
|
|
||||||
|
# Go Komutları
|
||||||
|
go run main.go # Çalıştır
|
||||||
|
go build -o main . # Derle
|
||||||
|
go mod tidy # Bağımlılıkları temizle
|
||||||
|
swag init -g main.go # Swagger güncelle
|
||||||
|
|
||||||
|
# Redis Komutları
|
||||||
|
docker exec -it gauth_redis redis-cli
|
||||||
|
> PING # Bağlantı testi
|
||||||
|
> KEYS * # Tüm key'leri listele
|
||||||
|
> GET user:UUID # User cache getir
|
||||||
|
> DEL session:TOKEN # Session sil
|
||||||
|
> FLUSHDB # Tüm cache'i temizle
|
||||||
|
|
||||||
|
# PostgreSQL Komutları
|
||||||
|
docker exec -it gauth_postgres psql -U postgres -d gauth
|
||||||
|
\dt # Tabloları listele
|
||||||
|
\d users # Users tablosu yapısı
|
||||||
|
SELECT * FROM roles; # Rolleri listele
|
||||||
|
SELECT * FROM users LIMIT 10; # Kullanıcıları listele
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Environment Variables
|
||||||
|
|
||||||
|
| Değişken | Varsayılan | Açıklama |
|
||||||
|
|----------|------------|----------|
|
||||||
|
| `PORT` | 8080 | Server portu |
|
||||||
|
| `DB_URL` | - | PostgreSQL bağlantısı |
|
||||||
|
| `REDIS_URL` | - | Redis bağlantısı |
|
||||||
|
| `JWT_SECRET` | - | JWT gizli anahtar |
|
||||||
|
| `GOOGLE_CLIENT_ID` | - | Google OAuth |
|
||||||
|
| `GITHUB_CLIENT_ID` | - | GitHub OAuth |
|
||||||
|
|
||||||
|
## 📡 API Endpoints
|
||||||
|
|
||||||
|
### Public Endpoints
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Register
|
||||||
|
POST /v1/auth/register
|
||||||
|
{
|
||||||
|
"email": "user@example.com",
|
||||||
|
"password": "SecurePass123!",
|
||||||
|
"user_name": "username"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Login
|
||||||
|
POST /v1/auth/login
|
||||||
|
{
|
||||||
|
"email": "user@example.com",
|
||||||
|
"password": "SecurePass123!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# OAuth
|
||||||
|
GET /v1/auth/google
|
||||||
|
GET /v1/auth/github
|
||||||
|
|
||||||
|
# Verify Email
|
||||||
|
GET /v1/auth/verify-email?token=...
|
||||||
|
|
||||||
|
# Refresh Token
|
||||||
|
POST /v1/auth/refresh
|
||||||
|
{
|
||||||
|
"refresh_token": "..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Protected Endpoints (Requires Authorization Header)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Get User Info
|
||||||
|
GET /v1/auth/me
|
||||||
|
Authorization: Bearer <token>
|
||||||
|
|
||||||
|
# Validate Token
|
||||||
|
GET /v1/auth/validate
|
||||||
|
Authorization: Bearer <token>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🛡️ Rate Limits
|
||||||
|
|
||||||
|
| Endpoint | Limit | Süre |
|
||||||
|
|----------|-------|------|
|
||||||
|
| `/v1/auth/login` | 5 | 1 dakika |
|
||||||
|
| `/v1/auth/register` | 3 | 5 dakika |
|
||||||
|
| Genel API | 100 | 1 dakika |
|
||||||
|
|
||||||
|
## 🗄️ Redis Keys
|
||||||
|
|
||||||
|
| Pattern | Açıklama | TTL |
|
||||||
|
|---------|----------|-----|
|
||||||
|
| `user:{id}` | User cache | 1 saat |
|
||||||
|
| `session:{token}` | Session data | 24 saat |
|
||||||
|
| `blacklist:{token}` | Invalidated tokens | 24 saat |
|
||||||
|
| `ratelimit:{key}` | Rate limit counters | Dinamik |
|
||||||
|
| `email_verify:{email}` | Email verification | Dinamik |
|
||||||
|
| `password_reset:{email}` | Password reset | Dinamik |
|
||||||
|
|
||||||
|
## 🧪 Test Komutları
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Health Check
|
||||||
|
curl http://localhost:8080/
|
||||||
|
|
||||||
|
# Register Test
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Test123!","user_name":"testuser"}'
|
||||||
|
|
||||||
|
# Login Test
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"test@test.com","password":"Test123!"}'
|
||||||
|
|
||||||
|
# Get User Info (with token)
|
||||||
|
curl http://localhost:8080/v1/auth/me \
|
||||||
|
-H "Authorization: Bearer YOUR_TOKEN_HERE"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 Sorun Giderme
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Servis durumlarını kontrol et
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
# App loglarını kontrol et
|
||||||
|
docker-compose logs app
|
||||||
|
|
||||||
|
# Redis bağlantısı
|
||||||
|
docker exec -it gauth_redis redis-cli PING
|
||||||
|
|
||||||
|
# PostgreSQL bağlantısı
|
||||||
|
docker exec -it gauth_postgres pg_isready -U postgres
|
||||||
|
|
||||||
|
# Container'ı yeniden başlat
|
||||||
|
docker-compose restart app
|
||||||
|
|
||||||
|
# Tüm servisleri yeniden oluştur
|
||||||
|
docker-compose down
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📊 Database Schema
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- Users Table
|
||||||
|
users (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
email VARCHAR UNIQUE,
|
||||||
|
user_name VARCHAR NOT NULL,
|
||||||
|
password_hash VARCHAR,
|
||||||
|
email_verified BOOLEAN,
|
||||||
|
email_verify_token VARCHAR,
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Roles Table
|
||||||
|
roles (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
name VARCHAR UNIQUE,
|
||||||
|
description TEXT
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Permissions Table
|
||||||
|
permissions (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
name VARCHAR UNIQUE,
|
||||||
|
description TEXT
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔐 CORS Yapılandırması
|
||||||
|
|
||||||
|
Varsayılan: `http://localhost:3000`
|
||||||
|
|
||||||
|
Değiştirmek için `main.go`:
|
||||||
|
```go
|
||||||
|
AllowOrigins: []string{
|
||||||
|
"http://localhost:3000",
|
||||||
|
"https://yourdomain.com",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📚 Cache Service Örnekleri
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "gauth-central/internal/services"
|
||||||
|
|
||||||
|
cache := services.NewCacheService()
|
||||||
|
|
||||||
|
// User caching
|
||||||
|
cache.SetUser(userID, user, 1*time.Hour)
|
||||||
|
user, err := cache.GetUser(userID)
|
||||||
|
|
||||||
|
// Session
|
||||||
|
cache.SetSession(token, userID, 24*time.Hour)
|
||||||
|
userID, err := cache.GetSession(token)
|
||||||
|
|
||||||
|
// Rate limiting
|
||||||
|
count, err := cache.IncrementRateLimit("login:"+ip, 1*time.Minute)
|
||||||
|
if count > 5 {
|
||||||
|
// Rate limit exceeded
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token blacklist
|
||||||
|
cache.BlacklistToken(token, 24*time.Hour)
|
||||||
|
isBlacklisted, err := cache.IsTokenBlacklisted(token)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🎯 Önemli Dosyalar
|
||||||
|
|
||||||
|
| Dosya | Açıklama |
|
||||||
|
|-------|----------|
|
||||||
|
| `main.go` | Ana uygulama |
|
||||||
|
| `config/config.go` | Yapılandırma |
|
||||||
|
| `internal/database/redis.go` | Redis bağlantısı |
|
||||||
|
| `internal/services/cache_service.go` | Cache servisi |
|
||||||
|
| `api/routes/routes.go` | Route tanımları |
|
||||||
|
| `api/middlewares/rate_limit_middleware.go` | Rate limiting |
|
||||||
|
| `docker-compose.yml` | Docker yapılandırması |
|
||||||
|
| `.env` | Environment variables |
|
||||||
|
|
||||||
|
## 📖 Dokümantasyon
|
||||||
|
|
||||||
|
- `README.md` - Genel proje bilgisi
|
||||||
|
- `SETUP.md` - Detaylı kurulum rehberi
|
||||||
|
- `CHANGELOG.md` - Versiyon geçmişi
|
||||||
|
- `QUICK_REFERENCE.md` - Bu dosya
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
💡 **İpucu**: Swagger UI'da tüm endpoint'leri test edebilirsiniz: http://localhost:8080/docs/index.html
|
||||||
558
docs/SETTINGS_API.md
Normal file
558
docs/SETTINGS_API.md
Normal file
@@ -0,0 +1,558 @@
|
|||||||
|
# 🔧 CORS & Rate Limit Yönetim API'si
|
||||||
|
|
||||||
|
## Yeni Endpoint'ler
|
||||||
|
|
||||||
|
### Base URL
|
||||||
|
```
|
||||||
|
http://localhost:8080/v1/settings
|
||||||
|
```
|
||||||
|
|
||||||
|
**Not:** Tüm settings endpoint'leri authentication gerektirir (Bearer token).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 CORS Whitelist Yönetimi
|
||||||
|
|
||||||
|
### 1. Tüm Whitelist Kayıtlarını Getir
|
||||||
|
```
|
||||||
|
GET /v1/settings/cors/whitelist
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "http://localhost:3000",
|
||||||
|
"description": "Default local frontend",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "system",
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Yeni Whitelist Ekle
|
||||||
|
```
|
||||||
|
POST /v1/settings/cors/whitelist
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "https://example.com",
|
||||||
|
"description": "Production frontend"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (201):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "https://example.com",
|
||||||
|
"description": "Production frontend",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "user@example.com",
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Whitelist Güncelle
|
||||||
|
```
|
||||||
|
PUT /v1/settings/cors/whitelist/{id}
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "https://newdomain.com",
|
||||||
|
"description": "Updated description",
|
||||||
|
"is_active": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Whitelist updated successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Whitelist Sil
|
||||||
|
```
|
||||||
|
DELETE /v1/settings/cors/whitelist/{id}
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Whitelist entry deleted successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚫 CORS Blacklist Yönetimi
|
||||||
|
|
||||||
|
### 1. Tüm Blacklist Kayıtlarını Getir
|
||||||
|
```
|
||||||
|
GET /v1/settings/cors/blacklist
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "http://malicious-site.com",
|
||||||
|
"reason": "Security threat",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "admin@example.com",
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Yeni Blacklist Ekle
|
||||||
|
```
|
||||||
|
POST /v1/settings/cors/blacklist
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "http://spam-site.com",
|
||||||
|
"reason": "Spam attempts detected"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (201):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"origin": "http://spam-site.com",
|
||||||
|
"reason": "Spam attempts detected",
|
||||||
|
"is_active": true,
|
||||||
|
"created_by": "user@example.com",
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Blacklist Güncelle
|
||||||
|
```
|
||||||
|
PUT /v1/settings/cors/blacklist/{id}
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"origin": "http://updated-domain.com",
|
||||||
|
"reason": "Updated reason",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Blacklist updated successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Blacklist Sil
|
||||||
|
```
|
||||||
|
DELETE /v1/settings/cors/blacklist/{id}
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Blacklist entry deleted successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚡ Rate Limit Ayarları Yönetimi
|
||||||
|
|
||||||
|
### 1. Tüm Rate Limit Ayarlarını Getir
|
||||||
|
```
|
||||||
|
GET /v1/settings/ratelimit
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"name": "login",
|
||||||
|
"description": "Login endpoint rate limit",
|
||||||
|
"max_requests": 5,
|
||||||
|
"window_seconds": 60,
|
||||||
|
"is_active": true,
|
||||||
|
"updated_by": "admin@example.com",
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"name": "register",
|
||||||
|
"description": "Registration endpoint rate limit",
|
||||||
|
"max_requests": 3,
|
||||||
|
"window_seconds": 300,
|
||||||
|
"is_active": true,
|
||||||
|
"updated_by": null,
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "uuid",
|
||||||
|
"name": "api",
|
||||||
|
"description": "General API rate limit",
|
||||||
|
"max_requests": 100,
|
||||||
|
"window_seconds": 60,
|
||||||
|
"is_active": true,
|
||||||
|
"updated_by": null,
|
||||||
|
"created_at": "2026-02-04T00:00:00Z",
|
||||||
|
"updated_at": "2026-02-04T00:00:00Z"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Rate Limit Ayarını Güncelle
|
||||||
|
```
|
||||||
|
PUT /v1/settings/ratelimit/{id}
|
||||||
|
Authorization: Bearer {token}
|
||||||
|
Content-Type: application/json
|
||||||
|
```
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"max_requests": 10,
|
||||||
|
"window_seconds": 120,
|
||||||
|
"description": "Updated rate limit",
|
||||||
|
"is_active": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response (200):**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"message": "Rate limit setting updated successfully"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 Çalışma Mantığı
|
||||||
|
|
||||||
|
### CORS Kontrolü
|
||||||
|
|
||||||
|
1. **Request gelir** → Origin header okunur
|
||||||
|
2. **Blacklist kontrolü** → Origin blacklist'te var mı?
|
||||||
|
- Varsa → **403 Forbidden**
|
||||||
|
3. **Whitelist kontrolü** → Origin whitelist'te var mı?
|
||||||
|
- Varsa → **İzin ver**
|
||||||
|
- Yoksa → **403 Forbidden**
|
||||||
|
|
||||||
|
### Cache Stratejisi
|
||||||
|
|
||||||
|
- **Whitelist/Blacklist**: 1 saat cache
|
||||||
|
- **Rate Limit Settings**: 1 saat cache
|
||||||
|
- Her CRUD işleminden sonra ilgili cache **invalidate** edilir
|
||||||
|
- Database'den tekrar okunur ve cache'lenir
|
||||||
|
|
||||||
|
### Rate Limiting
|
||||||
|
|
||||||
|
1. **Database'den ayarlar okunur** (cache'den veya DB'den)
|
||||||
|
2. **IP bazlı sayaç** Redis'te tutulur
|
||||||
|
3. **Limit aşılırsa** → **429 Too Many Requests**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 Kullanım Örnekleri
|
||||||
|
|
||||||
|
### JavaScript/TypeScript
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const API_BASE = 'http://localhost:8080/v1/settings';
|
||||||
|
const token = localStorage.getItem('access_token');
|
||||||
|
|
||||||
|
// Whitelist'e yeni origin ekle
|
||||||
|
async function addToWhitelist(origin, description) {
|
||||||
|
const response = await fetch(`${API_BASE}/cors/whitelist`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ origin, description })
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rate limit ayarlarını getir
|
||||||
|
async function getRateLimits() {
|
||||||
|
const response = await fetch(`${API_BASE}/ratelimit`, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rate limit güncelle
|
||||||
|
async function updateRateLimit(id, maxRequests, windowSeconds) {
|
||||||
|
const response = await fetch(`${API_BASE}/ratelimit/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
max_requests: maxRequests,
|
||||||
|
window_seconds: windowSeconds
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blacklist'e ekle
|
||||||
|
async function addToBlacklist(origin, reason) {
|
||||||
|
const response = await fetch(`${API_BASE}/cors/blacklist`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ origin, reason })
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### cURL Örnekleri
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Token al (önce login)
|
||||||
|
TOKEN="your_access_token_here"
|
||||||
|
|
||||||
|
# Whitelist'i görüntüle
|
||||||
|
curl -X GET http://localhost:8080/v1/settings/cors/whitelist \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
|
||||||
|
# Yeni origin ekle
|
||||||
|
curl -X POST http://localhost:8080/v1/settings/cors/whitelist \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"origin": "https://myapp.com",
|
||||||
|
"description": "Production app"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Whitelist güncelle
|
||||||
|
curl -X PUT http://localhost:8080/v1/settings/cors/whitelist/UUID_HERE \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"is_active": false
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Blacklist'e ekle
|
||||||
|
curl -X POST http://localhost:8080/v1/settings/cors/blacklist \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"origin": "http://bad-site.com",
|
||||||
|
"reason": "Security threat"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Rate limit ayarlarını görüntüle
|
||||||
|
curl -X GET http://localhost:8080/v1/settings/ratelimit \
|
||||||
|
-H "Authorization: Bearer $TOKEN"
|
||||||
|
|
||||||
|
# Rate limit güncelle
|
||||||
|
curl -X PUT http://localhost:8080/v1/settings/ratelimit/UUID_HERE \
|
||||||
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"max_requests": 20,
|
||||||
|
"window_seconds": 60,
|
||||||
|
"description": "Updated login limit"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗄️ Database Tabloları
|
||||||
|
|
||||||
|
### cors_whitelists
|
||||||
|
```sql
|
||||||
|
CREATE TABLE cors_whitelists (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
origin VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
is_active BOOLEAN DEFAULT true,
|
||||||
|
created_by VARCHAR(255),
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### cors_blacklists
|
||||||
|
```sql
|
||||||
|
CREATE TABLE cors_blacklists (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
origin VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
reason TEXT,
|
||||||
|
is_active BOOLEAN DEFAULT true,
|
||||||
|
created_by VARCHAR(255),
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### rate_limit_settings
|
||||||
|
```sql
|
||||||
|
CREATE TABLE rate_limit_settings (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
name VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
max_requests BIGINT NOT NULL,
|
||||||
|
window_seconds INTEGER NOT NULL,
|
||||||
|
is_active BOOLEAN DEFAULT true,
|
||||||
|
updated_by VARCHAR(255),
|
||||||
|
created_at TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ Default Ayarlar
|
||||||
|
|
||||||
|
Uygulama ilk kez başlatıldığında otomatik olarak şu ayarlar oluşturulur:
|
||||||
|
|
||||||
|
### CORS Whitelist
|
||||||
|
- `http://localhost:3000` - Default local frontend
|
||||||
|
- `http://localhost:8080` - Backend self
|
||||||
|
|
||||||
|
### Rate Limit Settings
|
||||||
|
- **login**: 5 istek / 60 saniye
|
||||||
|
- **register**: 3 istek / 300 saniye
|
||||||
|
- **api**: 100 istek / 60 saniye
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔐 Güvenlik Notları
|
||||||
|
|
||||||
|
1. **Authentication Zorunlu**: Tüm settings endpoint'leri authentication gerektirir
|
||||||
|
2. **Admin Kontrolü**: Şu anda tüm authenticated kullanıcılar yönetebilir (TODO: Admin role check eklenecek)
|
||||||
|
3. **Cache**: Değişiklikler 1 saat boyunca cache'de kalır
|
||||||
|
4. **Blacklist Önceliği**: Blacklist kontrolü whitelist'ten önce yapılır
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 Frontend Admin Panel Örneği
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Admin Panel Component
|
||||||
|
class CorsManagement {
|
||||||
|
constructor() {
|
||||||
|
this.api = 'http://localhost:8080/v1/settings';
|
||||||
|
this.token = localStorage.getItem('access_token');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getWhitelist() {
|
||||||
|
const res = await fetch(`${this.api}/cors/whitelist`, {
|
||||||
|
headers: { 'Authorization': `Bearer ${this.token}` }
|
||||||
|
});
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async addWhitelist(origin, description) {
|
||||||
|
const res = await fetch(`${this.api}/cors/whitelist`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ origin, description })
|
||||||
|
});
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateWhitelist(id, data) {
|
||||||
|
const res = await fetch(`${this.api}/cors/whitelist/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${this.token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteWhitelist(id) {
|
||||||
|
const res = await fetch(`${this.api}/cors/whitelist/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: { 'Authorization': `Bearer ${this.token}` }
|
||||||
|
});
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kullanım
|
||||||
|
const corsManager = new CorsManagement();
|
||||||
|
|
||||||
|
// Whitelist listele
|
||||||
|
corsManager.getWhitelist().then(data => {
|
||||||
|
console.log('Whitelist:', data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Yeni ekle
|
||||||
|
corsManager.addWhitelist('https://myapp.com', 'Production app');
|
||||||
|
|
||||||
|
// Güncelle
|
||||||
|
corsManager.updateWhitelist('uuid-here', { is_active: false });
|
||||||
|
|
||||||
|
// Sil
|
||||||
|
corsManager.deleteWhitelist('uuid-here');
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Özet
|
||||||
|
|
||||||
|
Artık CORS whitelist/blacklist ve rate limit ayarlarını:
|
||||||
|
|
||||||
|
- ✅ **Database'de** saklayabiliyorsunuz
|
||||||
|
- ✅ **Redis ile cache**'leyebiliyorsunuz
|
||||||
|
- ✅ **Frontend'den yönetebiliyorsunuz**
|
||||||
|
- ✅ **CRUD işlemleri** yapabiliyorsunuz
|
||||||
|
- ✅ **Dinamik olarak** güncelleyebiliyorsunuz
|
||||||
|
|
||||||
|
Tüm ayarlar database'de tutulur, değişiklikler anında Redis cache'ini invalidate eder ve yeni değerler kullanılmaya başlanır!
|
||||||
328
docs/SETUP.md
Normal file
328
docs/SETUP.md
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
# 🚀 GAuth-Central Kurulum Rehberi
|
||||||
|
|
||||||
|
## Hızlı Başlangıç
|
||||||
|
|
||||||
|
### Option 1: Standalone Mode (Mevcut Sunucular ile)
|
||||||
|
|
||||||
|
Eğer zaten çalışan PostgreSQL ve Redis sunucularınız varsa:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. .env dosyasını kontrol edin ve sunucu bilgilerini girin
|
||||||
|
# DB_URL="host=YOUR_HOST user=YOUR_USER password=YOUR_PASS dbname=YOUR_DB..."
|
||||||
|
# REDIS_URL=redis://user:pass@YOUR_HOST:6379/0
|
||||||
|
|
||||||
|
# 2. Uygulamayı başlatın
|
||||||
|
./start.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Script şunları yapacaktır:
|
||||||
|
- ✅ .env dosyasını kontrol eder
|
||||||
|
- ✅ PostgreSQL bağlantısını test eder
|
||||||
|
- ✅ Redis bağlantısını test eder
|
||||||
|
- ✅ Uygulamayı derler ve başlatır
|
||||||
|
|
||||||
|
### Option 2: Docker ile (Yeni Kurulum)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Start-with-docker scriptini çalıştırın
|
||||||
|
./start-with-docker.sh
|
||||||
|
|
||||||
|
# 2. Logları izleyin
|
||||||
|
docker-compose logs -f app
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 2: Docker ile (Yeni Kurulum)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Start-with-docker scriptini çalıştırın
|
||||||
|
./start-with-docker.sh
|
||||||
|
|
||||||
|
# 2. Logları izleyin
|
||||||
|
docker-compose logs -f app
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 3: Manuel Kurulum (Sadece Uygulama)
|
||||||
|
|
||||||
|
**Not:** Bu option mevcut PostgreSQL ve Redis sunucularınızla çalışmak için kullanılır.
|
||||||
|
|
||||||
|
#### 1. Bağımlılıkları Yükleyin
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go mod download
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. .env Dosyasını Yapılandırın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# .env dosyasını düzenleyin
|
||||||
|
nano .env
|
||||||
|
```
|
||||||
|
|
||||||
|
Gerekli ayarlar:
|
||||||
|
```env
|
||||||
|
PORT=8080
|
||||||
|
|
||||||
|
# Mevcut PostgreSQL sunucunuz
|
||||||
|
DB_URL="host=10.80.80.70 user=cloud password=xxx dbname=go_gauth port=5432 sslmode=disable TimeZone=Europe/Istanbul"
|
||||||
|
|
||||||
|
# Mevcut Redis sunucunuz
|
||||||
|
REDIS_URL=redis://default:xxx@10.80.80.70:6379/0
|
||||||
|
|
||||||
|
# JWT Secret
|
||||||
|
JWT_SECRET=your_super_secret_key
|
||||||
|
|
||||||
|
# OAuth credentials (opsiyonel)
|
||||||
|
GOOGLE_CLIENT_ID=...
|
||||||
|
GOOGLE_CLIENT_SECRET=...
|
||||||
|
GITHUB_CLIENT_ID=...
|
||||||
|
GITHUB_CLIENT_SECRET=...
|
||||||
|
CLIENT_CALLBACK_URL=http://localhost:8080/v1/auth
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 3. Uygulamayı Çalıştırın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Quick start script ile
|
||||||
|
./start.sh
|
||||||
|
|
||||||
|
# veya manuel
|
||||||
|
go build -o main .
|
||||||
|
./main
|
||||||
|
|
||||||
|
# veya doğrudan
|
||||||
|
go run main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 4: Docker ile Sadece Veritabanları
|
||||||
|
|
||||||
|
### Option 4: Docker ile Sadece Veritabanları
|
||||||
|
|
||||||
|
Eğer uygulamayı local'de çalıştırıp sadece veritabanlarını Docker'da tutmak isterseniz:
|
||||||
|
|
||||||
|
#### 1. PostgreSQL'i Başlatın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name gauth_postgres \
|
||||||
|
-e POSTGRES_USER=postgres \
|
||||||
|
-e POSTGRES_PASSWORD=yourpassword \
|
||||||
|
-e POSTGRES_DB=gauth \
|
||||||
|
-p 5432:5432 \
|
||||||
|
postgres:17-alpine
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. Redis'i Başlatın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Docker ile
|
||||||
|
docker run -d \
|
||||||
|
--name gauth_redis \
|
||||||
|
-p 6379:6379 \
|
||||||
|
redis:7-alpine
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 4. .env Dosyasını Yapılandırın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
# .env dosyasını düzenleyin
|
||||||
|
```
|
||||||
|
|
||||||
|
Örnek .env:
|
||||||
|
```env
|
||||||
|
PORT=8080
|
||||||
|
DB_URL="host=localhost user=postgres password=yourpassword dbname=gauth port=5432 sslmode=disable TimeZone=Europe/Istanbul"
|
||||||
|
REDIS_URL=redis://localhost:6379/0
|
||||||
|
JWT_SECRET=your_super_secret_key
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5. Uygulamayı Çalıştırın
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Geliştirme modu
|
||||||
|
go run main.go
|
||||||
|
|
||||||
|
# Veya derleyip çalıştırın
|
||||||
|
go build -o main .
|
||||||
|
./main
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Yapılandırma Detayları
|
||||||
|
|
||||||
|
### PostgreSQL Bağlantısı
|
||||||
|
|
||||||
|
Uygulamanız PostgreSQL veritabanına bağlanacak ve otomatik olarak:
|
||||||
|
- Tabloları oluşturacak (migration)
|
||||||
|
- Seed data ekleyecek (roles, permissions)
|
||||||
|
- Email doğrulama sütununu güncelleyecek
|
||||||
|
|
||||||
|
### Redis Cache
|
||||||
|
|
||||||
|
Redis aşağıdaki amaçlarla kullanılır:
|
||||||
|
|
||||||
|
1. **Session Yönetimi**: Token-based session storage
|
||||||
|
2. **Rate Limiting**: API çağrılarını sınırlandırma
|
||||||
|
3. **Cache**: Kullanıcı verileri ve sık erişilen datalar
|
||||||
|
4. **Token Blacklist**: Logout işlemlerinde token iptal
|
||||||
|
5. **Email Verification**: Email doğrulama token'ları
|
||||||
|
6. **Password Reset**: Şifre sıfırlama token'ları
|
||||||
|
|
||||||
|
### CORS Yapılandırması
|
||||||
|
|
||||||
|
Varsayılan olarak `http://localhost:3000` origin'ine izin verilir. Değiştirmek için `main.go` dosyasını düzenleyin:
|
||||||
|
|
||||||
|
```go
|
||||||
|
AllowOrigins: []string{"http://localhost:3000", "https://yourdomain.com"},
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🧪 Test Etme
|
||||||
|
|
||||||
|
### 1. Sağlık Kontrolü
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl http://localhost:8080/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Swagger UI
|
||||||
|
|
||||||
|
Tarayıcınızda: `http://localhost:8080/docs/index.html`
|
||||||
|
|
||||||
|
### 3. Kullanıcı Kaydı
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "SecurePass123!",
|
||||||
|
"user_name": "testuser"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Giriş
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:8080/v1/auth/login \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "SecurePass123!"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Redis Bağlantı Kontrolü
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Redis CLI ile
|
||||||
|
docker exec -it gauth_redis redis-cli
|
||||||
|
|
||||||
|
# Redis içinde
|
||||||
|
> PING
|
||||||
|
PONG
|
||||||
|
|
||||||
|
> KEYS *
|
||||||
|
(Redis'teki tüm key'leri gösterir)
|
||||||
|
|
||||||
|
> GET user:UUID_HERE
|
||||||
|
(Kullanıcı cache verisi)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. PostgreSQL Bağlantı Kontrolü
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# PostgreSQL CLI ile
|
||||||
|
docker exec -it gauth_postgres psql -U postgres -d gauth
|
||||||
|
|
||||||
|
# PostgreSQL içinde
|
||||||
|
\dt -- Tabloları listele
|
||||||
|
\d users -- Users tablosu yapısını göster
|
||||||
|
SELECT * FROM roles; -- Rolleri listele
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📊 Rate Limiting Yapılandırması
|
||||||
|
|
||||||
|
Varsayılan limitler:
|
||||||
|
|
||||||
|
- **Login**: 5 deneme / dakika
|
||||||
|
- **Register**: 3 deneme / 5 dakika
|
||||||
|
- **Genel API**: 100 istek / dakika
|
||||||
|
|
||||||
|
Değiştirmek için `api/middlewares/rate_limit_middleware.go` dosyasını düzenleyin.
|
||||||
|
|
||||||
|
## 🔐 OAuth Yapılandırması
|
||||||
|
|
||||||
|
### Google OAuth
|
||||||
|
|
||||||
|
1. [Google Cloud Console](https://console.cloud.google.com/) → API & Services → Credentials
|
||||||
|
2. OAuth 2.0 Client ID oluşturun
|
||||||
|
3. Authorized redirect URIs: `http://localhost:8080/v1/auth/google/callback`
|
||||||
|
4. Client ID ve Secret'ı `.env` dosyasına ekleyin
|
||||||
|
|
||||||
|
### GitHub OAuth
|
||||||
|
|
||||||
|
1. [GitHub Developer Settings](https://github.com/settings/developers) → OAuth Apps → New
|
||||||
|
2. Authorization callback URL: `http://localhost:8080/v1/auth/github/callback`
|
||||||
|
3. Client ID ve Secret'ı `.env` dosyasına ekleyin
|
||||||
|
|
||||||
|
## 🐛 Sorun Giderme
|
||||||
|
|
||||||
|
### Redis bağlanamıyor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Redis durumunu kontrol et
|
||||||
|
docker ps | grep redis
|
||||||
|
|
||||||
|
# Redis loglarını kontrol et
|
||||||
|
docker logs gauth_redis
|
||||||
|
|
||||||
|
# Redis'i yeniden başlat
|
||||||
|
docker restart gauth_redis
|
||||||
|
```
|
||||||
|
|
||||||
|
### PostgreSQL bağlanamıyor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# PostgreSQL durumunu kontrol et
|
||||||
|
docker ps | grep postgres
|
||||||
|
|
||||||
|
# PostgreSQL loglarını kontrol et
|
||||||
|
docker logs gauth_postgres
|
||||||
|
|
||||||
|
# Bağlantıyı test et
|
||||||
|
docker exec -it gauth_postgres pg_isready -U postgres
|
||||||
|
```
|
||||||
|
|
||||||
|
### CORS hatası alıyorum
|
||||||
|
|
||||||
|
`main.go` dosyasında `AllowOrigins` değerini kontrol edin ve frontend URL'inizi ekleyin.
|
||||||
|
|
||||||
|
### Rate limit çok düşük
|
||||||
|
|
||||||
|
`api/middlewares/rate_limit_middleware.go` dosyasında limit değerlerini artırın.
|
||||||
|
|
||||||
|
## 📝 Notlar
|
||||||
|
|
||||||
|
- Üretim ortamında `JWT_SECRET` değerini güçlü bir değerle değiştirin
|
||||||
|
- Redis şifre koruması için production'da Redis AUTH kullanın
|
||||||
|
- PostgreSQL için SSL bağlantısı kullanın (sslmode=require)
|
||||||
|
- Log seviyelerini production'da ayarlayın
|
||||||
|
- CORS origin'lerini production domain'lerinizle güncelleyin
|
||||||
|
|
||||||
|
## 🔄 Güncellemeler
|
||||||
|
|
||||||
|
Swagger dokümantasyonunu güncellemek için:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
swag init -g main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
Migration eklemek için:
|
||||||
|
|
||||||
|
`internal/database/db.go` dosyasındaki `Migrate()` fonksiyonunu güncelleyin.
|
||||||
|
|
||||||
|
## 📚 Daha Fazla Bilgi
|
||||||
|
|
||||||
|
- [Gin Web Framework](https://gin-gonic.com/)
|
||||||
|
- [GORM ORM](https://gorm.io/)
|
||||||
|
- [Redis Go Client](https://redis.uptrace.dev/)
|
||||||
|
- [JWT Go](https://github.com/golang-jwt/jwt)
|
||||||
9
docs/api_backend.txt
Normal file
9
docs/api_backend.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/ --> gauth-central/api/routes.SetupRoutes.func1 (3 handlers)
|
||||||
|
[GIN-debug] GET /docs/*any --> github.com/swaggo/gin-swagger.CustomWrapHandler.func1 (3 handlers)
|
||||||
|
[GIN-debug] POST /v1/auth/register --> gauth-central/api/handlers.(*AuthHandler).Register-fm (3 handlers)
|
||||||
|
[GIN-debug] POST /v1/auth/login --> gauth-central/api/handlers.(*AuthHandler).Login-fm (3 handlers)
|
||||||
|
[GIN-debug] GET /v1/auth/:provider --> gauth-central/api/handlers.(*AuthHandler).BeginAuth-fm (3 handlers)
|
||||||
|
[GIN-debug] GET /v1/auth/:provider/callback --> gauth-central/api/handlers.(*AuthHandler).Callback-fm (3 handlers)
|
||||||
|
[GIN-debug] POST /v1/auth/refresh --> gauth-central/api/handlers.(*AuthHandler).Refresh-fm (3 handlers)
|
||||||
|
[GIN-debug] GET /v1/auth/me --> gauth-central/api/handlers.(*AuthHandler).Me-fm (4 handlers)
|
||||||
|
[GIN-debug] GET /v1/auth/validate
|
||||||
18
eslint.config.mjs
Normal file
18
eslint.config.mjs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { defineConfig, globalIgnores } from "eslint/config";
|
||||||
|
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||||
|
import nextTs from "eslint-config-next/typescript";
|
||||||
|
|
||||||
|
const eslintConfig = defineConfig([
|
||||||
|
...nextVitals,
|
||||||
|
...nextTs,
|
||||||
|
// Override default ignores of eslint-config-next.
|
||||||
|
globalIgnores([
|
||||||
|
// Default ignores of eslint-config-next:
|
||||||
|
".next/**",
|
||||||
|
"out/**",
|
||||||
|
"build/**",
|
||||||
|
"next-env.d.ts",
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export default eslintConfig;
|
||||||
19
hooks/use-mobile.ts
Normal file
19
hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
const MOBILE_BREAKPOINT = 768
|
||||||
|
|
||||||
|
export function useIsMobile() {
|
||||||
|
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||||
|
const onChange = () => {
|
||||||
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||||
|
}
|
||||||
|
mql.addEventListener("change", onChange)
|
||||||
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||||
|
return () => mql.removeEventListener("change", onChange)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return !!isMobile
|
||||||
|
}
|
||||||
109
lib/api/fetchClient.ts
Normal file
109
lib/api/fetchClient.ts
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
|
// .env'deki NEXT_PUBLIC_API_BASE kullanılır (örn: http://127.0.0.1:8080). /v1 prefix'i burada eklenir.
|
||||||
|
const getBaseUrl = () => {
|
||||||
|
const base = process.env.NEXT_PUBLIC_API_BASE || "http://localhost:8080";
|
||||||
|
const normalized = base.replace(/\/$/, "");
|
||||||
|
return `${normalized}/v1`;
|
||||||
|
};
|
||||||
|
const BASE_URL = getBaseUrl();
|
||||||
|
|
||||||
|
interface FetchOptions extends RequestInit {
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AuthResponse {
|
||||||
|
access_token: string;
|
||||||
|
refresh_token: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fetchClient = async (endpoint: string, options: FetchOptions = {}) => {
|
||||||
|
const getAccessToken = () => Cookies.get("access_token");
|
||||||
|
const getRefreshToken = () => Cookies.get("refresh_token");
|
||||||
|
|
||||||
|
const setTokens = (access: string, refresh: string) => {
|
||||||
|
Cookies.set("access_token", access, { secure: true, sameSite: 'strict' });
|
||||||
|
Cookies.set("refresh_token", refresh, { secure: true, sameSite: 'strict' });
|
||||||
|
// Dispatch event for other tabs or parts of the app to know (optional)
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
window.dispatchEvent(new Event("storage"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearTokens = () => {
|
||||||
|
Cookies.remove("access_token");
|
||||||
|
Cookies.remove("refresh_token");
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
} catch (e) { }
|
||||||
|
window.location.href = "/login";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
...options.headers,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!(options.body instanceof FormData)) {
|
||||||
|
headers["Content-Type"] = "application/json";
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = getAccessToken();
|
||||||
|
if (token) {
|
||||||
|
headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const config: RequestInit = {
|
||||||
|
...options,
|
||||||
|
headers,
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = await fetch(`${BASE_URL}${endpoint}`, config);
|
||||||
|
|
||||||
|
// Handle 401 - Token Expired
|
||||||
|
if (response.status === 401) {
|
||||||
|
const refreshToken = getRefreshToken();
|
||||||
|
if (!refreshToken) {
|
||||||
|
clearTokens();
|
||||||
|
throw new Error("Session expired");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Attempt to refresh token
|
||||||
|
const refreshResponse = await fetch(`${BASE_URL}/auth/refresh`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ refresh_token: refreshToken }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!refreshResponse.ok) {
|
||||||
|
throw new Error("Refresh failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: AuthResponse = await refreshResponse.json();
|
||||||
|
setTokens(data.access_token, data.refresh_token);
|
||||||
|
|
||||||
|
// Retry original request with new token
|
||||||
|
headers["Authorization"] = `Bearer ${data.access_token}`;
|
||||||
|
response = await fetch(`${BASE_URL}${endpoint}`, { ...options, headers });
|
||||||
|
} catch (error) {
|
||||||
|
clearTokens();
|
||||||
|
throw new Error("Session expired. Please login again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle other errors
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
const errorMessage = errorData.error || errorData.message || response.statusText;
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return json if content type is json, otherwise text or null
|
||||||
|
const contentType = response.headers.get("content-type");
|
||||||
|
if (contentType && contentType.includes("application/json")) {
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
|
};
|
||||||
300
lib/features/auth/authSlice.ts
Normal file
300
lib/features/auth/authSlice.ts
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
import { fetchClient } from "@/lib/api/fetchClient";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
|
// Types
|
||||||
|
export interface Permission {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Role {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
permissions?: Permission[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SocialAccount {
|
||||||
|
id: number;
|
||||||
|
provider: string;
|
||||||
|
email: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
roles: Role[];
|
||||||
|
avatar_url?: string;
|
||||||
|
email_verified?: boolean;
|
||||||
|
is_oauth_user?: boolean;
|
||||||
|
social_accounts?: SocialAccount[];
|
||||||
|
created_at?: string;
|
||||||
|
updated_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AuthState {
|
||||||
|
user: User | null;
|
||||||
|
isAuthenticated: boolean;
|
||||||
|
isLoading: boolean;
|
||||||
|
error: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LoginResponse {
|
||||||
|
user_id: string;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
access_token: string;
|
||||||
|
refresh_token: string;
|
||||||
|
roles: Role[];
|
||||||
|
avatar?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RegisterResponse {
|
||||||
|
user_id: string;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
avatar: string;
|
||||||
|
email_verified: boolean;
|
||||||
|
message: string;
|
||||||
|
roles: Role[];
|
||||||
|
verification_token: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial State
|
||||||
|
const initialState: AuthState = {
|
||||||
|
user: null,
|
||||||
|
isAuthenticated: false,
|
||||||
|
isLoading: false,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Async Thunks
|
||||||
|
export const login = createAsyncThunk(
|
||||||
|
"auth/login",
|
||||||
|
async (credentials: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response: LoginResponse = await fetchClient("/auth/login", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(credentials),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validate Check: Ensure tokens exist
|
||||||
|
if (!response.access_token || !response.refresh_token) {
|
||||||
|
return rejectWithValue("Giriş başarısız: Token alınamadı. Lütfen emailinizi doğruladığınızdan emin olun.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store tokens in cookies
|
||||||
|
Cookies.set("access_token", response.access_token, { secure: true, sameSite: 'strict' });
|
||||||
|
Cookies.set("refresh_token", response.refresh_token, { secure: true, sameSite: 'strict' });
|
||||||
|
|
||||||
|
// Store user info in localStorage for convenience (optional, can be removed if strict cookie only)
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
localStorage.setItem("user", JSON.stringify({
|
||||||
|
id: response.user_id,
|
||||||
|
username: response.username,
|
||||||
|
email: response.email,
|
||||||
|
roles: response.roles,
|
||||||
|
avatar_url: response.avatar
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const register = createAsyncThunk(
|
||||||
|
"auth/register",
|
||||||
|
async (credentials: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response: RegisterResponse = await fetchClient("/auth/register", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(credentials),
|
||||||
|
});
|
||||||
|
|
||||||
|
// NOTE: Register does NOT return tokens anymore.
|
||||||
|
// We do NOT set cookies here.
|
||||||
|
// We do NOT set localStorage user here.
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const fetchProfile = createAsyncThunk(
|
||||||
|
"auth/fetchProfile",
|
||||||
|
async (_, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await fetchClient("/profile");
|
||||||
|
const data = response as any;
|
||||||
|
// Map API response to User type, specifically avatar -> avatar_url
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
avatar_url: data.avatar,
|
||||||
|
roles: data.roles || []
|
||||||
|
} as User;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const updateProfile = createAsyncThunk(
|
||||||
|
"auth/updateProfile",
|
||||||
|
async (formData: FormData, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await fetchClient("/profile", {
|
||||||
|
method: "PUT",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = (response as any).user;
|
||||||
|
|
||||||
|
// Map API response to User type, specifically avatar -> avatar_url
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
avatar_url: data.avatar,
|
||||||
|
roles: data.roles || []
|
||||||
|
} as User;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const changePassword = createAsyncThunk(
|
||||||
|
"auth/changePassword",
|
||||||
|
async (data: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await fetchClient("/profile/password", {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const changeEmail = createAsyncThunk(
|
||||||
|
"auth/changeEmail",
|
||||||
|
async (data: any, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await fetchClient("/profile/email", {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Slice
|
||||||
|
const authSlice = createSlice({
|
||||||
|
name: "auth",
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
logout: (state) => {
|
||||||
|
state.user = null;
|
||||||
|
state.isAuthenticated = false;
|
||||||
|
state.error = null;
|
||||||
|
Cookies.remove("access_token");
|
||||||
|
Cookies.remove("refresh_token");
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
restoreSession: (state) => {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
const userStr = localStorage.getItem("user");
|
||||||
|
const token = Cookies.get("access_token");
|
||||||
|
if (userStr && token) {
|
||||||
|
try {
|
||||||
|
const parsedUser = JSON.parse(userStr);
|
||||||
|
// Migration for legacy data: map avatar to avatar_url if needed
|
||||||
|
if (parsedUser.avatar && !parsedUser.avatar_url) {
|
||||||
|
parsedUser.avatar_url = parsedUser.avatar;
|
||||||
|
}
|
||||||
|
state.user = parsedUser;
|
||||||
|
state.isAuthenticated = true;
|
||||||
|
} catch (e) {
|
||||||
|
// Corrupt user data
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
Cookies.remove("access_token");
|
||||||
|
Cookies.remove("refresh_token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
extraReducers: (builder) => {
|
||||||
|
// Login
|
||||||
|
builder.addCase(login.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
state.error = null;
|
||||||
|
});
|
||||||
|
builder.addCase(login.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.isAuthenticated = true;
|
||||||
|
state.user = {
|
||||||
|
id: action.payload.user_id,
|
||||||
|
username: action.payload.username,
|
||||||
|
email: action.payload.email,
|
||||||
|
roles: action.payload.roles,
|
||||||
|
avatar_url: action.payload.avatar
|
||||||
|
};
|
||||||
|
});
|
||||||
|
builder.addCase(login.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.error = action.payload as string;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register
|
||||||
|
builder.addCase(register.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
state.error = null;
|
||||||
|
});
|
||||||
|
builder.addCase(register.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
// isAuthenticated remains false because we need email verification
|
||||||
|
state.isAuthenticated = false;
|
||||||
|
// We do not set the user state effectively until they login
|
||||||
|
state.user = null;
|
||||||
|
});
|
||||||
|
builder.addCase(register.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.error = action.payload as string;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch Profile
|
||||||
|
builder.addCase(fetchProfile.fulfilled, (state, action) => {
|
||||||
|
state.user = action.payload;
|
||||||
|
// Sync with localStorage so next refresh has fresh data
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
localStorage.setItem("user", JSON.stringify(action.payload));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update Profile
|
||||||
|
builder.addCase(updateProfile.fulfilled, (state, action) => {
|
||||||
|
state.user = action.payload;
|
||||||
|
// Sync with localStorage so next refresh has fresh data
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
localStorage.setItem("user", JSON.stringify(action.payload));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { logout, restoreSession } = authSlice.actions;
|
||||||
|
export default authSlice.reducer;
|
||||||
215
lib/features/cors/corsSlice.ts
Normal file
215
lib/features/cors/corsSlice.ts
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||||
|
import { fetchClient } from "@/lib/api/fetchClient";
|
||||||
|
|
||||||
|
// Types
|
||||||
|
export interface CorsEntry {
|
||||||
|
id: string;
|
||||||
|
origin: string;
|
||||||
|
description?: string; // For whitelist
|
||||||
|
reason?: string; // For blacklist
|
||||||
|
is_active: boolean;
|
||||||
|
created_by: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CorsState {
|
||||||
|
whitelist: CorsEntry[];
|
||||||
|
blacklist: CorsEntry[];
|
||||||
|
isLoading: boolean;
|
||||||
|
error: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: CorsState = {
|
||||||
|
whitelist: [],
|
||||||
|
blacklist: [],
|
||||||
|
isLoading: false,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Async Thunks
|
||||||
|
|
||||||
|
// --- WHITELIST ---
|
||||||
|
|
||||||
|
export const fetchWhitelists = createAsyncThunk(
|
||||||
|
"cors/fetchWhitelists",
|
||||||
|
async (_, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
return await fetchClient("/settings/cors/whitelist");
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const createWhitelist = createAsyncThunk(
|
||||||
|
"cors/createWhitelist",
|
||||||
|
async (data: { origin: string; description: string }, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
return await fetchClient("/settings/cors/whitelist", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const updateWhitelist = createAsyncThunk(
|
||||||
|
"cors/updateWhitelist",
|
||||||
|
async ({ id, data }: { id: string; data: Partial<CorsEntry> }, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await fetchClient(`/settings/cors/whitelist/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return { id, data };
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deleteWhitelist = createAsyncThunk(
|
||||||
|
"cors/deleteWhitelist",
|
||||||
|
async (id: string, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await fetchClient(`/settings/cors/whitelist/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
return id;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// --- BLACKLIST ---
|
||||||
|
|
||||||
|
export const fetchBlacklists = createAsyncThunk(
|
||||||
|
"cors/fetchBlacklists",
|
||||||
|
async (_, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
return await fetchClient("/settings/cors/blacklist");
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const createBlacklist = createAsyncThunk(
|
||||||
|
"cors/createBlacklist",
|
||||||
|
async (data: { origin: string; reason: string }, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
return await fetchClient("/settings/cors/blacklist", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const updateBlacklist = createAsyncThunk(
|
||||||
|
"cors/updateBlacklist",
|
||||||
|
async ({ id, data }: { id: string; data: Partial<CorsEntry> }, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await fetchClient(`/settings/cors/blacklist/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return { id, data };
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deleteBlacklist = createAsyncThunk(
|
||||||
|
"cors/deleteBlacklist",
|
||||||
|
async (id: string, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await fetchClient(`/settings/cors/blacklist/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
return id;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const corsSlice = createSlice({
|
||||||
|
name: "cors",
|
||||||
|
initialState,
|
||||||
|
reducers: {},
|
||||||
|
extraReducers: (builder) => {
|
||||||
|
// Fetch Whitelists
|
||||||
|
builder.addCase(fetchWhitelists.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
state.error = null;
|
||||||
|
});
|
||||||
|
builder.addCase(fetchWhitelists.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.whitelist = action.payload as CorsEntry[];
|
||||||
|
});
|
||||||
|
builder.addCase(fetchWhitelists.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.error = action.payload as string;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create Whitelist
|
||||||
|
builder.addCase(createWhitelist.fulfilled, (state, action) => {
|
||||||
|
state.whitelist.push(action.payload as CorsEntry);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update Whitelist
|
||||||
|
builder.addCase(updateWhitelist.fulfilled, (state, action) => {
|
||||||
|
const index = state.whitelist.findIndex((item) => item.id === action.payload.id);
|
||||||
|
if (index !== -1) {
|
||||||
|
state.whitelist[index] = { ...state.whitelist[index], ...action.payload.data };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete Whitelist
|
||||||
|
builder.addCase(deleteWhitelist.fulfilled, (state, action) => {
|
||||||
|
state.whitelist = state.whitelist.filter((item) => item.id !== action.payload);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch Blacklists
|
||||||
|
builder.addCase(fetchBlacklists.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
state.error = null;
|
||||||
|
});
|
||||||
|
builder.addCase(fetchBlacklists.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.blacklist = action.payload as CorsEntry[];
|
||||||
|
});
|
||||||
|
builder.addCase(fetchBlacklists.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.error = action.payload as string;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create Blacklist
|
||||||
|
builder.addCase(createBlacklist.fulfilled, (state, action) => {
|
||||||
|
state.blacklist.push(action.payload as CorsEntry);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update Blacklist
|
||||||
|
builder.addCase(updateBlacklist.fulfilled, (state, action) => {
|
||||||
|
const index = state.blacklist.findIndex((item) => item.id === action.payload.id);
|
||||||
|
if (index !== -1) {
|
||||||
|
state.blacklist[index] = { ...state.blacklist[index], ...action.payload.data };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete Blacklist
|
||||||
|
builder.addCase(deleteBlacklist.fulfilled, (state, action) => {
|
||||||
|
state.blacklist = state.blacklist.filter((item) => item.id !== action.payload);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default corsSlice.reducer;
|
||||||
256
lib/features/users/usersSlice.ts
Normal file
256
lib/features/users/usersSlice.ts
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
// Users Slice for managing users and deleted users
|
||||||
|
import { fetchClient } from "@/lib/api/fetchClient";
|
||||||
|
import { User } from "@/lib/features/auth/authSlice";
|
||||||
|
|
||||||
|
/** API'den gelen kullanıcıyı frontend User tipine çevirir (avatar -> avatar_url, permissions null ise []). */
|
||||||
|
function mapApiUserToUser(apiUser: Record<string, unknown>): User & { deleted_at?: string } {
|
||||||
|
const roles = (apiUser.roles as User["roles"]) || [];
|
||||||
|
return {
|
||||||
|
id: String(apiUser.id),
|
||||||
|
username: String(apiUser.username ?? ""),
|
||||||
|
email: String(apiUser.email ?? ""),
|
||||||
|
roles: roles.map((r) => ({ ...r, permissions: r.permissions ?? [] })),
|
||||||
|
avatar_url: apiUser.avatar ? String(apiUser.avatar) : (apiUser.avatar_url as string | undefined),
|
||||||
|
deleted_at: apiUser.deleted_at ? String(apiUser.deleted_at) : undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Types
|
||||||
|
export interface CreateUserRequest {
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
password?: string;
|
||||||
|
roles?: string[];
|
||||||
|
avatar?: File;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateUserRequest {
|
||||||
|
id: string;
|
||||||
|
username?: string;
|
||||||
|
email?: string;
|
||||||
|
password?: string;
|
||||||
|
roles?: string[];
|
||||||
|
avatar?: File;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UsersState {
|
||||||
|
users: User[]; // Active users
|
||||||
|
deletedUsers: (User & { deleted_at?: string })[]; // Soft-deleted users
|
||||||
|
isLoading: boolean;
|
||||||
|
error: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: UsersState = {
|
||||||
|
users: [],
|
||||||
|
deletedUsers: [],
|
||||||
|
isLoading: false,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Async Thunks
|
||||||
|
export const fetchUsers = createAsyncThunk(
|
||||||
|
"users/fetchAll",
|
||||||
|
async (_, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await fetchClient("/admin/users") as { users?: unknown[]; data?: unknown[]; pagination?: unknown };
|
||||||
|
const rawList = response.users ?? response.data ?? (Array.isArray(response) ? response : null);
|
||||||
|
const list = Array.isArray(rawList) ? rawList : [];
|
||||||
|
return list.map((u) => mapApiUserToUser(u as Record<string, unknown>));
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const fetchDeletedUsers = createAsyncThunk(
|
||||||
|
"users/fetchDeleted",
|
||||||
|
async (_, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const response = await fetchClient("/admin/users/deleted") as { users?: unknown[]; data?: unknown[]; pagination?: unknown };
|
||||||
|
const rawList = response.users ?? response.data ?? (Array.isArray(response) ? response : null);
|
||||||
|
const list = Array.isArray(rawList) ? rawList : [];
|
||||||
|
return list.map((u) => mapApiUserToUser(u as Record<string, unknown>));
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const createUser = createAsyncThunk(
|
||||||
|
"users/create",
|
||||||
|
async (userData: CreateUserRequest, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("user_name", userData.username);
|
||||||
|
formData.append("email", userData.email);
|
||||||
|
if (userData.password) formData.append("password", userData.password);
|
||||||
|
|
||||||
|
if (userData.roles && userData.roles.length > 0) {
|
||||||
|
userData.roles.forEach((r) => formData.append("roles", r));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userData.avatar) {
|
||||||
|
formData.append("avatar", userData.avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetchClient("/admin/users", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
const raw = (response as { user?: Record<string, unknown> }).user ?? response;
|
||||||
|
return mapApiUserToUser(raw as Record<string, unknown>);
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const updateUser = createAsyncThunk(
|
||||||
|
"users/update",
|
||||||
|
async (userData: UpdateUserRequest, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const { id, username, email, password, roles, avatar } = userData;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
if (username !== undefined) formData.append("user_name", username);
|
||||||
|
if (email !== undefined) formData.append("email", email);
|
||||||
|
if (password) formData.append("password", password);
|
||||||
|
if (roles && roles.length > 0) {
|
||||||
|
roles.forEach((r) => formData.append("roles", r));
|
||||||
|
}
|
||||||
|
if (avatar) {
|
||||||
|
formData.append("avatar", avatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetchClient(`/admin/users/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
const raw = (response as { user?: Record<string, unknown> }).user ?? response;
|
||||||
|
return mapApiUserToUser(raw as Record<string, unknown>);
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deleteUser = createAsyncThunk(
|
||||||
|
"users/delete",
|
||||||
|
async (payload: string | { id: string; hard: boolean }, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
const id = typeof payload === "string" ? payload : payload.id;
|
||||||
|
const isHard = typeof payload === "object" && payload.hard;
|
||||||
|
|
||||||
|
const endpoint = `/admin/users/${id}${isHard ? "?hard=true" : ""}`;
|
||||||
|
|
||||||
|
await fetchClient(endpoint, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
return { id, isHard };
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export const restoreUser = createAsyncThunk(
|
||||||
|
"users/restore",
|
||||||
|
async (id: string, { rejectWithValue }) => {
|
||||||
|
try {
|
||||||
|
await fetchClient(`/admin/users/${id}/restore`, {
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
return id;
|
||||||
|
} catch (error: any) {
|
||||||
|
return rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const usersSlice = createSlice({
|
||||||
|
name: "users",
|
||||||
|
initialState,
|
||||||
|
reducers: {},
|
||||||
|
extraReducers: (builder) => {
|
||||||
|
// Fetch Active
|
||||||
|
builder.addCase(fetchUsers.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
state.error = null;
|
||||||
|
});
|
||||||
|
builder.addCase(fetchUsers.fulfilled, (state, action: PayloadAction<User[]>) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.users = action.payload;
|
||||||
|
});
|
||||||
|
builder.addCase(fetchUsers.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.error = action.payload as string;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fetch Deleted
|
||||||
|
builder.addCase(fetchDeletedUsers.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
state.error = null;
|
||||||
|
});
|
||||||
|
builder.addCase(fetchDeletedUsers.fulfilled, (state, action: PayloadAction<User[]>) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.deletedUsers = action.payload;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create
|
||||||
|
builder.addCase(createUser.fulfilled, (state, action: PayloadAction<User>) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
if (action.payload && action.payload.id) {
|
||||||
|
state.users.push(action.payload);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update
|
||||||
|
builder.addCase(updateUser.fulfilled, (state, action: PayloadAction<User>) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
if (action.payload && action.payload.id) {
|
||||||
|
const index = state.users.findIndex(u => u.id === action.payload.id);
|
||||||
|
if (index !== -1) {
|
||||||
|
state.users[index] = action.payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
builder.addCase(deleteUser.fulfilled, (state, action: PayloadAction<{ id: string, isHard: boolean }>) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
const { id, isHard } = action.payload;
|
||||||
|
|
||||||
|
// Remove from active users list (always happens)
|
||||||
|
const deletedUser = state.users.find(u => u.id === id);
|
||||||
|
state.users = state.users.filter(u => u.id !== id);
|
||||||
|
|
||||||
|
// If Soft Delete, add to deletedUsers list (mechanically we should re-fetch, but optimistically we can add if we had the full object)
|
||||||
|
if (!isHard && deletedUser) {
|
||||||
|
state.deletedUsers.unshift({ ...deletedUser, deleted_at: new Date().toISOString() });
|
||||||
|
}
|
||||||
|
|
||||||
|
// If Hard Delete, remove from deletedUsers list too (checking if it was there)
|
||||||
|
if (isHard) {
|
||||||
|
state.deletedUsers = state.deletedUsers.filter(u => u.id !== id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Restore
|
||||||
|
builder.addCase(restoreUser.fulfilled, (state, action: PayloadAction<string>) => {
|
||||||
|
const id = action.payload;
|
||||||
|
const restoredUser = state.deletedUsers.find(u => u.id === id);
|
||||||
|
|
||||||
|
// Remove from deleted list
|
||||||
|
state.deletedUsers = state.deletedUsers.filter(u => u.id !== id);
|
||||||
|
|
||||||
|
// Add to active list
|
||||||
|
if (restoredUser) {
|
||||||
|
const { deleted_at, ...user } = restoredUser;
|
||||||
|
state.users.push(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default usersSlice.reducer;
|
||||||
8
lib/hooks.ts
Normal file
8
lib/hooks.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { useDispatch, useSelector, useStore } from "react-redux";
|
||||||
|
import type { TypedUseSelectorHook } from "react-redux";
|
||||||
|
import type { AppDispatch, AppStore, RootState } from "./store";
|
||||||
|
|
||||||
|
// Use throughout your app instead of plain `useDispatch` and `useSelector`
|
||||||
|
export const useAppDispatch: () => AppDispatch = useDispatch;
|
||||||
|
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
||||||
|
export const useAppStore: () => AppStore = useStore;
|
||||||
8
lib/schemas/login.ts
Normal file
8
lib/schemas/login.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const loginSchema = z.object({
|
||||||
|
email: z.string().email("Geçerli bir email adresi giriniz"),
|
||||||
|
password: z.string().min(1, "Şifre alanı zorunludur"),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type LoginSchema = z.infer<typeof loginSchema>;
|
||||||
13
lib/schemas/register.ts
Normal file
13
lib/schemas/register.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const registerSchema = z.object({
|
||||||
|
username: z.string().min(3, "Kullanıcı adı en az 3 karakter olmalıdır"),
|
||||||
|
email: z.string().email("Geçerli bir email adresi giriniz"),
|
||||||
|
password: z.string().min(6, "Şifre en az 6 karakter olmalıdır"),
|
||||||
|
confirmPassword: z.string()
|
||||||
|
}).refine((data) => data.password === data.confirmPassword, {
|
||||||
|
message: "Şifreler eşleşmiyor",
|
||||||
|
path: ["confirmPassword"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export type RegisterSchema = z.infer<typeof registerSchema>;
|
||||||
20
lib/store.ts
Normal file
20
lib/store.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { configureStore } from "@reduxjs/toolkit";
|
||||||
|
import authReducer from "./features/auth/authSlice";
|
||||||
|
import usersReducer from "./features/users/usersSlice";
|
||||||
|
import corsReducer from "./features/cors/corsSlice";
|
||||||
|
|
||||||
|
export const makeStore = () => {
|
||||||
|
return configureStore({
|
||||||
|
reducer: {
|
||||||
|
auth: authReducer,
|
||||||
|
users: usersReducer,
|
||||||
|
cors: corsReducer,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Infer the type of makeStore
|
||||||
|
export type AppStore = ReturnType<typeof makeStore>;
|
||||||
|
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||||
|
export type RootState = ReturnType<AppStore["getState"]>;
|
||||||
|
export type AppDispatch = AppStore["dispatch"];
|
||||||
15
lib/utils.ts
Normal file
15
lib/utils.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { clsx, type ClassValue } from "clsx"
|
||||||
|
import { twMerge } from "tailwind-merge"
|
||||||
|
|
||||||
|
export function cn(...inputs: ClassValue[]) {
|
||||||
|
return twMerge(clsx(inputs))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Backend'den gelen avatar_url tam veya relative olabilir; görüntülenebilir URL döner. */
|
||||||
|
export function getAvatarUrl(avatarUrl: string | undefined): string | undefined {
|
||||||
|
if (!avatarUrl) return undefined
|
||||||
|
if (avatarUrl.startsWith("http://") || avatarUrl.startsWith("https://")) return avatarUrl
|
||||||
|
const base = process.env.NEXT_PUBLIC_API_BASE || ""
|
||||||
|
const normalized = base.replace(/\/$/, "")
|
||||||
|
return `${normalized}${avatarUrl.startsWith("/") ? "" : "/"}${avatarUrl}`
|
||||||
|
}
|
||||||
19
next.config.ts
Normal file
19
next.config.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
|
output: "standalone",
|
||||||
|
images: {
|
||||||
|
remotePatterns: [
|
||||||
|
{
|
||||||
|
protocol: "http",
|
||||||
|
hostname: "localhost",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
protocol: "http",
|
||||||
|
hostname: "127.0.0.1",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
42
package.json
Normal file
42
package.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "next-go-blog",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start",
|
||||||
|
"lint": "eslint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@reduxjs/toolkit": "^2.11.2",
|
||||||
|
"class-variance-authority": "^0.7.1",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"ioredis": "^5.9.2",
|
||||||
|
"js-cookie": "^3.0.5",
|
||||||
|
"lucide-react": "^0.563.0",
|
||||||
|
"next": "16.1.6",
|
||||||
|
"next-auth": "^4.24.13",
|
||||||
|
"next-themes": "^0.4.6",
|
||||||
|
"nextjs-turnstile": "^1.0.3",
|
||||||
|
"radix-ui": "^1.4.3",
|
||||||
|
"react": "19.2.3",
|
||||||
|
"react-dom": "19.2.3",
|
||||||
|
"react-redux": "^9.2.0",
|
||||||
|
"sweetalert2": "^11.26.18",
|
||||||
|
"tailwind-merge": "^3.4.0",
|
||||||
|
"zod": "^4.3.6"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4",
|
||||||
|
"@types/js-cookie": "^3.0.6",
|
||||||
|
"@types/node": "^20",
|
||||||
|
"@types/react": "^19",
|
||||||
|
"@types/react-dom": "^19",
|
||||||
|
"eslint": "^9",
|
||||||
|
"eslint-config-next": "16.1.6",
|
||||||
|
"tailwindcss": "^4",
|
||||||
|
"tw-animate-css": "^1.4.0",
|
||||||
|
"typescript": "^5"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
postcss.config.mjs
Normal file
7
postcss.config.mjs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const config = {
|
||||||
|
plugins: {
|
||||||
|
"@tailwindcss/postcss": {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
1
public/file.svg
Normal file
1
public/file.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 391 B |
1
public/globe.svg
Normal file
1
public/globe.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||||
|
After Width: | Height: | Size: 1.0 KiB |
1
public/next.svg
Normal file
1
public/next.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.3 KiB |
1
public/vercel.svg
Normal file
1
public/vercel.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||||
|
After Width: | Height: | Size: 128 B |
1
public/window.svg
Normal file
1
public/window.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||||
|
After Width: | Height: | Size: 385 B |
34
tsconfig.json
Normal file
34
tsconfig.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2017",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"incremental": true,
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "next"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"next-env.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
".next/types/**/*.ts",
|
||||||
|
".next/dev/types/**/*.ts",
|
||||||
|
"**/*.mts"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user