Skip to content

Commit

Permalink
feat: changes from codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlitgrace committed Oct 30, 2024
1 parent 4e21863 commit d221786
Show file tree
Hide file tree
Showing 7 changed files with 651 additions and 206 deletions.
3 changes: 2 additions & 1 deletion app/(routes)/(admin)/admin/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import AdminBlogForm from '@/app/_components/_admin/admin-blog-form';
import { PostSelect } from '@/db/schema';
import { notFound } from 'next/navigation';

export default async function Page({ params }: { params: { slug: string } }) {
export default async function Page(props: { params: Promise<{ slug: string }> }) {
const params = await props.params;
const post: Omit<PostSelect, 'createdAt'> = await fetch(
`${process.env.NEXT_PUBLIC_APP_URL}/api/blog/${params.slug}`,
)
Expand Down
10 changes: 5 additions & 5 deletions app/(routes)/(main)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import Markdown from '@/components/markdown';
import TableOfContents from '@/app/_components/_main/table-of-contents';
import { notFound } from 'next/navigation';

export async function generateMetadata({
params,
}: {
params: { slug: string };
export async function generateMetadata(props: {
params: Promise<{ slug: string }>;
}): Promise<Metadata> {
const params = await props.params;
const res = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/blog/${params.slug}`);

if (res.status === 404)
Expand Down Expand Up @@ -62,7 +61,8 @@ export async function generateMetadata({
};
}

export default async function Page({ params }: { params: { slug: string } }) {
export default async function Page(props: { params: Promise<{ slug: string }> }) {
const params = await props.params;
const post: PostSelect = await fetch(`${process.env.NEXT_PUBLIC_APP_URL}/api/blog/${params.slug}`)
.then((res) => {
if (res.status === 404) notFound();
Expand Down
2 changes: 1 addition & 1 deletion app/_lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function createSession(username: string) {
const expireTime = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
const session = await encrypt({ username, expireTime });

cookies().set('session', session, {
(await cookies()).set('session', session, {
httpOnly: true,
secure: true,
expires: expireTime,
Expand Down
8 changes: 5 additions & 3 deletions app/api/blog/[slug]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { eq } from 'drizzle-orm';
import { NextRequest, NextResponse } from 'next/server';

interface RestProps {
params: { slug: string };
params: Promise<{ slug: string }>;
}

export async function GET(_request: NextRequest, { params }: RestProps) {
export async function GET(_request: NextRequest, props: RestProps) {
const params = await props.params;
try {
const post = await db
.select()
Expand All @@ -26,7 +27,8 @@ export async function GET(_request: NextRequest, { params }: RestProps) {
}
}

export async function DELETE(_request: NextRequest, { params }: RestProps) {
export async function DELETE(_request: NextRequest, props: RestProps) {
const params = await props.params;
try {
await db.delete(posts).where(eq(posts.slug, params.slug));
return NextResponse.json({ message: 'success' });
Expand Down
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { decrypt } from './app/_lib/session';

export default async function middleware(request: NextRequest) {
const cookie = cookies().get('session')?.value;
const cookie = (await cookies()).get('session')?.value;
const session = await decrypt(cookie);

const { pathname } = request.nextUrl;
Expand Down
Loading

0 comments on commit d221786

Please sign in to comment.