fix(auth): move initialAuthState/AuthState to auth-types.ts

Server-action files ('use server') can only export async functions.
Exporting initialAuthState (object) caused:
  'A use server file can only export async functions, found object'
when sign-up form was submitted.

Moved AuthState type and initialAuthState const to lib/appwrite/auth-types.ts.
Updated 3 form components to import the const from the new location.
This commit is contained in:
kovakmedya
2026-04-30 03:08:26 +03:00
parent dfa1b28632
commit d8b61b7da8
5 changed files with 13 additions and 12 deletions
@@ -9,7 +9,8 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { forgotPasswordAction, initialAuthState } from "@/lib/appwrite/auth-actions"; import { forgotPasswordAction } from "@/lib/appwrite/auth-actions";
import { initialAuthState } from "@/lib/appwrite/auth-types";
export function ForgotPasswordForm1({ className, ...props }: React.ComponentProps<"div">) { export function ForgotPasswordForm1({ className, ...props }: React.ComponentProps<"div">) {
const [state, formAction, isPending] = useActionState(forgotPasswordAction, initialAuthState); const [state, formAction, isPending] = useActionState(forgotPasswordAction, initialAuthState);
@@ -10,7 +10,8 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Logo } from "@/components/logo"; import { Logo } from "@/components/logo";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { initialAuthState, signInAction } from "@/lib/appwrite/auth-actions"; import { signInAction } from "@/lib/appwrite/auth-actions";
import { initialAuthState } from "@/lib/appwrite/auth-types";
export function LoginForm1({ className, ...props }: React.ComponentProps<"div">) { export function LoginForm1({ className, ...props }: React.ComponentProps<"div">) {
const [state, formAction, isPending] = useActionState(signInAction, initialAuthState); const [state, formAction, isPending] = useActionState(signInAction, initialAuthState);
@@ -10,7 +10,8 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Logo } from "@/components/logo"; import { Logo } from "@/components/logo";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { initialAuthState, signUpAction } from "@/lib/appwrite/auth-actions"; import { signUpAction } from "@/lib/appwrite/auth-actions";
import { initialAuthState } from "@/lib/appwrite/auth-types";
export function SignupForm1({ className, ...props }: React.ComponentProps<"div">) { export function SignupForm1({ className, ...props }: React.ComponentProps<"div">) {
const [state, formAction, isPending] = useActionState(signUpAction, initialAuthState); const [state, formAction, isPending] = useActionState(signUpAction, initialAuthState);
+1 -9
View File
@@ -5,13 +5,7 @@ import { redirect } from "next/navigation";
import { AppwriteException, ID } from "node-appwrite"; import { AppwriteException, ID } from "node-appwrite";
import { APPWRITE_SESSION_COOKIE, createAdminClient, createSessionClient } from "./server"; import { APPWRITE_SESSION_COOKIE, createAdminClient, createSessionClient } from "./server";
import type { AuthState } from "./auth-types";
export type AuthState = {
ok: boolean;
error?: string;
};
const initial: AuthState = { ok: false };
function appwriteError(e: unknown): string { function appwriteError(e: unknown): string {
if (e instanceof AppwriteException) { if (e instanceof AppwriteException) {
@@ -114,5 +108,3 @@ export async function signOutAction() {
(await cookies()).delete(APPWRITE_SESSION_COOKIE); (await cookies()).delete(APPWRITE_SESSION_COOKIE);
redirect("/sign-in"); redirect("/sign-in");
} }
export const initialAuthState = initial;
+6
View File
@@ -0,0 +1,6 @@
export type AuthState = {
ok: boolean;
error?: string;
};
export const initialAuthState: AuthState = { ok: false };