-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor mutations to use helper queries and add validators fi…
…le (#73)
- Loading branch information
Showing
8 changed files
with
89 additions
and
111 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getAuthUserId } from "@convex-dev/auth/server"; | ||
import { | ||
customCtx, | ||
customMutation, | ||
customQuery, | ||
} from "convex-helpers/server/customFunctions"; | ||
import { mutation, query } from "./_generated/server"; | ||
|
||
export const userQuery = customQuery( | ||
query, | ||
customCtx(async (ctx) => { | ||
const userId = await getAuthUserId(ctx); | ||
if (userId === null) throw new Error("Not authenticated"); | ||
return { userId, ctx }; | ||
}), | ||
); | ||
|
||
export const userMutation = customMutation(mutation, { | ||
args: {}, | ||
input: async (ctx) => { | ||
const userId = await getAuthUserId(ctx); | ||
if (userId === null) throw new Error("Not authenticated"); | ||
return { ctx: { userId }, args: {} }; | ||
}, | ||
}); |
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
Oops, something went wrong.