first commit
This commit is contained in:
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user