fix: handle auth for ai assistant

This commit is contained in:
Andrey A. committed 2026-02-02 20:22:48 +01:00
1 parent d9e3cdb5d2
commit 5a67ece2d3
4 files changed
+8 -5

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { ResponseError, ResponseFailure } from 'types'
import { IS_PLATFORM } from '../constants'
import { IS_PLATFORM, STUDIO_AUTH_ENABLED } from '../constants'
import { apiAuthenticate } from './apiAuthenticate'
export function isResponseOk<T>(response: T | ResponseFailure | undefined): response is T {
@@ -32,7 +32,7 @@ export default async function apiWrapper(
try {
const { withAuth } = options || {}
if (IS_PLATFORM && withAuth) {
if ((IS_PLATFORM || STUDIO_AUTH_ENABLED) && withAuth) {
const response = await apiAuthenticate(req, res)
if (!isResponseOk(response)) {
return res.status(401).json({
+2 -1
View File
@@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { z } from 'zod'
import { IS_PLATFORM } from 'common'
import { STUDIO_AUTH_ENABLED } from 'lib/constants'
import type { AiOptInLevel } from 'hooks/misc/useOrgOptedIntoAi'
import { getModel } from 'lib/ai/model'
import { getOrgAIDetails } from 'lib/ai/org-ai-details'
@@ -37,7 +38,7 @@ export async function handlePost(req: NextApiRequest, res: NextApiResponse) {
const authorization = req.headers.authorization
const accessToken = authorization?.replace('Bearer ', '')
if (IS_PLATFORM && !accessToken) {
if ((IS_PLATFORM || STUDIO_AUTH_ENABLED) && !accessToken) {
return res.status(401).json({ error: 'Authorization token is required' })
}
+2 -1
View File
@@ -4,6 +4,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'
import z from 'zod'
import { IS_PLATFORM } from 'common'
import { STUDIO_AUTH_ENABLED } from 'lib/constants'
import { executeSql } from 'data/sql/execute-sql-query'
import type { AiOptInLevel } from 'hooks/misc/useOrgOptedIntoAi'
import { getModel } from 'lib/ai/model'
@@ -59,7 +60,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
const authorization = req.headers.authorization
const accessToken = authorization?.replace('Bearer ', '')
if (IS_PLATFORM && !accessToken) {
if ((IS_PLATFORM || STUDIO_AUTH_ENABLED) && !accessToken) {
return res.status(401).json({ error: 'Authorization token is required' })
}
+2 -1
View File
@@ -1,5 +1,6 @@
import { Output, generateText, stepCountIs } from 'ai'
import { IS_PLATFORM } from 'common'
import { STUDIO_AUTH_ENABLED } from 'lib/constants'
import { source } from 'common-tags'
import { NextApiRequest, NextApiResponse } from 'next'
import { z } from 'zod'
@@ -55,7 +56,7 @@ export async function handlePost(req: NextApiRequest, res: NextApiResponse) {
const authorization = req.headers.authorization
const accessToken = authorization?.replace('Bearer ', '')
if (IS_PLATFORM && !accessToken) {
if ((IS_PLATFORM || STUDIO_AUTH_ENABLED) && !accessToken) {
return res.status(401).json({ error: 'Authorization token is required' })
}