Email Callback URL Not Set Correctly in Vercel Deployment
Environment
- Operating System: Darwin
- Node Version: v21.2.0
- Nuxt Version: 3.8.2
- CLI Version: 3.10.0
- Nitro Version: 2.8.0
- Package Manager: [email protected]
- Builder: -
- User Config: modules, ui, auth, devtools
- Runtime Modules: @nuxt/[email protected], @sidebase/[email protected]
- Build Modules: -
Reproduction
N/A
Describe the bug
I've added a simple EmailProvider to use a magic link to sign in. I have no special callback handling. I have a simple app with a protected page. When I try to access this page, I correctly am redirected to the sign-in page:
https://
I use the email provider to send the default email with a link. Locally, it works and includes the callback URL properly. In my Vercel deployment, instead of the expected callback, the URL is:
https://
Then I get a 404 error on the sw.js page not found.
I'm not sure if it's related, but the documentation on AUTH_ORIGIN and baseUrl is a bit confusing. If I don't set an environment variable for AUTH_ORIGIN, the app crashes horribly. The docs state that baseUrl must include the full path, but if I include the "/api/auth" path portion along with my app URL in AUTH_ORIGIN, that causes the "/api/auth" portion to be duplicated. I've tried even hardcoding the "baseUrl" in my nuxt.config.ts file to include the /api/auth path, but it seems like it's overwritten by AUTH_ORIGIN?
nuxt.config.ts:
auth: {
isEnabled: true,
baseUrl: 'https://
export default NuxtAuthHandler({ secret: process.env.AUTH_SECRET, adapter: PrismaAdapter(prisma), providers: [ // @ts-expect-error You need to use .default here for it to work during SSR. May be fixed via Vite at some point GithubProvider.default({ clientId: process.env.GITHUB_AUTH_PROVIDER_CLIENT_ID, clientSecret: process.env.GITHUB_AUTH_PROVIDER_CLIENT_SECRET }), EmailProvider.default({ server: process.env.EMAIL_SERVER, from: process.env.EMAIL_FROM }) ], session: { strategy: 'jwt' } })
In vercel environment var:
AUTH_ORIGIN=https://
Additional context
No response
Logs
No response
Got this to work finally. Two things:
- I added typescript checking, which flagged that "baseUrl" should have been "baseURL". I set this to baseURL: AUTH_ORIGIN + "/api/auth"
- Took a while, but kind of figured out the sw.js part. I think this was a holdover from some experimental deployments with SSR set to false, then my browser had registered a service worker for that site and was making a GET request for it. Using Developer Tools (under Application) to stop and de-register the service worker made the 404 error go away, which allowed the callback URL generation to work correctly.