feat: ♿️ Add sleekplan paths
This commit is contained in:
@ -20,7 +20,7 @@ import { SupportBubble } from 'components/shared/SupportBubble'
|
|||||||
|
|
||||||
if (process.env.NEXT_PUBLIC_E2E_TEST === 'enabled') enableMocks()
|
if (process.env.NEXT_PUBLIC_E2E_TEST === 'enabled') enableMocks()
|
||||||
|
|
||||||
const App = ({ Component, pageProps }: AppProps) => {
|
const App = ({ Component, pageProps: { session, ...pageProps } }: AppProps) => {
|
||||||
useRouterProgressBar()
|
useRouterProgressBar()
|
||||||
const { query } = useRouter()
|
const { query } = useRouter()
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ const App = ({ Component, pageProps }: AppProps) => {
|
|||||||
return (
|
return (
|
||||||
<ChakraProvider theme={customTheme}>
|
<ChakraProvider theme={customTheme}>
|
||||||
<KBarProvider actions={actions}>
|
<KBarProvider actions={actions}>
|
||||||
<SessionProvider>
|
<SessionProvider session={session}>
|
||||||
<UserContext>
|
<UserContext>
|
||||||
{typebotId ? (
|
{typebotId ? (
|
||||||
<TypebotContext typebotId={typebotId}>
|
<TypebotContext typebotId={typebotId}>
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
import { withSentry } from '@sentry/nextjs'
|
|
||||||
import { User } from 'db'
|
|
||||||
import { sign } from 'jsonwebtoken'
|
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { getAuthenticatedUser } from 'services/api/utils'
|
|
||||||
import { methodNotAllowed, notAuthenticated } from 'utils'
|
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
||||||
if (req.method === 'GET') {
|
|
||||||
const user = await getAuthenticatedUser(req)
|
|
||||||
if (!user) return notAuthenticated(res)
|
|
||||||
const ssoToken = createSSOToken(user)
|
|
||||||
res.redirect(`https://feedback.typebot.io?sso=${ssoToken}`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
methodNotAllowed(res)
|
|
||||||
}
|
|
||||||
|
|
||||||
const createSSOToken = (user: User) => {
|
|
||||||
if (!process.env.SLEEKPLAN_SSO_KEY) return
|
|
||||||
const userData = {
|
|
||||||
mail: user.email,
|
|
||||||
id: user.id,
|
|
||||||
name: user.name,
|
|
||||||
img: user.image,
|
|
||||||
}
|
|
||||||
|
|
||||||
return sign(userData, process.env.SLEEKPLAN_SSO_KEY, { algorithm: 'HS256' })
|
|
||||||
}
|
|
||||||
|
|
||||||
export default withSentry(handler)
|
|
41
apps/builder/pages/feedback.tsx
Normal file
41
apps/builder/pages/feedback.tsx
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { getSession } from 'next-auth/react'
|
||||||
|
import { NextPageContext } from 'next'
|
||||||
|
import { User } from 'db'
|
||||||
|
import { isNotDefined } from 'utils'
|
||||||
|
import { sign } from 'jsonwebtoken'
|
||||||
|
|
||||||
|
const FeedbackPage = () => {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getServerSideProps(context: NextPageContext) {
|
||||||
|
const session = await getSession(context)
|
||||||
|
if (isNotDefined(session?.user))
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: false,
|
||||||
|
destination: `/signin?redirectPath=%2Ffeedback`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const sleekplanToken = createSSOToken(session?.user as User)
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: false,
|
||||||
|
destination: `https://feedback.typebot.io?sso=${sleekplanToken}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const createSSOToken = (user: User) => {
|
||||||
|
if (!process.env.SLEEKPLAN_SSO_KEY) return
|
||||||
|
const userData = {
|
||||||
|
mail: user.email,
|
||||||
|
id: user.id,
|
||||||
|
name: user.name,
|
||||||
|
img: user.image,
|
||||||
|
}
|
||||||
|
|
||||||
|
return sign(userData, process.env.SLEEKPLAN_SSO_KEY, { algorithm: 'HS256' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FeedbackPage
|
@ -10,10 +10,11 @@ import { Spinner, useToast } from '@chakra-ui/react'
|
|||||||
import { pay } from 'services/stripe'
|
import { pay } from 'services/stripe'
|
||||||
import { useUser } from 'contexts/UserContext'
|
import { useUser } from 'contexts/UserContext'
|
||||||
import { Banner } from 'components/dashboard/annoucements/AnnoucementBanner'
|
import { Banner } from 'components/dashboard/annoucements/AnnoucementBanner'
|
||||||
|
import { NextPageContext } from 'next/types'
|
||||||
|
|
||||||
const DashboardPage = () => {
|
const DashboardPage = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const { query, isReady, push } = useRouter()
|
const { query, isReady } = useRouter()
|
||||||
const { user } = useUser()
|
const { user } = useUser()
|
||||||
const toast = useToast({
|
const toast = useToast({
|
||||||
position: 'top-right',
|
position: 'top-right',
|
||||||
@ -35,14 +36,7 @@ const DashboardPage = () => {
|
|||||||
if (!isReady) return
|
if (!isReady) return
|
||||||
const couponCode = query.coupon?.toString()
|
const couponCode = query.coupon?.toString()
|
||||||
const stripeStatus = query.stripe?.toString()
|
const stripeStatus = query.stripe?.toString()
|
||||||
const sleekplan = query.sleekplan?.toString()
|
|
||||||
const redirectPath = query.redirectPath as string | undefined
|
|
||||||
|
|
||||||
if (sleekplan) {
|
|
||||||
setIsLoading(true)
|
|
||||||
push('/api/auth/sleekplan')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (stripeStatus === 'success')
|
if (stripeStatus === 'success')
|
||||||
toast({
|
toast({
|
||||||
title: 'Typebot Pro',
|
title: 'Typebot Pro',
|
||||||
@ -54,7 +48,6 @@ const DashboardPage = () => {
|
|||||||
location.href = '/typebots'
|
location.href = '/typebots'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (redirectPath) push(redirectPath)
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [isReady])
|
}, [isReady])
|
||||||
|
|
||||||
@ -84,4 +77,16 @@ const DashboardPage = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getServerSideProps(context: NextPageContext) {
|
||||||
|
const redirectPath = context.query.redirectPath?.toString()
|
||||||
|
return redirectPath
|
||||||
|
? {
|
||||||
|
redirect: {
|
||||||
|
permanent: false,
|
||||||
|
destination: redirectPath,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: { props: {} }
|
||||||
|
}
|
||||||
|
|
||||||
export default DashboardPage
|
export default DashboardPage
|
||||||
|
Reference in New Issue
Block a user