Files
file-one/convex/users.ts

26 lines
674 B
TypeScript
Raw Normal View History

2025-09-15 21:44:41 +00:00
import { mutation } from "./_generated/server"
import { authenticatedQuery } from "./functions"
import { getOrCreateUser, userIdentityOrThrow } from "./model/user"
2025-09-13 22:02:27 +01:00
2025-09-15 21:44:41 +00:00
export const getCurrentUser = authenticatedQuery({
2025-09-13 22:02:27 +01:00
handler: async (ctx) => {
2025-09-15 21:44:41 +00:00
// ctx.user is the internal Convex user document
return ctx.user
},
})
export const syncUser = mutation({
handler: async (ctx) => {
// This function creates or updates the internal user from identity provider
const userId = await getOrCreateUser(ctx)
const identity = await userIdentityOrThrow(ctx)
return {
userId,
jwtSubject: identity.subject,
name: identity.name,
email: identity.email,
}
2025-09-13 22:02:27 +01:00
},
})