🚑 (auth) Fix bad requests with getSession on server side
This commit is contained in:
@@ -1,19 +1,27 @@
|
|||||||
import prisma from '@/lib/prisma'
|
import prisma from '@/lib/prisma'
|
||||||
|
import { authOptions } from '@/pages/api/auth/[...nextauth]'
|
||||||
import { setUser } from '@sentry/nextjs'
|
import { setUser } from '@sentry/nextjs'
|
||||||
import { User } from '@typebot.io/prisma'
|
import { User } from '@typebot.io/prisma'
|
||||||
import { NextApiRequest } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { getSession } from 'next-auth/react'
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { mockedUser } from '../mockedUser'
|
||||||
|
import { env } from '@typebot.io/lib'
|
||||||
|
|
||||||
export const getAuthenticatedUser = async (
|
export const getAuthenticatedUser = async (
|
||||||
req: NextApiRequest
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse
|
||||||
): Promise<User | undefined> => {
|
): Promise<User | undefined> => {
|
||||||
const bearerToken = extractBearerToken(req)
|
const bearerToken = extractBearerToken(req)
|
||||||
if (bearerToken) return authenticateByToken(bearerToken)
|
if (bearerToken) return authenticateByToken(bearerToken)
|
||||||
const session = await getSession({ req })
|
const user =
|
||||||
if (!session?.user || !('id' in session.user)) return
|
env('E2E_TEST') === 'true'
|
||||||
const user = session.user as User
|
? mockedUser
|
||||||
|
: ((await getServerSession(req, res, authOptions))?.user as
|
||||||
|
| User
|
||||||
|
| undefined)
|
||||||
|
if (!user || !('id' in user)) return
|
||||||
setUser({ id: user.id, email: user.email ?? undefined })
|
setUser({ id: user.id, email: user.email ?? undefined })
|
||||||
return session?.user as User
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
const authenticateByToken = async (
|
const authenticateByToken = async (
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { inferAsyncReturnType } from '@trpc/server'
|
|||||||
import * as trpcNext from '@trpc/server/adapters/next'
|
import * as trpcNext from '@trpc/server/adapters/next'
|
||||||
|
|
||||||
export async function createContext(opts: trpcNext.CreateNextContextOptions) {
|
export async function createContext(opts: trpcNext.CreateNextContextOptions) {
|
||||||
const user = await getAuthenticatedUser(opts.req)
|
const user = await getAuthenticatedUser(opts.req, opts.res)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import NextAuth, { Account } from 'next-auth'
|
import NextAuth, { Account, AuthOptions } from 'next-auth'
|
||||||
import EmailProvider from 'next-auth/providers/email'
|
import EmailProvider from 'next-auth/providers/email'
|
||||||
import GitHubProvider from 'next-auth/providers/github'
|
import GitHubProvider from 'next-auth/providers/github'
|
||||||
import GitlabProvider from 'next-auth/providers/gitlab'
|
import GitlabProvider from 'next-auth/providers/gitlab'
|
||||||
@@ -128,11 +128,7 @@ if (isNotEmpty(process.env.CUSTOM_OAUTH_WELL_KNOWN_URL)) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
export const authOptions: AuthOptions = {
|
||||||
if (req.url === '/api/auth/session' && env('E2E_TEST') === 'true')
|
|
||||||
return res.send({ user: mockedUser })
|
|
||||||
if (req.method === 'HEAD') return res.status(200)
|
|
||||||
return NextAuth(req, res, {
|
|
||||||
adapter: CustomAdapter(prisma),
|
adapter: CustomAdapter(prisma),
|
||||||
secret: process.env.ENCRYPTION_SECRET,
|
secret: process.env.ENCRYPTION_SECRET,
|
||||||
providers,
|
providers,
|
||||||
@@ -168,7 +164,17 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
const isMockingSession =
|
||||||
|
req.method === 'GET' &&
|
||||||
|
req.url === '/api/auth/session' &&
|
||||||
|
env('E2E_TEST') === 'true'
|
||||||
|
if (isMockingSession) return res.send({ user: mockedUser })
|
||||||
|
const requestIsFromCompanyFirewall = req.method === 'HEAD'
|
||||||
|
if (requestIsFromCompanyFirewall) return res.status(200).end()
|
||||||
|
return await NextAuth(req, res, authOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateLastActivityDate = async (user: User) => {
|
const updateLastActivityDate = async (user: User) => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@typebot.io/lib/api'
|
} from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const workspaceId = req.query.workspaceId as string | undefined
|
const workspaceId = req.query.workspaceId as string | undefined
|
||||||
if (!workspaceId) return badRequest(res)
|
if (!workspaceId) return badRequest(res)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const workspaceId = req.query.workspaceId as string | undefined
|
const workspaceId = req.query.workspaceId as string | undefined
|
||||||
if (!workspaceId) return badRequest(res)
|
if (!workspaceId) return badRequest(res)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { oauth2Client } from '@/lib/googleSheets'
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const state = req.query.state as string | undefined
|
const state = req.query.state as string | undefined
|
||||||
if (!state) return badRequest(res)
|
if (!state) return badRequest(res)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@typebot.io/lib/api'
|
} from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const workspaceId = req.query.workspaceId as string | undefined
|
const workspaceId = req.query.workspaceId as string | undefined
|
||||||
if (!workspaceId) return badRequest(res)
|
if (!workspaceId) return badRequest(res)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { got } from 'got'
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const workspaceId = req.query.workspaceId as string | undefined
|
const workspaceId = req.query.workspaceId as string | undefined
|
||||||
if (!workspaceId) return badRequest(res)
|
if (!workspaceId) return badRequest(res)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
const parentFolderId = req.query.parentId
|
const parentFolderId = req.query.parentId
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
const id = req.query.id as string
|
const id = req.query.id as string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { notAuthenticated } from '@typebot.io/lib/api'
|
|||||||
import { SmtpCredentials } from '@typebot.io/schemas'
|
import { SmtpCredentials } from '@typebot.io/schemas'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const { from, port, isTlsEnabled, username, password, host, to } = (
|
const { from, port, isTlsEnabled, username, password, host, to } = (
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { setUser } from '@sentry/nextjs'
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
setUser({ email: user.email ?? undefined, id: user.id })
|
setUser({ email: user.email ?? undefined, id: user.id })
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { setUser } from '@sentry/nextjs'
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
setUser({ email: user.email ?? undefined, id: user.id })
|
setUser({ email: user.email ?? undefined, id: user.id })
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
|||||||
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUser'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const publicId = req.query.publicId as string | undefined
|
const publicId = req.query.publicId as string | undefined
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
try {
|
try {
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
const id = req.query.id as string
|
const id = req.query.id as string
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const handler = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*')
|
res.setHeader('Access-Control-Allow-Origin', '*')
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import Stripe from 'stripe'
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const session = await createCheckoutSession(user.id)
|
const session = await createCheckoutSession(user.id)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { omit } from '@typebot.io/lib'
|
|||||||
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
try {
|
try {
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { isReadTypebotForbidden } from '@/features/typebot/helpers/isReadTypebot
|
|||||||
import { removeTypebotOldProperties } from '@/features/typebot/helpers/removeTypebotOldProperties'
|
import { removeTypebotOldProperties } from '@/features/typebot/helpers/removeTypebotOldProperties'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { canReadTypebots } from '@/helpers/databaseRules'
|
import { canReadTypebots } from '@/helpers/databaseRules'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
} from '@typebot.io/lib/api'
|
} from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
const userId = req.query.userId as string
|
const userId = req.query.userId as string
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { env } from '@typebot.io/lib'
|
|||||||
import { sendGuestInvitationEmail } from '@typebot.io/emails'
|
import { sendGuestInvitationEmail } from '@typebot.io/emails'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const typebotId = req.query.typebotId as string | undefined
|
const typebotId = req.query.typebotId as string | undefined
|
||||||
if (!typebotId) return badRequest(res)
|
if (!typebotId) return badRequest(res)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
const email = req.query.email as string
|
const email = req.query.email as string
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
import { getTypebot } from '@/features/typebot/helpers/getTypebot'
|
import { getTypebot } from '@/features/typebot/helpers/getTypebot'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { getTypebot } from '@/features/typebot/helpers/getTypebot'
|
|||||||
import { omit } from '@typebot.io/lib'
|
import { omit } from '@typebot.io/lib'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
const webhookId = req.query.webhookId as string
|
const webhookId = req.query.webhookId as string
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
|||||||
import { User } from '@typebot.io/prisma'
|
import { User } from '@typebot.io/prisma'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
const id = req.query.userId as string
|
const id = req.query.userId as string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { generateId } from '@typebot.io/lib'
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const apiTokens = await prisma.apiToken.findMany({
|
const apiTokens = await prisma.apiToken.findMany({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
|
|
||||||
if (req.method === 'DELETE') {
|
if (req.method === 'DELETE') {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { env } from '@typebot.io/lib'
|
|||||||
import { isSeatsLimitReached } from '@typebot.io/lib/pricing'
|
import { isSeatsLimitReached } from '@typebot.io/lib/pricing'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const data = req.body as Omit<WorkspaceInvitation, 'id' | 'createdAt'>
|
const data = req.body as Omit<WorkspaceInvitation, 'id' | 'createdAt'>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'PATCH') {
|
if (req.method === 'PATCH') {
|
||||||
const data = req.body as Omit<WorkspaceInvitation, 'createdAt'>
|
const data = req.body as Omit<WorkspaceInvitation, 'createdAt'>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '@typebot.io/lib/api'
|
} from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const id = req.query.workspaceId as string
|
const id = req.query.workspaceId as string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { getAuthenticatedUser } from '@/features/auth/helpers/getAuthenticatedUs
|
|||||||
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
import { methodNotAllowed, notAuthenticated } from '@typebot.io/lib/api'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req, res)
|
||||||
if (!user) return notAuthenticated(res)
|
if (!user) return notAuthenticated(res)
|
||||||
if (req.method === 'PATCH') {
|
if (req.method === 'PATCH') {
|
||||||
const workspaceId = req.query.workspaceId as string
|
const workspaceId = req.query.workspaceId as string
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { getSession } from 'next-auth/react'
|
import { GetServerSidePropsContext } from 'next'
|
||||||
import { NextPageContext } from 'next'
|
|
||||||
import { User } from '@typebot.io/prisma'
|
import { User } from '@typebot.io/prisma'
|
||||||
import { isNotDefined } from '@typebot.io/lib'
|
import { isNotDefined } from '@typebot.io/lib'
|
||||||
import { sign } from 'jsonwebtoken'
|
import { sign } from 'jsonwebtoken'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from './api/auth/[...nextauth]'
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps(context: NextPageContext) {
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||||
const session = await getSession(context)
|
const session = await getServerSession(context.req, context.res, authOptions)
|
||||||
if (isNotDefined(session?.user))
|
if (isNotDefined(session?.user))
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { getSession } from 'next-auth/react'
|
import { getServerSession } from 'next-auth'
|
||||||
import { NextPageContext } from 'next'
|
|
||||||
import { User } from '@typebot.io/prisma'
|
import { User } from '@typebot.io/prisma'
|
||||||
import { isNotDefined } from '@typebot.io/lib'
|
import { isNotDefined } from '@typebot.io/lib'
|
||||||
import { sign } from 'jsonwebtoken'
|
import { sign } from 'jsonwebtoken'
|
||||||
|
import { authOptions } from '../api/auth/[...nextauth]'
|
||||||
|
import { GetServerSidePropsContext } from 'next'
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps(context: NextPageContext) {
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||||
const session = await getSession(context)
|
const session = await getServerSession(context.req, context.res, authOptions)
|
||||||
const feedbackId = context.query.feedbackId?.toString() as string
|
const feedbackId = context.query.feedbackId?.toString() as string
|
||||||
if (isNotDefined(session?.user))
|
if (isNotDefined(session?.user))
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { getLocaleProps } from '@/locales'
|
import { getLocaleProps } from '@/locales'
|
||||||
import { GetServerSidePropsContext } from 'next'
|
import { GetServerSidePropsContext } from 'next'
|
||||||
import { getSession } from 'next-auth/react'
|
import { getServerSession } from 'next-auth'
|
||||||
|
import { authOptions } from './api/auth/[...nextauth]'
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return null
|
return null
|
||||||
@@ -8,7 +9,11 @@ export default function Page() {
|
|||||||
|
|
||||||
export const getServerSideProps = getLocaleProps(
|
export const getServerSideProps = getLocaleProps(
|
||||||
async (context: GetServerSidePropsContext) => {
|
async (context: GetServerSidePropsContext) => {
|
||||||
const session = await getSession(context)
|
const session = await getServerSession(
|
||||||
|
context.req,
|
||||||
|
context.res,
|
||||||
|
authOptions
|
||||||
|
)
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
Reference in New Issue
Block a user