14 lines
510 B
TypeScript
14 lines
510 B
TypeScript
import { IdentityContext } from '@app/server/identity';
|
|
import { prisma } from '@app/server/prisma/client';
|
|
import { Identity } from '@generated/types';
|
|
import { toIdentitySchema } from './mappers/identityMapper';
|
|
|
|
export async function IdentityResolver(
|
|
_: any,
|
|
__: any,
|
|
{ identity }: IdentityContext
|
|
): Promise<Identity> {
|
|
if (identity == null) throw new Error('Unauthorized.');
|
|
const model = await prisma.user.findUniqueOrThrow({ where: { id: identity.id } });
|
|
return toIdentitySchema(model);
|
|
}
|