Trying to add avatar upload. Project works rn so wanna push
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { ConvexError, v } from 'convex/values';
|
||||
import { convexAuth, getAuthUserId } from '@convex-dev/auth/server';
|
||||
import { query } from './_generated/server';
|
||||
import { mutation, query } from './_generated/server';
|
||||
import Password from './CustomPassword';
|
||||
|
||||
export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
|
||||
@@ -10,7 +11,7 @@ export const getUser = query(async (ctx) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
if (!userId) return null;
|
||||
const user = await ctx.db.get(userId);
|
||||
if (!user) return null;
|
||||
if (!user) throw new ConvexError('User not found.');
|
||||
return {
|
||||
id: user._id,
|
||||
email: user.email ?? null,
|
||||
@@ -18,3 +19,15 @@ export const getUser = query(async (ctx) => {
|
||||
image: user.image ?? null,
|
||||
};
|
||||
});
|
||||
|
||||
export const updateUserImage = mutation({
|
||||
args: {
|
||||
storageId: v.id('_storage')
|
||||
},
|
||||
handler: async (ctx, {storageId}) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
if (!userId) throw new ConvexError('Not authenticated.');
|
||||
await ctx.db.patch(userId, { image: storageId });
|
||||
return { success: true };
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user