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
3 changes: 2 additions & 1 deletion playground/docus/content/2.studio/2.setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export default defineNuxtConfig({
owner: 'your-username', // your GitHub username or organization
repo: 'your-repo', // your repository name
branch: 'main', // the branch to commit to
rootDir: '' // optional: if your Nuxt app is in a subdirectory
rootDir: '', // optional: if your Nuxt app is in a subdirectory
private: true // optional: whether the repository is private or public (default: true)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions playground/docus/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineNuxtConfig({
repo: 'studio',
branch: 'main',
rootDir: 'playground/docus',
private: false,
},
},
})
9 changes: 9 additions & 0 deletions src/module/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ interface ModuleOptions {
* @default ''
*/
rootDir?: string
/**
* Whether the repository is private or public.
* If set to false, the 'public_repo' scope will be used instead of the 'repo' scope.
* @default true
*/
private?: boolean
}
/**
* Enable Nuxt Studio to edit content and media files on your filesystem.
Expand Down Expand Up @@ -89,6 +95,7 @@ export default defineNuxtModule<ModuleOptions>({
repo: '',
branch: 'main',
rootDir: '',
private: true,
},
auth: {
github: {
Expand Down Expand Up @@ -140,6 +147,8 @@ export default defineNuxtModule<ModuleOptions>({
// @ts-expect-error todo fix github type issue
github: options.auth?.github,
},
// @ts-expect-error Autogenerated type does not match with options
repository: options.repository,
}

addPlugin(process.env.STUDIO_DEV_SERVER
Expand Down
7 changes: 4 additions & 3 deletions src/module/src/runtime/server/routes/auth/github.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ interface RequestAccessTokenOptions {
}

export default eventHandler(async (event: H3Event) => {
const config = defu(useRuntimeConfig(event).studio?.auth?.github, {
const studioConfig = useRuntimeConfig(event).studio
const config = defu(studioConfig?.auth?.github, {
clientId: process.env.STUDIO_GITHUB_CLIENT_ID,
clientSecret: process.env.STUDIO_GITHUB_CLIENT_SECRET,
authorizationURL: 'https://github.com/login/oauth/authorize',
Expand Down Expand Up @@ -117,8 +118,8 @@ export default eventHandler(async (event: H3Event) => {
if (config.emailRequired && !config.scope.includes('user:email')) {
config.scope.push('user:email')
}
if (config.emailRequired && !config.scope.includes('repo')) {
config.scope.push('repo')
if (config.emailRequired && !config.scope.includes('repo') && !config.scope.includes('public_repo')) {
config.scope.push(studioConfig.repository.private ? 'repo' : 'public_repo')
}

return sendRedirect(
Expand Down
Loading