-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch context based clients (#14)
BREAKING CHANGE: `getAuthData` removed from `createOpts`; `withAuth: true` removed from action opts; use context based clients Closes #13
- Loading branch information
Showing
16 changed files
with
542 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Try it yourself: [Link to example on Vercel](https://next-safe-action.vercel.app/). | ||
|
||
This is a basic implementation of the [next-safe-action](https:/TheEdoRan/next-safe-action/tree/main/packages/next-safe-action) library. | ||
This is a basic implementation of the [next-safe-action](../next-safe-action) library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...e-app/src/app/withauth/edituser-action.ts → ...p/src/app/with-context/edituser-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
import { randomBytes } from "crypto"; | ||
import { randomUUID } from "crypto"; | ||
import { createSafeActionClient } from "next-safe-action"; | ||
|
||
const action = createSafeActionClient({ | ||
// You can provide a custom function, otherwise the lib will use `console.error` | ||
export const action = createSafeActionClient({ | ||
// You can provide a custom log function, otherwise the lib will use `console.error` | ||
// as the default logging system. If you want to disable server errors logging, | ||
// just pass an empty function. | ||
serverErrorLogFunction: (e) => { | ||
console.error("CUSTOM ERROR LOG FUNCTION:", e); | ||
}, | ||
// This is required when you pass `withAuth: true` to safe actions. | ||
// Defining an action with `withAuth: true` option without implementing | ||
// the `getAuthData` function, results in a server error on action execution. | ||
// The return object of this function will be passed as the second parameter of | ||
// a server action definition function, where you provided `withAuth: true` as | ||
// an option. | ||
// Check `editUser` action in `src/app/withauth/edituser-action.ts` file for a | ||
// practical example. | ||
getAuthData: async () => { | ||
}); | ||
|
||
export const authAction = createSafeActionClient({ | ||
// You can provide a context builder function. In this case, context is used | ||
// for (fake) auth purposes. | ||
buildContext: async () => { | ||
return { | ||
userId: randomBytes(6).toString("hex"), | ||
userId: randomUUID(), | ||
}; | ||
}, | ||
}); | ||
|
||
export { action }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.