@@ -42,6 +42,7 @@ export default async function AdminPage() {
4242 let hasApiError = false
4343 let orgs : Awaited < ReturnType < typeof getOrganizations > > = [ ]
4444 let installedOrgsCount = 0
45+ const installLink = getInstallLink ( "/admin" )
4546
4647 try {
4748 const allOrgs = await getOrganizations ( )
@@ -51,8 +52,13 @@ export default async function AdminPage() {
5152 hasApiError = true
5253 }
5354
54- if ( ! hasApiError && orgs . length === 0 && installedOrgsCount === 0 ) {
55- redirect ( "/api/github/install?returnTo=%2Fadmin" )
55+ if (
56+ ! hasApiError &&
57+ orgs . length === 0 &&
58+ installedOrgsCount === 0 &&
59+ installLink . autoRedirectHref
60+ ) {
61+ redirect ( installLink . autoRedirectHref )
5662 }
5763
5864 const hasInstalledOrgs = installedOrgsCount > 0
@@ -69,12 +75,12 @@ export default async function AdminPage() {
6975 Manage CLAs for your GitHub organizations and personal accounts.
7076 </ p >
7177 </ div >
72- < Link href = "/api/github/install?returnTo=%2Fadmin" >
78+ < a href = { installLink . href } >
7379 < Button className = "gap-2" >
7480 < Plus className = "h-4 w-4" />
7581 Install on GitHub Account
7682 </ Button >
77- </ Link >
83+ </ a >
7884 </ div >
7985
8086 { hasApiError ? (
@@ -123,12 +129,12 @@ export default async function AdminPage() {
123129 ? "We found an installation, but your account is not recognized as an admin for any installed GitHub account."
124130 : "Install the CLA Bot GitHub App on your organization or personal account to get started." }
125131 </ p >
126- < Link href = "/api/github/install?returnTo=%2Fadmin" >
132+ < a href = { installLink . href } >
127133 < Button className = "gap-2" >
128134 < Github className = "h-4 w-4" />
129135 Install GitHub App
130136 </ Button >
131- </ Link >
137+ </ a >
132138 </ CardContent >
133139 </ Card >
134140 ) : (
@@ -194,3 +200,22 @@ export default async function AdminPage() {
194200 </ div >
195201 )
196202}
203+
204+ function getInstallLink ( returnTo : string ) {
205+ const fallback = `/api/github/install?returnTo=${ encodeURIComponent ( returnTo ) } `
206+ const appSlug = process . env . GITHUB_APP_SLUG ?. trim ( )
207+ if ( ! appSlug ) {
208+ return {
209+ href : fallback ,
210+ autoRedirectHref : null ,
211+ }
212+ }
213+
214+ const installUrl = new URL ( `https://github.com/apps/${ appSlug } /installations/new` )
215+ installUrl . searchParams . set ( "state" , returnTo )
216+
217+ return {
218+ href : installUrl . toString ( ) ,
219+ autoRedirectHref : installUrl . toString ( ) ,
220+ }
221+ }
0 commit comments