feat(frontend): Server Actions for thought, social, and profile mutations
This commit is contained in:
28
thoughts-frontend/app/actions/social.ts
Normal file
28
thoughts-frontend/app/actions/social.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
"use server";
|
||||
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
import {
|
||||
followUser as apiFollowUser,
|
||||
unfollowUser as apiUnfollowUser,
|
||||
} from "@/lib/api";
|
||||
|
||||
async function getToken(): Promise<string> {
|
||||
const token = (await cookies()).get("auth_token")?.value;
|
||||
if (!token) throw new Error("Not authenticated");
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function followUser(username: string) {
|
||||
const token = await getToken();
|
||||
await apiFollowUser(username, token);
|
||||
revalidateTag(`profile:${username}`);
|
||||
revalidateTag("feed");
|
||||
}
|
||||
|
||||
export async function unfollowUser(username: string) {
|
||||
const token = await getToken();
|
||||
await apiUnfollowUser(username, token);
|
||||
revalidateTag(`profile:${username}`);
|
||||
revalidateTag("feed");
|
||||
}
|
||||
Reference in New Issue
Block a user