next-safe-form 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,29 +88,40 @@ useActionForm();
|
|
|
88
88
|
```ts
|
|
89
89
|
export async function loginAction(_, formData: FormData) {
|
|
90
90
|
const data = Object.fromEntries(formData);
|
|
91
|
+
const { success, error } = await someValidationFunction(data);
|
|
91
92
|
|
|
92
93
|
// Example validation error
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
success: false,
|
|
96
|
-
error: { email: "Email is required" },
|
|
97
|
-
type: "fields",
|
|
98
|
-
};
|
|
99
|
-
}
|
|
94
|
+
if (!success || error) {
|
|
95
|
+
const fields = extractZodError(error);
|
|
100
96
|
|
|
101
|
-
// Example server error
|
|
102
|
-
if (data.email !== "test@test.com") {
|
|
103
97
|
return {
|
|
104
98
|
success: false,
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
data,
|
|
100
|
+
error: {
|
|
101
|
+
type: "fields",
|
|
102
|
+
fields,
|
|
103
|
+
message: "Données invalides",
|
|
104
|
+
},
|
|
107
105
|
};
|
|
108
106
|
}
|
|
109
107
|
|
|
108
|
+
// Example server error
|
|
110
109
|
return {
|
|
111
|
-
success:
|
|
110
|
+
success: false,
|
|
112
111
|
data,
|
|
112
|
+
error: {
|
|
113
|
+
type: "server",
|
|
114
|
+
message: "Identifiant incorrect",
|
|
115
|
+
},
|
|
113
116
|
};
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
success: true,
|
|
120
|
+
data: {
|
|
121
|
+
phone: "",
|
|
122
|
+
password: ""
|
|
123
|
+
}
|
|
124
|
+
};
|
|
114
125
|
}
|
|
115
126
|
```
|
|
116
127
|
|