Skip to content

Commit

Permalink
build: ♿️ Improve feedback redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 7, 2022
1 parent 7f82604 commit 1bcc8ae
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions apps/builder/pages/feedback/[feedbackId].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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)
const feedbackId = context.query.feedbackId?.toString() as string
if (isNotDefined(session?.user))
return {
redirect: {
permanent: false,
destination: `/signin?redirectPath=%2Ffeedback%2F${feedbackId}`,
},
}
const sleekplanToken = createSSOToken(session?.user as User)
return {
redirect: {
permanent: false,
destination: `https://feedback.typebot.io/feedback/${feedbackId}/?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

2 comments on commit 1bcc8ae

@vercel
Copy link

@vercel vercel bot commented on 1bcc8ae Mar 7, 2022

@vercel
Copy link

@vercel vercel bot commented on 1bcc8ae Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.