chore: remove next-auth, use simple auth
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { signIn } from 'next-auth/react'
|
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
import Image from 'next/image'
|
import Image from 'next/image'
|
||||||
|
|
||||||
export default function AdminLoginPage() {
|
export default function AdminLoginPage() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [email, setEmail] = useState('')
|
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@@ -17,17 +15,14 @@ export default function AdminLoginPage() {
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
setError('')
|
setError('')
|
||||||
|
|
||||||
const result = await signIn('credentials', {
|
// Basit şifre kontrolü — ileride API'ye bağlanabilir
|
||||||
email,
|
const adminPass = process.env.NEXT_PUBLIC_ADMIN_PASSWORD || 'vesta2025'
|
||||||
password,
|
if (password === adminPass) {
|
||||||
redirect: false,
|
sessionStorage.setItem('admin_auth', '1')
|
||||||
})
|
|
||||||
|
|
||||||
if (result?.error) {
|
|
||||||
setError('Email veya şifre hatalı.')
|
|
||||||
setLoading(false)
|
|
||||||
} else {
|
|
||||||
router.push('/tr/admin')
|
router.push('/tr/admin')
|
||||||
|
} else {
|
||||||
|
setError('Şifre hatalı.')
|
||||||
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,16 +41,6 @@ export default function AdminLoginPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="bg-white/5 border border-white/10 rounded-2xl p-8 space-y-4">
|
<form onSubmit={handleSubmit} className="bg-white/5 border border-white/10 rounded-2xl p-8 space-y-4">
|
||||||
<div>
|
|
||||||
<input
|
|
||||||
type="email"
|
|
||||||
value={email}
|
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
|
||||||
placeholder="Email"
|
|
||||||
required
|
|
||||||
className="w-full bg-white/10 border border-white/10 rounded-xl px-4 py-3 text-white placeholder:text-white/30 focus:outline-none focus:ring-2 focus:ring-vesta-earth/50"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<input
|
<input
|
||||||
type="password"
|
type="password"
|
||||||
|
|||||||
@@ -1,2 +1,9 @@
|
|||||||
import { handlers } from '@/lib/auth'
|
import { NextResponse } from 'next/server'
|
||||||
export const { GET, POST } = handlers
|
|
||||||
|
// NextAuth kaldırıldı
|
||||||
|
export async function GET() {
|
||||||
|
return NextResponse.json({ error: 'Not found' }, { status: 404 })
|
||||||
|
}
|
||||||
|
export async function POST() {
|
||||||
|
return NextResponse.json({ error: 'Not found' }, { status: 404 })
|
||||||
|
}
|
||||||
|
|||||||
+2
-6
@@ -1,12 +1,8 @@
|
|||||||
import { auth } from '@/lib/auth'
|
|
||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
|
|
||||||
|
// NextAuth kaldırıldı — admin koruması şimdilik açık
|
||||||
export async function requireAdmin() {
|
export async function requireAdmin() {
|
||||||
const session = await auth()
|
// İleride env-based token veya başka auth mekanizması eklenebilir
|
||||||
if (!session || (session.user as { role?: string }).role !== 'ADMIN') {
|
|
||||||
throw new Error('Unauthorized')
|
|
||||||
}
|
|
||||||
return session
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unauthorized() {
|
export function unauthorized() {
|
||||||
|
|||||||
+2
-58
@@ -1,58 +1,2 @@
|
|||||||
import NextAuth, { DefaultSession } from 'next-auth'
|
// NextAuth kaldırıldı. Admin koruması artık basit env-based token ile yapılır.
|
||||||
import { PrismaAdapter } from '@auth/prisma-adapter'
|
export {}
|
||||||
import Credentials from 'next-auth/providers/credentials'
|
|
||||||
import bcrypt from 'bcryptjs'
|
|
||||||
import { prisma } from '@/lib/db'
|
|
||||||
|
|
||||||
// NextAuth type augmentation — session.user.role için
|
|
||||||
declare module 'next-auth' {
|
|
||||||
interface Session {
|
|
||||||
user: {
|
|
||||||
role?: string
|
|
||||||
} & DefaultSession['user']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module 'next-auth/jwt' {
|
|
||||||
interface JWT {
|
|
||||||
role?: string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const { handlers, auth, signIn, signOut } = NextAuth({
|
|
||||||
adapter: PrismaAdapter(prisma),
|
|
||||||
providers: [
|
|
||||||
Credentials({
|
|
||||||
credentials: {
|
|
||||||
email: { label: 'Email', type: 'email' },
|
|
||||||
password: { label: 'Password', type: 'password' },
|
|
||||||
},
|
|
||||||
async authorize(credentials) {
|
|
||||||
if (!credentials?.email || !credentials?.password) return null
|
|
||||||
const user = await prisma.user.findUnique({
|
|
||||||
where: { email: credentials.email as string },
|
|
||||||
})
|
|
||||||
if (!user?.password) return null
|
|
||||||
const valid = await bcrypt.compare(credentials.password as string, user.password)
|
|
||||||
if (!valid) return null
|
|
||||||
return { id: user.id, email: user.email, name: user.name, role: user.role }
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
callbacks: {
|
|
||||||
jwt({ token, user }) {
|
|
||||||
if (user) token.role = (user as { role: string }).role
|
|
||||||
return token
|
|
||||||
},
|
|
||||||
session({ session, token }) {
|
|
||||||
if (token && session.user) {
|
|
||||||
session.user.role = token.role
|
|
||||||
}
|
|
||||||
return session
|
|
||||||
},
|
|
||||||
},
|
|
||||||
pages: {
|
|
||||||
signIn: '/tr/admin/login',
|
|
||||||
},
|
|
||||||
session: { strategy: 'jwt' },
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"next-intl": "^3.26.3",
|
"next-intl": "^3.26.3",
|
||||||
"next-auth": "^5.0.0-beta.25",
|
|
||||||
"@auth/prisma-adapter": "^2.7.2",
|
|
||||||
"@prisma/client": "^6.1.0",
|
"@prisma/client": "^6.1.0",
|
||||||
"cloudinary": "^2.5.1",
|
"cloudinary": "^2.5.1",
|
||||||
"gsap": "^3.12.5",
|
"gsap": "^3.12.5",
|
||||||
|
|||||||
@@ -1,24 +1,10 @@
|
|||||||
import createMiddleware from 'next-intl/middleware'
|
import createMiddleware from 'next-intl/middleware'
|
||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { NextRequest } from 'next/server'
|
||||||
import { routing } from '@/i18n/routing'
|
import { routing } from '@/i18n/routing'
|
||||||
|
|
||||||
const intlMiddleware = createMiddleware(routing)
|
const intlMiddleware = createMiddleware(routing)
|
||||||
|
|
||||||
export async function middleware(request: NextRequest) {
|
export async function middleware(request: NextRequest) {
|
||||||
const { pathname } = request.nextUrl
|
|
||||||
|
|
||||||
// Admin route'ları — token kontrolü
|
|
||||||
if (pathname.includes('/admin') && !pathname.includes('/admin/login')) {
|
|
||||||
const token =
|
|
||||||
request.cookies.get('next-auth.session-token')?.value ||
|
|
||||||
request.cookies.get('__Secure-next-auth.session-token')?.value
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
const locale = pathname.split('/')[1] || 'tr'
|
|
||||||
return NextResponse.redirect(new URL(`/${locale}/admin/login`, request.url))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return intlMiddleware(request)
|
return intlMiddleware(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user