@@ -10,12 +10,12 @@ import { useRuntimeConfig } from '#imports'
1010export interface OAuthGitHubConfig {
1111 /**
1212 * GitHub OAuth Client ID
13- * @default process.env.NUXT_OAUTH_GITHUB_CLIENT_ID
13+ * @default process.env.STUDIO_GITHUB_CLIENT_ID
1414 */
1515 clientId ?: string
1616 /**
1717 * GitHub OAuth Client Secret
18- * @default process.env.NUXT_OAUTH_GITHUB_CLIENT_SECRET
18+ * @default process.env.STUDIO_GITHUB_CLIENT_SECRET
1919 */
2020 clientSecret ?: string
2121 /**
@@ -58,8 +58,8 @@ export interface OAuthGitHubConfig {
5858
5959 /**
6060 * Redirect URL to to allow overriding for situations like prod failing to determine public hostname
61- * @default process.env.NUXT_OAUTH_GITHUB_REDIRECT_URL
62- * @see https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between- github-apps-and-oauth-apps
61+ * Use ` process.env.STUDIO_GITHUB_REDIRECT_URL` to overwrite the default redirect URL.
62+ * @default is ${hostname}/__nuxt_studio/auth/ github
6363 */
6464 redirectURL ?: string
6565}
@@ -83,6 +83,7 @@ export default eventHandler(async (event: H3Event) => {
8383 const config = defu ( useRuntimeConfig ( event ) . studio ?. auth ?. github , {
8484 clientId : process . env . STUDIO_GITHUB_CLIENT_ID ,
8585 clientSecret : process . env . STUDIO_GITHUB_CLIENT_SECRET ,
86+ redirectURL : process . env . STUDIO_GITHUB_REDIRECT_URL ,
8687 authorizationURL : 'https://github.com/login/oauth/authorize' ,
8788 tokenURL : 'https://github.com/login/oauth/access_token' ,
8889 apiURL : 'https://api.github.com' ,
@@ -109,7 +110,9 @@ export default eventHandler(async (event: H3Event) => {
109110 }
110111
111112 const requestURL = getRequestURL ( event )
112- const redirectURL = `${ requestURL . protocol } //${ requestURL . host } ${ requestURL . pathname } `
113+
114+ config . redirectURL = config . redirectURL || `${ requestURL . protocol } //${ requestURL . host } ${ requestURL . pathname } `
115+
113116 const state = await handleState ( event )
114117
115118 if ( ! query . code ) {
@@ -125,7 +128,7 @@ export default eventHandler(async (event: H3Event) => {
125128 event ,
126129 withQuery ( config . authorizationURL as string , {
127130 client_id : config . clientId ,
128- redirect_uri : redirectURL ,
131+ redirect_uri : config . redirectURL ,
129132 scope : config . scope . join ( ' ' ) ,
130133 state,
131134 ...config . authorizationParams ,
@@ -149,7 +152,7 @@ export default eventHandler(async (event: H3Event) => {
149152 grant_type : 'authorization_code' ,
150153 client_id : config . clientId ,
151154 client_secret : config . clientSecret ,
152- redirect_uri : redirectURL ,
155+ redirect_uri : config . redirectURL ,
153156 code : query . code ,
154157 } ,
155158 } )
0 commit comments