next-action-forge 0.2.7 → 0.2.8

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.
Files changed (2) hide show
  1. package/README.md +52 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -155,6 +155,57 @@ export const updateProfile = authClient
155
155
  });
156
156
  ```
157
157
 
158
+ ### Server-Driven Redirects
159
+
160
+ Define redirects that execute automatically after successful actions:
161
+
162
+ ```typescript
163
+ // Simple redirect
164
+ export const logoutAction = actionClient
165
+ .redirect("/login")
166
+ .action(async () => {
167
+ await clearSession();
168
+ return { message: "Logged out successfully" };
169
+ });
170
+
171
+ // Redirect with configuration
172
+ export const deleteAccountAction = actionClient
173
+ .redirect({
174
+ url: "/goodbye",
175
+ replace: true, // Use router.replace instead of push
176
+ delay: 2000 // Delay redirect by 2 seconds
177
+ })
178
+ .action(async () => {
179
+ await deleteUserAccount();
180
+ return { deleted: true };
181
+ });
182
+
183
+ // Conditional redirect based on result
184
+ export const updateProfileAction = actionClient
185
+ .redirect((result) => result.needsVerification ? "/verify" : "/profile")
186
+ .inputSchema(profileSchema)
187
+ .action(async (input) => {
188
+ const user = await updateUser(input);
189
+ return {
190
+ user,
191
+ needsVerification: !user.emailVerified
192
+ };
193
+ });
194
+ ```
195
+
196
+ Client-side usage:
197
+
198
+ ```tsx
199
+ const { execute } = useServerAction(logoutAction, {
200
+ onSuccess: (data) => {
201
+ // This runs BEFORE the redirect
202
+ toast.success("Logged out successfully");
203
+ },
204
+ preventRedirect: true, // Optionally prevent automatic redirect
205
+ redirectDelay: 1000, // Global delay for all redirects
206
+ });
207
+ ```
208
+
158
209
  ### Form Actions
159
210
 
160
211
  ```typescript
@@ -442,6 +493,7 @@ client
442
493
  .inputSchema(zodSchema) // Set input validation schema
443
494
  .outputSchema(zodSchema) // Set output validation schema
444
495
  .onError(handler) // Set error handler
496
+ .redirect(config) // Set redirect on success
445
497
  .action(serverFunction) // Define the server action
446
498
  .formAction(serverFunction) // Define a form action
447
499
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-action-forge",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "A simple, type-safe toolkit for Next.js server actions with Zod validation",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",