Materialize teams from Logto JWT claims
Build and deploy Docker image / build (push) Successful in 50s

This commit is contained in:
Ruslan Bakiev
2026-06-05 13:10:47 +07:00
parent 030e13d02e
commit 221b66e0d3
6 changed files with 119 additions and 46 deletions
+7
View File
@@ -2,6 +2,7 @@ import { GraphQLError } from 'graphql'
import { randomUUID, createHash } from 'crypto'
import { prisma } from '../db.js'
import { requireScopes, type AuthContext } from '../auth.js'
import { materializeTeamFromContext } from '../team-materialization.js'
export const teamTypeDefs = `#graphql
type TeamUser {
@@ -153,6 +154,7 @@ export const teamResolvers = {
team: async (_: unknown, __: unknown, ctx: AuthContext) => {
requireScopes(ctx, 'teams:member')
if (!ctx.teamUuid) throw new GraphQLError('Team UUID not found')
await materializeTeamFromContext(ctx)
const team = await getTeamByUuid(ctx.teamUuid)
return team ? mapTeam(team) : null
},
@@ -166,6 +168,7 @@ export const teamResolvers = {
teamMembers: async (_: unknown, __: unknown, ctx: AuthContext) => {
requireScopes(ctx, 'teams:member')
if (!ctx.teamUuid) return []
await materializeTeamFromContext(ctx)
const team = await prisma.team.findUnique({ where: { uuid: ctx.teamUuid } })
if (!team) return []
const members = await prisma.teamMember.findMany({
@@ -186,6 +189,7 @@ export const teamResolvers = {
teamAddresses: async (_: unknown, __: unknown, ctx: AuthContext) => {
requireScopes(ctx, 'teams:member')
if (!ctx.teamUuid) return []
await materializeTeamFromContext(ctx)
const team = await prisma.team.findUnique({ where: { uuid: ctx.teamUuid } })
if (!team) return []
const addrs = await prisma.teamAddress.findMany({ where: { teamId: team.id }, orderBy: { createdAt: 'desc' } })
@@ -204,6 +208,7 @@ export const teamResolvers = {
inviteMember: async (_: unknown, args: { input: { email: string; role?: string } }, ctx: AuthContext) => {
requireScopes(ctx, 'teams:member')
if (!ctx.teamUuid || !ctx.userId) throw new GraphQLError('Not authenticated')
await materializeTeamFromContext(ctx)
const team = await prisma.team.findUnique({ where: { uuid: ctx.teamUuid } })
if (!team) throw new GraphQLError('Team not found')
const invitation = await prisma.teamInvitation.create({
@@ -229,6 +234,7 @@ export const teamResolvers = {
createTeamAddress: async (_: unknown, args: { input: { name: string; address: string; latitude?: number; longitude?: number; countryCode?: string; isDefault?: boolean } }, ctx: AuthContext) => {
requireScopes(ctx, 'teams:member')
if (!ctx.teamUuid) throw new GraphQLError('Not authenticated')
await materializeTeamFromContext(ctx)
const team = await prisma.team.findUnique({ where: { uuid: ctx.teamUuid } })
if (!team) throw new GraphQLError('Team not found')
const addr = await prisma.teamAddress.create({
@@ -275,6 +281,7 @@ export const teamResolvers = {
setSelectedLocation: async (_: unknown, args: { input: { type: string; uuid: string; name: string; latitude: number; longitude: number } }, ctx: AuthContext) => {
requireScopes(ctx, 'teams:member')
if (!ctx.teamUuid) throw new GraphQLError('Not authenticated')
await materializeTeamFromContext(ctx)
await prisma.team.update({
where: { uuid: ctx.teamUuid },
data: {