Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checks.state agument is missing in production azure-ad #106

Open
markjkaem opened this issue May 23, 2023 · 0 comments
Open

checks.state agument is missing in production azure-ad #106

markjkaem opened this issue May 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@markjkaem
Copy link

markjkaem commented May 23, 2023

Environment

- Operating System: Windows_NT`

  • Node Version: v16.19.0
  • Nuxt Version: 3.1.1
  • Nitro Version: 2.1.1
  • Package Manager: pnpm@8.3.1
  • Builder: vite
  • User Config: routeRules, nitro, css, modules, auth, unocss, app
  • Runtime Modules: @unocss/nuxt@0.49.2, @pinia/nuxt@0.4.6, @vueuse/nuxt@9.13.0, @sidebase/nuxt-auth@0.6.0-beta.2, nuxt-icon@0.3.2
  • Build Modules: `-``

Reproduction

My server/api/auth/[...].ts

`import { NuxtAuthHandler } from '#auth'
import AzureADProvider from 'next-auth/providers/azure-ad'

export default NuxtAuthHandler({
pages: {
// Change the default behavior to use /login as the path for the sign-in page
signIn: '/login',
},
secret: process.env.AUTH_SECRET,

providers: [
    // @ts-expect-error You need to use .default here for it to work during SSR. May be fixed via Vite at some point
    AzureADProvider.default({
        clientId: process.env.AZURE_AD_CLIENT_ID,
        clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
        tenantId: process.env.AZURE_AD_TENANT_ID,
    }),
],

})
`

nuxt.config.ts

auth: { baseURL: '/api/auth', globalAppMiddleware: { isEnabled: false, }, isEnabled: true, provider: { type: 'authjs', defaultProvider: 'azure-ad', trustHost: true, }, },

middleware/auth.ts

`export default defineNuxtRouteMiddleware(async (route) => {
const { data } = useAuth()

const user = data.value?.user
if (!user?.email && route.path.includes('/')) {
    return navigateTo('/login')
}

})
`

Describe the bug

nitro] [dev] [unhandledRejection] Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client [next-auth][error][OAUTH_CALLBACK_ERROR] https://next-auth.js.org/errors#oauth_callback_error checks.state argument is missing { error: TypeError: checks.state argument is missing at Client.callback (C:\Users\m.teekens\sandb\validation\cash-statement\.output\server\node_modules\openid-client\lib\client.js:387:13) at oAuthCallback (C:\Users\m.teekens\sandb\validation\cash-statement\.output\server\node_modules\next-auth\core\lib\oauth\callback.js:127:29) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Object.callback (C:\Users\m.teekens\sandb\validation\cash-statement\.output\server\node_modules\next-auth\core\routes\callback.js:52:11) at async AuthHandler (C:\Users\m.teekens\sandb\validation\cash-statement\.output\server\node_modules\next-auth\core\index.js:201:28) at async file:///C:/Users/m.teekens/sandb/validation/cash-statement/.output/server/chunks/node-server.mjs:430:24 at async Object.handler (file:///C:/Users/m.teekens/sandb/validation/cash-statement/.output/server/node_modules/h3/dist/index.mjs:840:19) at async Server.toNodeHandle (file:///C:/Users/m.teekens/sandb/validation/cash-statement/.output/server/node_modules/h3/dist/index.mjs:915:7) { name: 'OAuthCallbackError', code: undefined }, providerId: 'azure-ad', message: 'checks.state argument is missing' }

Additional context

I'm using a custom middleware, if i remove the custom middleware i get a headers don't exist error.
I used github before, and that worked with the same setup

Logs

No response

@markjkaem markjkaem added the bug Something isn't working label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant