Skip to content

Commit

Permalink
build(signin): ♿️ Add SSO signin for Sleekplan
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 7, 2022
1 parent 0710403 commit 57663fd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"htmlparser2": "^7.2.0",
"immer": "^9.0.12",
"js-video-url-parser": "^0.5.1",
"jsonwebtoken": "^8.5.1",
"kbar": "^0.1.0-beta.27",
"micro": "^9.3.4",
"micro-cors": "^0.1.1",
Expand Down Expand Up @@ -84,6 +85,7 @@
"devDependencies": {
"@playwright/test": "^1.19.0",
"@types/google-spreadsheet": "^3.1.5",
"@types/jsonwebtoken": "8.5.1",
"@types/micro-cors": "^0.1.2",
"@types/minio": "^7.0.12",
"@types/node": "^17.0.17",
Expand Down
31 changes: 31 additions & 0 deletions apps/builder/pages/api/auth/sleekplan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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)
13 changes: 10 additions & 3 deletions apps/builder/pages/typebots.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { Flex, Link, Stack, Text } from '@chakra-ui/layout'
import { Link, Stack, Text, VStack } from '@chakra-ui/layout'
import { DashboardHeader } from 'components/dashboard/DashboardHeader'
import { Seo } from 'components/Seo'
import { FolderContent } from 'components/dashboard/FolderContent'
Expand Down Expand Up @@ -35,8 +35,14 @@ 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',
Expand Down Expand Up @@ -66,9 +72,10 @@ const DashboardPage = () => {
<DashboardHeader />
<TypebotDndContext>
{isLoading ? (
<Flex w="full" justifyContent="center" pt="10">
<VStack w="full" justifyContent="center" pt="10" spacing={6}>
<Text>You are being redirected...</Text>
<Spinner />
</Flex>
</VStack>
) : (
<FolderContent folder={null} />
)}
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,13 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=

"@types/jsonwebtoken@8.5.1":
version "8.5.1"
resolved "https://registry.yarnpkg.com/@types/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#56958cb2d80f6d74352bd2e501a018e2506a8a84"
integrity sha512-rNAPdomlIUX0i0cg2+I+Q1wOUr531zHBQ+cV/28PJ39bSPKjahatZZ2LMuhiguETkCgLVzfruw/ZvNMNkKoSzw==
dependencies:
"@types/node" "*"

"@types/keyv@*":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.3.tgz#1c9aae32872ec1f20dcdaee89a9f3ba88f465e41"
Expand Down

2 comments on commit 57663fd

@vercel
Copy link

@vercel vercel bot commented on 57663fd 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

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

@vercel
Copy link

@vercel vercel bot commented on 57663fd Mar 7, 2022

Please sign in to comment.