refactor: move convex into packages

This commit is contained in:
2025-09-16 23:17:01 +00:00
parent ff1334aa36
commit ec8ed588f5
22 changed files with 43 additions and 14 deletions

32
packages/convex/users.ts Normal file
View File

@@ -0,0 +1,32 @@
import { mutation } from "./_generated/server"
import { authenticatedQuery } from "./functions"
import * as Err from "./model/error"
export const getCurrentUser = authenticatedQuery({
handler: async (ctx) => {
// ctx.user is the internal Convex user document
return ctx.user
},
})
export const syncUser = mutation({
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity()
if (!identity) {
throw Err.create(Err.Code.Unauthenticated)
}
const existingUser = await ctx.db
.query("users")
.withIndex("byJwtSubject", (q) =>
q.eq("jwtSubject", identity.subject),
)
.first()
if (!existingUser) {
await ctx.db.insert("users", {
jwtSubject: identity.subject,
})
}
},
})