| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- "use server";
- import {cookies} from "next/headers";
- import { IS_GUEST } from "@/utils/constants";
- import { serverGraphqlFetch } from "@utils/bagisto";
- import {CUSTOMER_LOGOUT} from "@/graphql/customer/mutations";
- import type { LogoutData } from "@/types/types";
- export async function logoutAction() {
- try {
- const res = await serverGraphqlFetch<LogoutData>({
- query: CUSTOMER_LOGOUT,
- });
- let success = true;
- let msg = "";
- if(res.error) {
- success = false;
- msg = res.error.message;
- } else {
- success = res.data?.createLogout?.logout?.success ?? false;
- msg = res.data?.createLogout?.logout?.message ?? "";
- if(success) {
- const cookieStore = await cookies();
- // 设置游客状态
- cookieStore.set(IS_GUEST, "true");
- }
- }
- return {
- success,
- message: msg,
- };
- } catch (error: unknown) {
- return {
- success: false,
- message: error instanceof Error ? error.message : "Something went wrong",
- };
- }
- }
|