pstream-backend/server/routes/users/@me.ts
Pas 2ebdb1c901 Add nickname to users
Introduces a 'nickname' field to the users table and Prisma schema. Updates user registration and profile update routes to handle nicknames, including random nickname generation for new users. Adds a utility for generating random nicknames and migrates existing users to have generated nicknames.
2025-11-17 10:35:11 -07:00

36 lines
815 B
TypeScript

import { useAuth } from '~/utils/auth';
export default defineEventHandler(async event => {
const session = await useAuth().getCurrentSession();
const user = await prisma.users.findUnique({
where: { id: session.user },
});
if (!user) {
throw createError({
statusCode: 404,
message: 'User not found',
});
}
return {
user: {
id: user.id,
publicKey: user.public_key,
namespace: user.namespace,
nickname: user.nickname,
profile: user.profile,
permissions: user.permissions,
},
session: {
id: session.id,
user: session.user,
createdAt: session.created_at,
accessedAt: session.accessed_at,
expiresAt: session.expires_at,
device: session.device,
userAgent: session.user_agent,
},
};
});