Bladeren bron

添加注释

fogwind 1 week geleden
bovenliggende
commit
8c0cea0b68

+ 9 - 0
src/components/customer/RegistrationForm.tsx

@@ -32,7 +32,16 @@ export default function RegistrationForm() {
 
   const { showToast } = useCustomToast();
 
+  /**
+   * 
+   * 浏览器端 RegistrationForm.onSubmit
+      → 调用 createUser(data)  ← 这是一个 Server Action
+        → 发送 POST 请求到当前页面路由(或者由框架生成的端点)
+          → 服务端执行 createUser 函数(访问 cookies、session、数据库等)
+            → 返回结果给浏览器 
+   */
   const onSubmit: SubmitHandler<RegisterInputs> = async (data) => {
+    console.log('register run where?--------');
     if (data.password !== data.passwordConfirmation) {
       showToast("The Passwords do not match.", "warning");
       return;

+ 2 - 1
src/utils/actions.ts

@@ -1,4 +1,5 @@
 "use server";
+// 文件顶部的 "use server" 是所有导出的异步函数自动成为 Server Action 的标志。
 import { redirect } from "next/navigation";
 import {
   createUserToLogin,
@@ -50,7 +51,7 @@ export async function createUser(formData: RegisterInputs) {
     return {
       error: { message: err?.message || "An error occurred" },
       success: false,
-      customer: {},
+      customer: null,
     };
   }
 }

+ 2 - 0
src/utils/auth.ts

@@ -10,6 +10,7 @@ export const authOptions: NextAuthOptions = {
   },
 
   providers: [
+    // https://next-auth.js.org/configuration/providers/credentials
     CredentialsProvider({
       name: "Credentials",
       credentials: {
@@ -62,6 +63,7 @@ export const authOptions: NextAuthOptions = {
     }),
   ],
 
+  //https://next-auth.js.org/configuration/callbacks
   callbacks: {
     async jwt({ token, user }) {
       if (user) {

+ 2 - 2
src/utils/bagisto/index.ts

@@ -194,7 +194,7 @@ export async function bagistoFetch<T>({
     // let cc = await cookies();
     // console.log('bagistoFetch --- url:', GRAPHQL_URL,isCookies);
     // console.log('bagistoFetch --- queryString:', queryString);
-    // console.log('bagistoFetch --- baseHeaders:', baseHeaders);
+    console.log('bagistoFetch --- baseHeaders:', baseHeaders);
     // console.log('bagistoFetch --- cookies:', cc.getAll());
     // console.log('bagistoFetch --- variables:', variables);
     const result = await fetch(GRAPHQL_URL, {
@@ -385,7 +385,7 @@ export async function logoutUser() {
     const message =
       res?.body?.data?.createLogout?.logout?.message ?? "Logout executed";
 
-    // 下面两行代码没啥用
+
     const cookieStore = await cookies();
     cookieStore.delete(BAGISTO_SESSION);
 

+ 2 - 0
src/utils/hooks/useAddToCart.ts

@@ -1,3 +1,5 @@
+"use client";
+
 import { useCustomToast } from "./useToast";
 import { useAppDispatch } from "@/store/hooks";
 import { addItem, clearCart } from "@/store/slices/cart-slice";

+ 1 - 0
src/utils/hooks/useCartDetail.ts

@@ -48,6 +48,7 @@ export function useCartDetail() {
     }
   }, [getCartDetailMutation]);
 
+  // useCartDetail在组件中被调用时就会触发useEffect
   useEffect(() => {
     if (!cart && !isInFlightRef.current) {
       getCartDetail();

+ 1 - 1
src/utils/jwt-cookie.ts

@@ -1,5 +1,5 @@
 // import { NEXT_AUTH_SECRET } from "./constants";
-// 
+// 把游客token编码
 export const encodeJWT = (payload: object): string => {
   try {
     const jsonStr = JSON.stringify(payload);