From a44fb241369f7135003d957f803d901262e7ca93 Mon Sep 17 00:00:00 2001 From: Deardo Satria Date: Wed, 21 Oct 2026 11:36:52 +0700 Subject: [PATCH] Move login and logout actions into app/(auth)/actions.ts --- CLAUDE.md | 4 ++++ app/(auth)/{login => }/actions.ts | 5 +++++ app/(auth)/login/_components/login-form.tsx | 2 +- app/(dashboard)/actions.ts | 10 ---------- app/(dashboard)/page.tsx | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) rename app/(auth)/{login => }/actions.ts (90%) delete mode 100644 app/(dashboard)/actions.ts diff --git a/CLAUDE.md b/CLAUDE.md index aa4ebc4..0f213c3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -34,6 +34,7 @@ Tanpa folder `src/`. Kode aplikasi di root, sejajar config. ``` app/ + (auth)/actions.ts Server Actions auth (login, logout), dipakai lintas route group (auth)/login/page.tsx halaman publik (belum login) (dashboard)/layout.tsx kerangka UI halaman yang wajib login (bukan tempat cek session) (dashboard)// @@ -60,6 +61,9 @@ proxy.ts pengganti middleware di Next 16; hanya cek rin - Folder berawalan `_` tidak menjadi route; pakai untuk komponen yang dikolokasikan. - Route group `(nama)` hanya untuk mengelompokkan layout, tidak muncul di URL. - Import pakai alias `@/` (mis. `@/db`, `@/data/barang`). +- `actions.ts` dikolokasikan dengan fitur yang memakainya. Action yang dipakai lintas route group + (mis. `logout` dipanggil dari `(dashboard)`) ditaruh di level route group pemiliknya, lalu + di-import lewat alias (`@/app/(auth)/actions`), bukan path relatif `../(auth)/...`. ## Aturan data dan Server Actions diff --git a/app/(auth)/login/actions.ts b/app/(auth)/actions.ts similarity index 90% rename from app/(auth)/login/actions.ts rename to app/(auth)/actions.ts index 29a08fd..9d31865 100644 --- a/app/(auth)/login/actions.ts +++ b/app/(auth)/actions.ts @@ -48,3 +48,8 @@ export async function login( redirect("/"); } + +export async function logout() { + await auth.api.signOut({ headers: await headers() }); + redirect("/login"); +} diff --git a/app/(auth)/login/_components/login-form.tsx b/app/(auth)/login/_components/login-form.tsx index 2176b81..a8ebe11 100644 --- a/app/(auth)/login/_components/login-form.tsx +++ b/app/(auth)/login/_components/login-form.tsx @@ -16,7 +16,7 @@ import { FieldLabel, } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; -import { login, type LoginState } from "../actions"; +import { login, type LoginState } from "../../actions"; const initialState: LoginState = {}; diff --git a/app/(dashboard)/actions.ts b/app/(dashboard)/actions.ts deleted file mode 100644 index c61d876..0000000 --- a/app/(dashboard)/actions.ts +++ /dev/null @@ -1,10 +0,0 @@ -"use server"; - -import { headers } from "next/headers"; -import { redirect } from "next/navigation"; -import { auth } from "@/lib/auth"; - -export async function logout() { - await auth.api.signOut({ headers: await headers() }); - redirect("/login"); -} diff --git a/app/(dashboard)/page.tsx b/app/(dashboard)/page.tsx index f3a383c..c32d2e3 100644 --- a/app/(dashboard)/page.tsx +++ b/app/(dashboard)/page.tsx @@ -1,6 +1,6 @@ import { Suspense } from "react"; import { getCurrentUser } from "@/data/auth"; -import { logout } from "./actions"; +import { logout } from "@/app/(auth)/actions"; import { Button } from "@/components/ui/button"; export default function DashboardPage() {