Skip to content

Commit

Permalink
feat: Make OAuth optional and define it at runtime of the app (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD authored Nov 11, 2024
1 parent 4921241 commit 593eae3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions apps/shelve/app/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
const { title } = useAppConfig()
const { githubEnabled, googleEnabled } = useRuntimeConfig().public
const { title, githubEnabled, googleEnabled } = useAppConfig()
definePageMeta({
layout: 'auth',
Expand Down
24 changes: 12 additions & 12 deletions apps/shelve/modules/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ export default defineNuxtModule({
name: '@shelve/auth',
},
setup(options, nuxt) {
const { resolve } = createResolver(import.meta.url)
nuxt.hook('ready', () => {
let isGithubEnabled = false
let isGoogleEnabled = false

let isGithubEnabled = false
let isGoogleEnabled = false
if (process.env.NUXT_OAUTH_GITHUB_CLIENT_ID && process.env.NUXT_OAUTH_GITHUB_CLIENT_SECRET)
isGithubEnabled = true
if (process.env.NUXT_OAUTH_GOOGLE_CLIENT_ID && process.env.NUXT_OAUTH_GOOGLE_CLIENT_SECRET)
isGoogleEnabled = true

if (process.env.NUXT_OAUTH_GITHUB_CLIENT_ID && process.env.NUXT_OAUTH_GITHUB_CLIENT_SECRET)
isGithubEnabled = true
if (process.env.NUXT_OAUTH_GOOGLE_CLIENT_ID && process.env.NUXT_OAUTH_GOOGLE_CLIENT_SECRET)
isGoogleEnabled = true
nuxt.options.appConfig.googleEnabled = isGoogleEnabled
nuxt.options.appConfig.githubEnabled = isGithubEnabled
})

nuxt.options.runtimeConfig.public.googleEnabled = isGoogleEnabled
nuxt.options.runtimeConfig.public.githubEnabled = isGithubEnabled

if (isGithubEnabled) {
/*if (isGithubEnabled) {
addServerHandler({
route: '/auth/github',
handler: resolve('./runtime/github')
Expand All @@ -30,6 +30,6 @@ export default defineNuxtModule({
route: '/auth/google',
handler: resolve('./runtime/google')
})
}
}*/
}
})
File renamed without changes.
File renamed without changes.

0 comments on commit 593eae3

Please sign in to comment.