feat: integrate Cloudinary image upload, Instagram Feed, and fix Next.js warnings
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
import { SignJWT, jwtVerify } from 'jose';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
const secretKey = process.env.JWT_SECRET || 'fallback-secret-for-development-only-do-not-use-in-prod';
|
||||
const key = new TextEncoder().encode(secretKey);
|
||||
|
||||
export async function signToken(payload: any) {
|
||||
return await new SignJWT(payload)
|
||||
.setProtectedHeader({ alg: 'HS256' })
|
||||
.setIssuedAt()
|
||||
.setExpirationTime('1d') // 1 günlük oturum süresi
|
||||
.sign(key);
|
||||
}
|
||||
|
||||
export async function verifyToken(token: string) {
|
||||
try {
|
||||
const { payload } = await jwtVerify(token, key);
|
||||
return payload;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function setAuthCookie(token: string) {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set('admin_token', token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax',
|
||||
maxAge: 60 * 60 * 24, // 1 day in seconds
|
||||
path: '/',
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeAuthCookie() {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.delete('admin_token');
|
||||
}
|
||||
|
||||
export async function getAuthCookie() {
|
||||
const cookieStore = await cookies();
|
||||
const token = cookieStore.get('admin_token')?.value;
|
||||
return token ? await verifyToken(token) : null;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { PrismaClient } from '@/app/generated/prisma/client';
|
||||
import { Pool } from 'pg';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
|
||||
const pool = new Pool({ connectionString });
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined;
|
||||
};
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ??
|
||||
new PrismaClient({ adapter });
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
|
||||
Reference in New Issue
Block a user