Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ NEXTAUTH_URL=""
NEXTAUTH_SECRET=""
AUTH_TRUST_HOST="true"

# GitHub OAuth (replace with your actual values)
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""
# GitHub App Configuration (Required for GitHub login)
GITHUB_APP_ID=""
GITHUB_APP_PRIVATE_KEY=""
GITHUB_APP_WEBHOOK_SECRET=""
GITHUB_APP_CLIENT_ID=""
GITHUB_APP_CLIENT_SECRET=""
NEXT_PUBLIC_GITHUB_APP_NAME=""

# GitHub OAuth (DEPRECATED - Use GitHub App instead)
# GITHUB_CLIENT_ID=""
# GITHUB_CLIENT_SECRET=""

# Sealos OAuth
SEALOS_JWT_SECRET=""
Expand All @@ -31,5 +39,5 @@ LOG_LEVEL="info"

# login
ENABLE_PASSWORD_AUTH=""
ENABLE_PASSWORD_AUTH=""
ENABLE_GITHUB_AUTH="true"
ENABLE_SEALOS_AUTH=""
2 changes: 1 addition & 1 deletion app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function LoginPage() {
</div>

<Button
onClick={() => signIn('github', { callbackUrl: '/projects' })}
onClick={() => signIn('github-app', { callbackUrl: '/projects?github_install=true' })}
className="w-full bg-secondary text-secondary-foreground hover:bg-muted rounded-md"
size="lg"
variant="outline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import { useEffect, useState } from 'react'
import { ProjectStatus } from '@prisma/client'
import { useRouter } from 'next/navigation'
import { useRouter, useSearchParams } from 'next/navigation'
import { toast } from 'sonner'

import { getInstallations } from '@/lib/actions/github'
import type { ProjectWithRelations } from '@/lib/data/project'
import { env } from '@/lib/env'

import { PageHeaderWithFilter } from './page-header-with-filter'
import { ProjectList } from './project-list'
Expand All @@ -17,7 +20,9 @@ interface HomePageContentProps {

export function HomePageContent({ projects }: HomePageContentProps) {
const router = useRouter()
const searchParams = useSearchParams()
const [activeFilter, setActiveFilter] = useState<'ALL' | ProjectStatus>('ALL')
const [hasTriggeredInstall, setHasTriggeredInstall] = useState(false)

useEffect(() => {
const interval = setInterval(() => {
Expand All @@ -27,6 +32,76 @@ export function HomePageContent({ projects }: HomePageContentProps) {
return () => clearInterval(interval)
}, [router])

useEffect(() => {
if (hasTriggeredInstall) return

const shouldTriggerInstall = searchParams.get('github_install') === 'true'
if (!shouldTriggerInstall) return

const triggerGitHubAppInstall = async () => {
setHasTriggeredInstall(true)

try {
const result = await getInstallations()
if (result.success && result.data.length > 0) {
router.replace('/projects')
return
}

const appName = env.NEXT_PUBLIC_GITHUB_APP_NAME
if (!appName) {
toast.error('GitHub App is not configured')
router.replace('/projects')
return
}

const installUrl = `https://github.com/apps/${appName}/installations/new`

const width = 800
const height = 800
const left = window.screen.width / 2 - width / 2
const top = window.screen.height / 2 - height / 2

const popup = window.open(
installUrl,
'github-app-install',
`width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
)

if (!popup) {
toast.error('Failed to open popup window. Please allow popups for this site.')
router.replace('/projects')
return
}

const handleMessage = (event: MessageEvent) => {
if (event.origin !== window.location.origin) return
if (event.data.type !== 'github-app-installed') return

window.removeEventListener('message', handleMessage)
toast.success('GitHub App installed successfully!')
router.replace('/projects')
router.refresh()
}

window.addEventListener('message', handleMessage)

const checkClosed = setInterval(() => {
if (popup.closed) {
clearInterval(checkClosed)
window.removeEventListener('message', handleMessage)
router.replace('/projects')
}
}, 500)
} catch (error) {
console.error('Failed to trigger GitHub App install:', error)
router.replace('/projects')
}
}

triggerGitHubAppInstall()
}, [searchParams, hasTriggeredInstall, router])

return (
<>
<PageHeaderWithFilter activeFilter={activeFilter} onFilterChange={setActiveFilter} />
Expand Down
224 changes: 0 additions & 224 deletions app/api/auth/github/callback/route.ts

This file was deleted.

Loading