Skip to content

Commit 5a40a43

Browse files
authored
feat(oauth): add repository.private option for public repos (#49)
1 parent 1d249a3 commit 5a40a43

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

playground/docus/content/2.studio/2.setup.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export default defineNuxtConfig({
6363
owner: 'your-username', // your GitHub username or organization
6464
repo: 'your-repo', // your repository name
6565
branch: 'main', // the branch to commit to
66-
rootDir: '' // optional: if your Nuxt app is in a subdirectory
66+
rootDir: '', // optional: if your Nuxt app is in a subdirectory
67+
private: true // optional: whether the repository is private or public (default: true)
6768
}
6869
}
6970
})

playground/docus/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default defineNuxtConfig({
1919
repo: 'studio',
2020
branch: 'main',
2121
rootDir: 'playground/docus',
22+
private: false,
2223
},
2324
},
2425
})

src/module/src/module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ interface ModuleOptions {
6262
* @default ''
6363
*/
6464
rootDir?: string
65+
/**
66+
* Whether the repository is private or public.
67+
* If set to false, the 'public_repo' scope will be used instead of the 'repo' scope.
68+
* @default true
69+
*/
70+
private?: boolean
6571
}
6672
/**
6773
* Enable Nuxt Studio to edit content and media files on your filesystem.
@@ -89,6 +95,7 @@ export default defineNuxtModule<ModuleOptions>({
8995
repo: '',
9096
branch: 'main',
9197
rootDir: '',
98+
private: true,
9299
},
93100
auth: {
94101
github: {
@@ -140,6 +147,8 @@ export default defineNuxtModule<ModuleOptions>({
140147
// @ts-expect-error todo fix github type issue
141148
github: options.auth?.github,
142149
},
150+
// @ts-expect-error Autogenerated type does not match with options
151+
repository: options.repository,
143152
}
144153

145154
addPlugin(process.env.STUDIO_DEV_SERVER

src/module/src/runtime/server/routes/auth/github.get.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ interface RequestAccessTokenOptions {
8080
}
8181

8282
export default eventHandler(async (event: H3Event) => {
83-
const config = defu(useRuntimeConfig(event).studio?.auth?.github, {
83+
const studioConfig = useRuntimeConfig(event).studio
84+
const config = defu(studioConfig?.auth?.github, {
8485
clientId: process.env.STUDIO_GITHUB_CLIENT_ID,
8586
clientSecret: process.env.STUDIO_GITHUB_CLIENT_SECRET,
8687
redirectURL: process.env.STUDIO_GITHUB_REDIRECT_URL,
@@ -120,8 +121,8 @@ export default eventHandler(async (event: H3Event) => {
120121
if (config.emailRequired && !config.scope.includes('user:email')) {
121122
config.scope.push('user:email')
122123
}
123-
if (config.emailRequired && !config.scope.includes('repo')) {
124-
config.scope.push('repo')
124+
if (config.emailRequired && !config.scope.includes('repo') && !config.scope.includes('public_repo')) {
125+
config.scope.push(studioConfig.repository.private ? 'repo' : 'public_repo')
125126
}
126127

127128
return sendRedirect(

0 commit comments

Comments
 (0)