File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,8 @@ const plugin: NetlifyPlugin = {
7979 console . log ( `NextAuth package detected, setting NEXTAUTH_URL environment variable to ${ process . env . URL } ` )
8080
8181 const config = await getRequiredServerFiles ( publish )
82- config . config . env . NEXTAUTH_URL = process . env . URL
82+ const nextAuthUrl = `${ process . env . URL } ${ basePath } `
83+ config . config . env . NEXTAUTH_URL = nextAuthUrl
8384
8485 await updateRequiredServerFiles ( publish , config )
8586 }
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ const {
2525 patchNextFiles,
2626 unpatchNextFiles,
2727} = require ( '../plugin/src/helpers/files' )
28- const { getRequiredServerFiles } = require ( '../plugin/src/helpers/config' )
28+ const { getRequiredServerFiles, updateRequiredServerFiles } = require ( '../plugin/src/helpers/config' )
2929const { dirname } = require ( 'path' )
3030const { getProblematicUserRewrites } = require ( '../plugin/src/helpers/verification' )
3131
@@ -241,6 +241,26 @@ describe('onBuild()', () => {
241241 delete process . env . URL
242242 } )
243243
244+ test ( 'includes the basePath on NEXTAUTH_URL when present' , async ( ) => {
245+ const mockSiteUrl = 'https://my-netlify-site.app'
246+ process . env . URL = mockSiteUrl
247+
248+ await moveNextDist ( )
249+
250+ const initialConfig = await getRequiredServerFiles ( netlifyConfig . build . publish )
251+ initialConfig . config . basePath = "/foo"
252+ await updateRequiredServerFiles ( netlifyConfig . build . publish , initialConfig )
253+
254+ await plugin . onBuild ( defaultArgs )
255+
256+ expect ( onBuildHasRun ( netlifyConfig ) ) . toBe ( true )
257+ const config = await getRequiredServerFiles ( netlifyConfig . build . publish )
258+
259+ expect ( config . config . env . NEXTAUTH_URL ) . toEqual ( `${ mockSiteUrl } /foo` )
260+
261+ delete process . env . URL
262+ } )
263+
244264 test ( 'skips setting NEXTAUTH_URL when next-auth package is not found' , async ( ) => {
245265 isNextAuthInstalled . mockImplementation ( ( ) => {
246266 return false
You can’t perform that action at this time.
0 commit comments