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()
|
||||
|
||||
const App = ({ Component, pageProps }: AppProps) => {
|
||||
const App = ({ Component, pageProps: { session, ...pageProps } }: AppProps) => {
|
||||
useRouterProgressBar()
|
||||
const { query } = useRouter()
|
||||
|
||||
@ -28,7 +28,7 @@ const App = ({ Component, pageProps }: AppProps) => {
|
||||
return (
|
||||
<ChakraProvider theme={customTheme}>
|
||||
<KBarProvider actions={actions}>
|
||||
<SessionProvider>
|
||||
<SessionProvider session={session}>
|
||||
<UserContext>
|
||||
{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 { useUser } from 'contexts/UserContext'
|
||||
import { Banner } from 'components/dashboard/annoucements/AnnoucementBanner'
|
||||
import { NextPageContext } from 'next/types'
|
||||
|
||||
const DashboardPage = () => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const { query, isReady, push } = useRouter()
|
||||
const { query, isReady } = useRouter()
|
||||
const { user } = useUser()
|
||||
const toast = useToast({
|
||||
position: 'top-right',
|
||||
@ -35,14 +36,7 @@ const DashboardPage = () => {
|
||||
if (!isReady) return
|
||||
const couponCode = query.coupon?.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')
|
||||
toast({
|
||||
title: 'Typebot Pro',
|
||||
@ -54,7 +48,6 @@ const DashboardPage = () => {
|
||||
location.href = '/typebots'
|
||||
})
|
||||
}
|
||||
if (redirectPath) push(redirectPath)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [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
|
||||
|
Reference in New Issue
Block a user