Got the profile picture thing working!
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ConvexError, v } from 'convex/values';
|
||||
import { convexAuth, getAuthUserId } from '@convex-dev/auth/server';
|
||||
import { mutation, query } from './_generated/server';
|
||||
import { type Id } from './_generated/dataModel';
|
||||
import Password from './CustomPassword';
|
||||
|
||||
export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
|
||||
@@ -12,19 +13,23 @@ export const getUser = query(async (ctx) => {
|
||||
if (!userId) return null;
|
||||
const user = await ctx.db.get(userId);
|
||||
if (!user) throw new ConvexError('User not found.');
|
||||
const image: Id<'_storage'> | null =
|
||||
typeof user.image === 'string' && user.image.length > 0
|
||||
? user.image as Id<'_storage'>
|
||||
: null
|
||||
return {
|
||||
id: user._id,
|
||||
email: user.email ?? null,
|
||||
name: user.name ?? null,
|
||||
image: user.image ?? null,
|
||||
image,
|
||||
};
|
||||
});
|
||||
|
||||
export const updateUserImage = mutation({
|
||||
args: {
|
||||
storageId: v.id('_storage')
|
||||
storageId: v.id('_storage'),
|
||||
},
|
||||
handler: async (ctx, {storageId}) => {
|
||||
handler: async (ctx, { storageId }) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
if (!userId) throw new ConvexError('Not authenticated.');
|
||||
await ctx.db.patch(userId, { image: storageId });
|
||||
|
Reference in New Issue
Block a user