Revert new authentication method for preview bot

This commit is contained in:
Baptiste Arnaud
2023-11-13 15:45:11 +01:00
parent 084588a086
commit 06065c3e85
6 changed files with 26 additions and 43 deletions

View File

@@ -90,7 +90,7 @@ export const sendMessageV1 = publicProcedure
? undefined
: startParams.typebot,
message,
userId: parseUserId(user?.id),
userId: user?.id,
}
: {
type: 'live',
@@ -172,13 +172,3 @@ export const sendMessageV1 = publicProcedure
}
}
)
const parseUserId = (userId?: string): string => {
if (!userId)
throw new TRPCError({
code: 'UNAUTHORIZED',
message: 'You need to be authenticated to perform this action',
})
return userId
}

View File

@@ -90,7 +90,7 @@ export const sendMessageV2 = publicProcedure
? undefined
: startParams.typebot,
message,
userId: parseUserId(user?.id),
userId: user?.id,
}
: {
type: 'live',
@@ -172,13 +172,3 @@ export const sendMessageV2 = publicProcedure
}
}
)
const parseUserId = (userId?: string): string => {
if (!userId)
throw new TRPCError({
code: 'UNAUTHORIZED',
message: 'You need to be authenticated to perform this action',
})
return userId
}

View File

@@ -1,4 +1,3 @@
import { authenticatedProcedure } from '@/helpers/server/trpc'
import {
startPreviewChatInputSchema,
startPreviewChatResponseSchema,
@@ -6,8 +5,9 @@ import {
import { startSession } from '@typebot.io/bot-engine/startSession'
import { saveStateToDatabase } from '@typebot.io/bot-engine/saveStateToDatabase'
import { restartSession } from '@typebot.io/bot-engine/queries/restartSession'
import { publicProcedure } from '@/helpers/server/trpc'
export const startChatPreview = authenticatedProcedure
export const startChatPreview = publicProcedure
.meta({
openapi: {
method: 'POST',
@@ -47,7 +47,7 @@ export const startChatPreview = authenticatedProcedure
startFrom,
typebotId,
typebot: startTypebot,
userId: user.id,
userId: user?.id,
},
message,
})

View File

@@ -1,3 +1,4 @@
import { publicProcedure } from '@/helpers/server/trpc'
import { TRPCError } from '@trpc/server'
import { z } from 'zod'
import { getSession } from '@typebot.io/bot-engine/queries/getSession'
@@ -8,9 +9,8 @@ import {
Variable,
} from '@typebot.io/schemas'
import prisma from '@typebot.io/lib/prisma'
import { authenticatedProcedure } from '@/helpers/server/trpc'
export const updateTypebotInSession = authenticatedProcedure
export const updateTypebotInSession = publicProcedure
.meta({
openapi: {
method: 'POST',
@@ -28,6 +28,8 @@ export const updateTypebotInSession = authenticatedProcedure
)
.output(z.object({ message: z.literal('success') }))
.mutation(async ({ input: { sessionId }, ctx: { user } }) => {
if (!user)
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Unauthorized' })
const session = await getSession(sessionId)
if (!session)
throw new TRPCError({ code: 'NOT_FOUND', message: 'Session not found' })