d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
127 lines
3.3 KiB
TypeScript
127 lines
3.3 KiB
TypeScript
'use client'
|
|
|
|
import { type ReactNode, useState } from 'react'
|
|
import { Chip, cn } from '@sim/emcn'
|
|
import { createLogger } from '@sim/logger'
|
|
import { getErrorMessage } from '@sim/utils/errors'
|
|
import { GithubIcon, GoogleIcon, MicrosoftIcon } from '@/components/icons'
|
|
import { client } from '@/lib/auth/auth-client'
|
|
import { AUTH_BUTTON_CLASS } from '@/app/(auth)/components/constants'
|
|
|
|
const logger = createLogger('SocialLoginButtons')
|
|
|
|
interface SocialLoginButtonsProps {
|
|
githubAvailable: boolean
|
|
googleAvailable: boolean
|
|
microsoftAvailable: boolean
|
|
callbackURL?: string
|
|
isProduction: boolean
|
|
children?: ReactNode
|
|
}
|
|
|
|
export function SocialLoginButtons({
|
|
githubAvailable,
|
|
googleAvailable,
|
|
microsoftAvailable,
|
|
callbackURL = '/workspace',
|
|
isProduction,
|
|
children,
|
|
}: SocialLoginButtonsProps) {
|
|
const [isGithubLoading, setIsGithubLoading] = useState(false)
|
|
const [isGoogleLoading, setIsGoogleLoading] = useState(false)
|
|
const [isMicrosoftLoading, setIsMicrosoftLoading] = useState(false)
|
|
|
|
async function signInWithGithub() {
|
|
if (!githubAvailable) return
|
|
|
|
setIsGithubLoading(true)
|
|
try {
|
|
await client.signIn.social({ provider: 'github', callbackURL })
|
|
} catch (err) {
|
|
logger.error('GitHub sign-in failed', { error: getErrorMessage(err) })
|
|
} finally {
|
|
setIsGithubLoading(false)
|
|
}
|
|
}
|
|
|
|
async function signInWithGoogle() {
|
|
if (!googleAvailable) return
|
|
|
|
setIsGoogleLoading(true)
|
|
try {
|
|
await client.signIn.social({ provider: 'google', callbackURL })
|
|
} catch (err) {
|
|
logger.error('Google sign-in failed', { error: getErrorMessage(err) })
|
|
} finally {
|
|
setIsGoogleLoading(false)
|
|
}
|
|
}
|
|
|
|
async function signInWithMicrosoft() {
|
|
if (!microsoftAvailable) return
|
|
|
|
setIsMicrosoftLoading(true)
|
|
try {
|
|
await client.signIn.social({ provider: 'microsoft', callbackURL })
|
|
} catch (err) {
|
|
logger.error('Microsoft sign-in failed', { error: getErrorMessage(err) })
|
|
} finally {
|
|
setIsMicrosoftLoading(false)
|
|
}
|
|
}
|
|
|
|
const githubButton = (
|
|
<Chip
|
|
fullWidth
|
|
flush
|
|
leftIcon={GithubIcon}
|
|
className={cn(AUTH_BUTTON_CLASS, 'border border-[var(--border-1)]')}
|
|
disabled={!githubAvailable || isGithubLoading}
|
|
onClick={signInWithGithub}
|
|
>
|
|
{isGithubLoading ? 'Connecting…' : 'GitHub'}
|
|
</Chip>
|
|
)
|
|
|
|
const googleButton = (
|
|
<Chip
|
|
fullWidth
|
|
flush
|
|
leftIcon={GoogleIcon}
|
|
className={cn(AUTH_BUTTON_CLASS, 'border border-[var(--border-1)]')}
|
|
disabled={!googleAvailable || isGoogleLoading}
|
|
onClick={signInWithGoogle}
|
|
>
|
|
{isGoogleLoading ? 'Connecting…' : 'Google'}
|
|
</Chip>
|
|
)
|
|
|
|
const microsoftButton = (
|
|
<Chip
|
|
fullWidth
|
|
flush
|
|
leftIcon={MicrosoftIcon}
|
|
className={cn(AUTH_BUTTON_CLASS, 'border border-[var(--border-1)]')}
|
|
disabled={!microsoftAvailable || isMicrosoftLoading}
|
|
onClick={signInWithMicrosoft}
|
|
>
|
|
{isMicrosoftLoading ? 'Connecting…' : 'Microsoft'}
|
|
</Chip>
|
|
)
|
|
|
|
const hasAnyOAuthProvider = githubAvailable || googleAvailable || microsoftAvailable
|
|
|
|
if (!hasAnyOAuthProvider && !children) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<div className='grid gap-3'>
|
|
{googleAvailable && googleButton}
|
|
{microsoftAvailable && microsoftButton}
|
|
{githubAvailable && githubButton}
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|