kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
252600602b
commit
571329c2ae
|
@ -1,10 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import { assert } from '@agentic/platform-core'
|
||||
import { redirect, RedirectType, useSearchParams } from 'next/navigation'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
||||
import { SuccessPage } from './success-page'
|
||||
|
||||
export default async function Page({
|
||||
params
|
||||
|
@ -16,46 +12,3 @@ export default async function Page({
|
|||
|
||||
return <SuccessPage provider={provider} />
|
||||
}
|
||||
|
||||
function SuccessPage({
|
||||
provider:
|
||||
// TODO
|
||||
_provider
|
||||
}: {
|
||||
provider: string
|
||||
}) {
|
||||
const searchParams = useSearchParams()
|
||||
const code = searchParams.get('code')
|
||||
const ctx = useUnauthenticatedAgentic()
|
||||
|
||||
useEffect(() => {
|
||||
;(async function () {
|
||||
if (!code) {
|
||||
// TODO
|
||||
throw new Error('Missing code or challenge')
|
||||
}
|
||||
|
||||
if (!ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: make generic using `provider`
|
||||
try {
|
||||
const authSession = await ctx.api.exchangeOAuthCodeWithGitHub({
|
||||
code
|
||||
})
|
||||
|
||||
console.log('AUTH SUCCESS', { authSession })
|
||||
} catch (err) {
|
||||
console.error('AUTH ERROR', err)
|
||||
|
||||
return redirect('/login', RedirectType.replace)
|
||||
}
|
||||
|
||||
return redirect('/app', RedirectType.replace)
|
||||
})()
|
||||
}, [code, ctx])
|
||||
|
||||
// TODO: show a loading state
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
'use client'
|
||||
|
||||
import { redirect, RedirectType, useSearchParams } from 'next/navigation'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
import { useUnauthenticatedAgentic } from '@/components/agentic-provider'
|
||||
|
||||
export function SuccessPage({
|
||||
provider:
|
||||
// TODO
|
||||
_provider
|
||||
}: {
|
||||
provider: string
|
||||
}) {
|
||||
const searchParams = useSearchParams()
|
||||
const code = searchParams.get('code')
|
||||
const ctx = useUnauthenticatedAgentic()
|
||||
|
||||
useEffect(() => {
|
||||
;(async function () {
|
||||
if (!code) {
|
||||
// TODO
|
||||
throw new Error('Missing code or challenge')
|
||||
}
|
||||
|
||||
if (!ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: make generic using `provider`
|
||||
try {
|
||||
const authSession = await ctx.api.exchangeOAuthCodeWithGitHub({
|
||||
code
|
||||
})
|
||||
|
||||
console.log('AUTH SUCCESS', { authSession })
|
||||
} catch (err) {
|
||||
console.error('AUTH ERROR', err)
|
||||
|
||||
return redirect('/login', RedirectType.replace)
|
||||
}
|
||||
|
||||
return redirect('/app', RedirectType.replace)
|
||||
})()
|
||||
}, [code, ctx])
|
||||
|
||||
// TODO: show a loading state
|
||||
return null
|
||||
}
|
Ładowanie…
Reference in New Issue