sipher/convex/betterAuth/user/index.ts
Nixyan 32168722a2 Add user status management and metadata fields to authentication
- Introduced user status management with the ability to update online, busy, offline, and away statuses.
- Added metadata fields for user preferences, including phrase preferences and friends list.
- Updated API and database schema to accommodate new user fields.
- Enhanced the authentication component to handle additional user data effectively.
- Implemented hooks for socket management and OLM setup to improve user experience.
2025-12-19 17:04:24 -03:00

28 lines
No EOL
660 B
TypeScript

import { v } from "convex/values";
import { Id } from "../../_generated/dataModel";
import { mutation } from "../../_generated/server";
export const updateUserStatus = mutation({
args: {
status: v.string(),
isUserSet: v.boolean(),
},
handler: async (ctx, args) => {
const user = await ctx.auth.getUserIdentity();
if (!user) {
throw new Error("User not found");
}
const userId = ctx.db.normalizeId("user", user.subject as string) as Id<"user">;
if (!userId) {
throw new Error("User not found");
}
return ctx.db.patch<"user">("user", userId, {
status: {
status: args.status,
isUserSet: args.isUserSet,
},
});
},
});