2
0

⬆️ Upgrade dependencies

Closes #198, closes #171
This commit is contained in:
Baptiste Arnaud
2023-01-02 10:33:35 +01:00
parent b9ed50b016
commit ec7481d002
22 changed files with 992 additions and 942 deletions

View File

@ -1,4 +1,4 @@
import { IconProps, Icon } from '@chakra-ui/react'
import { IconProps, Icon, useColorModeValue } from '@chakra-ui/react'
export const featherIconsBaseProps: IconProps = {
fill: 'none',
@ -353,9 +353,13 @@ export const SendEmailIcon = (props: IconProps) => (
)
export const GithubIcon = (props: IconProps) => (
<Icon viewBox="0 0 512 512" {...props}>
<title>{'Logo Github'}</title>
<path d="M256 32C132.3 32 32 134.9 32 261.7c0 101.5 64.2 187.5 153.2 217.9a17.56 17.56 0 003.8.4c8.3 0 11.5-6.1 11.5-11.4 0-5.5-.2-19.9-.3-39.1a102.4 102.4 0 01-22.6 2.7c-43.1 0-52.9-33.5-52.9-33.5-10.2-26.5-24.9-33.6-24.9-33.6-19.5-13.7-.1-14.1 1.4-14.1h.1c22.5 2 34.3 23.8 34.3 23.8 11.2 19.6 26.2 25.1 39.6 25.1a63 63 0 0025.6-6c2-14.8 7.8-24.9 14.2-30.7-49.7-5.8-102-25.5-102-113.5 0-25.1 8.7-45.6 23-61.6-2.3-5.8-10-29.2 2.2-60.8a18.64 18.64 0 015-.5c8.1 0 26.4 3.1 56.6 24.1a208.21 208.21 0 01112.2 0c30.2-21 48.5-24.1 56.6-24.1a18.64 18.64 0 015 .5c12.2 31.6 4.5 55 2.2 60.8 14.3 16.1 23 36.6 23 61.6 0 88.2-52.4 107.6-102.3 113.3 8 7.1 15.2 21.1 15.2 42.5 0 30.7-.3 55.5-.3 63 0 5.4 3.1 11.5 11.4 11.5a19.35 19.35 0 004-.4C415.9 449.2 480 363.1 480 261.7 480 134.9 379.7 32 256 32z" />
<Icon viewBox="0 0 98 96" xmlns="http://www.w3.org/2000/svg" {...props}>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
fill={useColorModeValue('#24292f', 'white')}
/>
</Icon>
)

View File

@ -20,7 +20,6 @@ const userContext = createContext<{
isLoading: boolean
isSaving: boolean
hasUnsavedChanges: boolean
isOAuthProvider: boolean
currentWorkspaceId?: string
updateUser: (newUser: Partial<User>) => void
saveUser: (newUser?: Partial<User>) => Promise<void>
@ -36,10 +35,6 @@ export const UserProvider = ({ children }: { children: ReactNode }) => {
const [currentWorkspaceId, setCurrentWorkspaceId] = useState<string>()
const [isSaving, setIsSaving] = useState(false)
const isOAuthProvider = useMemo(
() => (session?.providerType as boolean | undefined) ?? false,
[session?.providerType]
)
const hasUnsavedChanges = useMemo(
() => !dequal(session?.user, user),
@ -97,7 +92,6 @@ export const UserProvider = ({ children }: { children: ReactNode }) => {
isSaving,
isLoading: status === 'loading',
hasUnsavedChanges,
isOAuthProvider,
currentWorkspaceId,
updateUser,
saveUser,

View File

@ -18,14 +18,7 @@ import { UploadButton } from '@/components/ImageUploadContent/UploadButton'
import { useUser } from '@/features/account'
export const MyAccountForm = () => {
const {
user,
updateUser,
saveUser,
hasUnsavedChanges,
isSaving,
isOAuthProvider,
} = useUser()
const { user, updateUser, saveUser, hasUnsavedChanges, isSaving } = useUser()
const handleFileUploaded = async (url: string) => {
updateUser({ image: url })
@ -74,12 +67,7 @@ export const MyAccountForm = () => {
hasArrow
>
<FormControl>
<FormLabel
htmlFor="email"
color={isOAuthProvider ? 'gray.500' : 'current'}
>
Email address
</FormLabel>
<FormLabel htmlFor="email">Email address</FormLabel>
<Input
id="email"
type="email"

View File

@ -76,6 +76,7 @@ export const SignInForm = ({
})
setAuthLoading(false)
}
if (isLoadingProviders) return <Spinner />
if (hasNoAuthProvider)
return (

View File

@ -7,7 +7,7 @@ import {
useSession,
} from 'next-auth/react'
import { useRouter } from 'next/router'
import React from 'react'
import React, { useState } from 'react'
import { stringify } from 'qs'
import { BuiltInProviderType } from 'next-auth/providers'
import { GoogleLogo } from '@/components/GoogleLogo'
@ -22,31 +22,28 @@ type Props = {
export const SocialLoginButtons = ({ providers }: Props) => {
const { query } = useRouter()
const { status } = useSession()
const [authLoading, setAuthLoading] =
useState<LiteralUnion<BuiltInProviderType, string>>()
const handleGitHubClick = async () =>
signIn('github', {
const handleSignIn = async (provider: string) => {
setAuthLoading(provider)
await signIn(provider, {
callbackUrl: `/typebots?${stringify(query)}`,
})
setTimeout(() => setAuthLoading(undefined), 3000)
}
const handleGoogleClick = async () =>
signIn('google', {
callbackUrl: `/typebots?${stringify(query)}`,
})
const handleGitHubClick = () => handleSignIn('github')
const handleFacebookClick = async () =>
signIn('facebook', {
callbackUrl: `/typebots?${stringify(query)}`,
})
const handleGoogleClick = () => handleSignIn('google')
const handleGitlabClick = async () =>
signIn('gitlab', {
callbackUrl: `/typebots?${stringify(query)}`,
})
const handleFacebookClick = () => handleSignIn('facebook')
const handleAzureAdClick = async () =>
signIn('azure-ad', {
callbackUrl: `/typebots?${stringify(query)}`,
})
const handleGitlabClick = () => handleSignIn('gitlab')
const handleAzureAdClick = () => handleSignIn('azure-ad')
const handleCustomOAuthClick = () => handleSignIn('custom-oauth')
return (
<Stack>
@ -55,7 +52,10 @@ export const SocialLoginButtons = ({ providers }: Props) => {
leftIcon={<GithubIcon />}
onClick={handleGitHubClick}
data-testid="github"
isLoading={['loading', 'authenticated'].includes(status)}
isLoading={
['loading', 'authenticated'].includes(status) ||
authLoading === 'github'
}
variant="outline"
>
Continue with GitHub
@ -66,7 +66,10 @@ export const SocialLoginButtons = ({ providers }: Props) => {
leftIcon={<GoogleLogo />}
onClick={handleGoogleClick}
data-testid="google"
isLoading={['loading', 'authenticated'].includes(status)}
isLoading={
['loading', 'authenticated'].includes(status) ||
authLoading === 'google'
}
variant="outline"
>
Continue with Google
@ -77,7 +80,10 @@ export const SocialLoginButtons = ({ providers }: Props) => {
leftIcon={<FacebookLogo />}
onClick={handleFacebookClick}
data-testid="facebook"
isLoading={['loading', 'authenticated'].includes(status)}
isLoading={
['loading', 'authenticated'].includes(status) ||
authLoading === 'facebook'
}
variant="outline"
>
Continue with Facebook
@ -88,7 +94,10 @@ export const SocialLoginButtons = ({ providers }: Props) => {
leftIcon={<GitlabLogo />}
onClick={handleGitlabClick}
data-testid="gitlab"
isLoading={['loading', 'authenticated'].includes(status)}
isLoading={
['loading', 'authenticated'].includes(status) ||
authLoading === 'gitlab'
}
variant="outline"
>
Continue with {providers.gitlab.name}
@ -99,7 +108,10 @@ export const SocialLoginButtons = ({ providers }: Props) => {
leftIcon={<AzureAdLogo />}
onClick={handleAzureAdClick}
data-testid="azure-ad"
isLoading={['loading', 'authenticated'].includes(status)}
isLoading={
['loading', 'authenticated'].includes(status) ||
authLoading === 'azure-ad'
}
variant="outline"
>
Continue with {providers['azure-ad'].name}
@ -107,8 +119,11 @@ export const SocialLoginButtons = ({ providers }: Props) => {
)}
{providers?.['custom-oauth'] && (
<Button
onClick={handleAzureAdClick}
isLoading={['loading', 'authenticated'].includes(status)}
onClick={handleCustomOAuthClick}
isLoading={
['loading', 'authenticated'].includes(status) ||
authLoading === 'custom-oauth'
}
variant="outline"
>
Continue with {providers['custom-oauth'].name}

View File

@ -155,8 +155,14 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
}
},
signIn: async ({ account, user }) => {
const userExists = user?.graphNavigation !== undefined
if (!account || (process.env.DISABLE_SIGNUP === 'true' && !userExists))
const userExists =
'graphNavigation' in user && user.graphNavigation !== undefined
if (
!account ||
(process.env.DISABLE_SIGNUP === 'true' &&
!userExists &&
user.email !== process.env.ADMIN_EMAIL)
)
return false
const requiredGroups = getRequiredGroups(account.provider)
if (requiredGroups.length > 0) {

View File

@ -6,6 +6,7 @@ import {
Plan,
WorkspaceRole,
WorkspaceInvitation,
Session,
} from 'db'
import type { Adapter, AdapterUser } from 'next-auth/adapters'
import cuid from 'cuid'
@ -74,19 +75,23 @@ export function CustomAdapter(p: PrismaClient): Adapter {
await convertInvitationsToCollaborations(p, user, invitations)
if (workspaceInvitations.length > 0)
await joinWorkspaces(p, user, workspaceInvitations)
return createdUser
return createdUser as AdapterUser
},
getUser: (id) => p.user.findUnique({ where: { id } }),
getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
getUser: async (id) =>
(await p.user.findUnique({ where: { id } })) as AdapterUser,
getUserByEmail: async (email) =>
(await p.user.findUnique({ where: { email } })) as AdapterUser,
async getUserByAccount(provider_providerAccountId) {
const account = await p.account.findUnique({
where: { provider_providerAccountId },
select: { user: true },
})
return account?.user ?? null
return (account?.user ?? null) as AdapterUser | null
},
updateUser: (data) => p.user.update({ where: { id: data.id }, data }),
deleteUser: (id) => p.user.delete({ where: { id } }),
updateUser: async (data) =>
(await p.user.update({ where: { id: data.id }, data })) as AdapterUser,
deleteUser: async (id) =>
(await p.user.delete({ where: { id } })) as AdapterUser,
linkAccount: async (data) => {
await p.account.create({
data: {
@ -117,7 +122,7 @@ export function CustomAdapter(p: PrismaClient): Adapter {
})
if (!userAndSession) return null
const { user, ...session } = userAndSession
return { user, session }
return { user, session } as { user: AdapterUser; session: Session }
},
createSession: (data) => p.session.create({ data }),
updateSession: (data) =>

View File

@ -30,7 +30,7 @@ export const addSubscriptionToWorkspace = async (
card: {
number: '4242424242424242',
exp_month: 12,
exp_year: 2022,
exp_year: 2024,
cvc: '123',
},
type: 'card',