Closed PlusA2M closed 3 years ago
I see it too, using Laravel Sanctum like this:
auth: {
strategies: {
cookie: {
cookie: {
name: 'XSRF-TOKEN',
},
},
laravelSanctum: {
provider: 'laravel/sanctum',
url: API_BASE_URL,
endpoints: {
login: { url: '/api/login' },
logout: { url: '/api/logout', method: 'DELETE' },
user: false,
},
},
autoFetchUser: false,
globalToken: false,
tokenRequired: false,
tokenType: false,
},
redirect: {
login: '/login',
logout: '/',
callback: '/login',
home: '/dashboard',
},
},
I've defined the auth middleware in nuxt.config.js as router middleware
router: {
middleware: ['auth'],
},
The pages are as follows:
dashboard --index login.vue - auth: 'guest' register.vue - auth: 'guest' index.vue - auth: 'guest'
If I try to put middlewares on the layouts it stops working..
@pi0 Just wanted to notify you about this issue, since @nuxtjs/auth v5 is under development it could hopefully be debugged in the next version.
"@nuxtjs/auth": "^4.9.1" I see it also in older version. Error below:
ERROR Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader (_http_outgoing.js:526:11) at Storage.setCookie (server.js:1410:20) at Storage.setUniversal (server.js:1222:10) at Storage.syncUniversal (server.js:1252:12) at Auth.syncToken (server.js:555:26) at CustomScheme.syncTokens (server.js:1041:22) at refreshAuthToken (server.js:36332:20) at server.js:36380:5 at server.js:1587:45 at processTicksAndRejections (internal/process/task_queues.js:97:5)
+1
Today I reproduce the same mistake. I followed the Nuxt.js documentation and an error popped up.
For me, these are two problems.
Thank you for report! We'll take a look at this issue :)
This is still a problem, FYI. Always happens when redirecting from login to homepage.
Version
v5.0 (latest development build)
v4.9.1Reproduction link
https://github.com/nuxt-community/auth-module/blob/dev/src/core/middleware.ts#L20:L24
Steps to reproduce
1) Set any page with
auth: 'guest'
2) Error on server-sidesCannot set headers after they are sent to the client
What is expected ?
No error
What is actually happening?
Error thrown
Additional comments?
I'm currently using @nuxtjs/auth-next, the code on https://github.com/nuxt-community/auth-module/blob/dev/src/core/middleware.ts#L20:L24 should redirect the user to the correct page, however, I think that's a chance for my server to run code on L26:27
const { tokenExpired, refreshTokenExpired, isRefreshable } = ctx.$auth.check(true)
before the redirect is finished, therefore causing the error.