nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

Local Storage warning when running auth in console and on server #1424

Closed haayman-imagem closed 2 years ago

haayman-imagem commented 2 years ago

Version

module: ^5.0.0-1641800591.39ceedf nuxt: @2.0.0

Nuxt configuration

mode:

What is expected?

no error message

What is actually happening?

The screen keeps saying

 WARN  [AUTH] Local storage is enabled in config, but browser doesn't support it                                                                                                                                                                           14:00:40  

 WARN  [AUTH] Local storage is enabled in config, but browser doesn't support it                                                                                                                                                                           14:00:40  

 WARN  [AUTH] Local storage is enabled in config, but browser doesn't support it                                                                                                                                                                           14:00:40  

 WARN  [AUTH] Local storage is enabled in config, but browser doesn't support it                                                                                                                                                                           14:00:40  

 WARN  [AUTH] Local storage is enabled in config, but browser doesn't support it                                                                                                                                                                           14:00:40  

Additional information

Checklist

Steps to reproduce

$ npx create-nuxt-app oauth2-nuxt choose minimal options

$ npm install @nuxtjs/auth-next @nuxtjs/axios axios

  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    // Doc: https://github.com/nuxt-community/dotenv-module
    '@nuxtjs/dotenv',

    '@nuxtjs/auth-next'
  ],
  /*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: { debug: true },
  auth: {
    redirect: {
      login: '/auth/login',
      logout: '/',
      callback: '/auth/login',
      home: '/'
    },

    strategies: {
      local: {
        endpoints: {
          login: {
            url: '/auth/signin',
            method: 'post',
            propertyName: 'token'
          },
          user: {
            url: '/users/details/me',
            method: 'get',
            propertyName: false
          },
          logout: false
        }
      }
    }
  },

$ npm run dev

access localhost:3000 from chrome

P.S. While writing this message I kept nuxt running and it just dumped



<--- Last few GCs --->

[32420:000001FF5F7BF9B0]   331720 ms: Mark-sweep 4007.0 (4133.1) -> 4006.9 (4133.3) MB, 2563.3 / 0.2 ms  (average mu = 0.157, current mu = 0.116) allocation failure GC in old space requested
[32420:000001FF5F7BF9B0]   334417 ms: Mark-sweep 4019.6 (4133.3) -> 4016.1 (4133.8) MB, 2575.2 / 0.2 ms  (average mu = 0.100, current mu = 0.045) deserialize GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
 1: 00007FF6E9A7052F napi_wrap+109311
 2: 00007FF6E9A15256 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfElementsOffset+33302
 3: 00007FF6E9A16026 node::OnFatalError+294
 4: 00007FF6EA2E163E v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF6EA2C64BD v8::SharedArrayBuffer::Externalize+781
 6: 00007FF6EA17094C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516
 7: 00007FF6EA15B58B v8::internal::NativeContextInferrer::Infer+59243
 8: 00007FF6EA140ABF v8::internal::MarkingWorklists::SwitchToContextSlow+57327
 9: 00007FF6EA15470B v8::internal::NativeContextInferrer::Infer+30955
10: 00007FF6EA14B82D v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6269
11: 00007FF6EA15395E v8::internal::NativeContextInferrer::Infer+27454
12: 00007FF6EA1578EB v8::internal::NativeContextInferrer::Infer+43723
13: 00007FF6EA161142 v8::internal::ItemParallelJob::Task::RunInternal+18
14: 00007FF6EA1610D1 v8::internal::ItemParallelJob::Run+641
15: 00007FF6EA1349D3 v8::internal::MarkingWorklists::SwitchToContextSlow+7939
16: 00007FF6EA14BCDC v8::internal::MarkCompactCollector::EnsureSweepingCompleted+7468
17: 00007FF6EA14A524 v8::internal::MarkCompactCollector::EnsureSweepingCompleted+1396
18: 00007FF6EA148088 v8::internal::MarkingWorklists::SwitchToContextSlow+87480
19: 00007FF6EA1766D1 v8::internal::Heap::LeftTrimFixedArray+929
20: 00007FF6EA1787B5 v8::internal::Heap::PageFlagsAreConsistent+789
21: 00007FF6EA16DA61 v8::internal::Heap::CollectGarbage+2033
22: 00007FF6EA17D3E9 v8::internal::Heap::RemoveNearHeapLimitCallback+2857
23: 00007FF6E9E5411F v8::internal::DeserializerAllocator::DecodeReservation+623
24: 00007FF6E9E55733 v8::internal::ContextDeserializer::Deserialize+51
25: 00007FF6E9E55987 v8::internal::ContextDeserializer::DeserializeContext+135
26: 00007FF6E9E469EC v8::internal::CreateSnapshotDataBlobInternal+1932
27: 00007FF6EA0DF051 v8::internal::IsolateAllocator::InitReservation+2017
28: 00007FF6EA0E16F5 v8::internal::IsolateAllocator::InitReservation+11909
29: 00007FF6EA2B5D1D v8::internal::AsmJsScanner::Seek+51821
30: 00007FF6EA2DC928 v8::SharedArrayBuffer::NewBackingStore+520
31: 00007FF6EA2D7ACB v8::Context::New+75
32: 00007FF6E9A1FBEA node::OnFatalError+40170
33: 00007FF6E9A215EE node::OnFatalError+46830
34: 00007FF6EA30385C v8::internal::SetupIsolateDelegate::SetupHeap+44220
35: 000002963F2CC81D
haayman-imagem commented 2 years ago

what is suprising here is that these message appear on the server, so apparently nuxt is trying to use localStorage on the server. I'm not surprised this doesn't work.

Tried to set localStorage:false in the configuration. Now the messages disappear, but the server hangs anyway

haayman-imagem commented 2 years ago

when I set ssr: false the problem goes away. Fine for me for now

peterramsis commented 2 years ago

Where can I set ssr false

haayman-imagem commented 2 years ago

in nuxt.config.js. At the toplevel

steklopod commented 2 years ago

With last version of auth-module and "@nuxt/bridge": "npm:@nuxt/bridge-edge@^3.0.0-27356801.e9128f3" situation is the same :-(

Снимок экрана 2022-01-11 в 22 52 28
AndrewStartcev commented 2 years ago

in nuxt.config.js. At the toplevel Fine! It worked. But I would still like to solve this bug without ssr: false :-(

bmulholland commented 2 years ago

I've updated this issue to be exclusively about the warning in console and on the server. I agree that auth should not be trying to use localStorage in that scenario -- I'll have a look.

VividLemon commented 2 years ago

Continues to be an issue for me as well. It seems like it's nuxt-auth and not the browser. Like nuxt-auth is trying to ping the browser when ssr is on. I think it should be noted that even with localStorage option in nuxt.config auth, it still persists. But I'm sure you knew about both. Only option was to use somebodies suggestion and disable ssr... but kind of defeats the point of using Nuxt.

bmulholland commented 2 years ago

I've pushed a PR with a fix -- can someone please try it out and confirm it's working? https://github.com/nuxt-community/auth-module/pull/1430

peterramsis commented 2 years ago

I deleted node_modules and install and this is still warning is existing @bmulholland

haayman-imagem commented 2 years ago

alas. I did the same. I saw there was an update in package.json and used that ("@nuxtjs/auth-next": "^5.0.0-1642070881.71ddfdf",), deleted node_modules and reinstalled

There is one major improvement though: I only get 6 warnings and then it stops and the page is loaded. Yesterday the server wouldn't give a response. image

VividLemon commented 2 years ago

I've pushed a PR with a fix -- can someone please try it out and confirm it's working? #1430

@haayman-imagem is correct. The server now starts and loads correctly, something that it was unable to do before. But the console warnings still persist. Though, step in the right direction, localStorage: false in the options seems to be working correctly and disables the errors (well, disables localStorage)

haayman-imagem commented 2 years ago

I've pushed a PR with a fix -- can someone please try it out and confirm it's working? #1430

@haayman-imagem is correct. The server now starts and loads correctly, something that it was unable to do before. But the console warnings still persist. Though, step in the right direction, localStorage: false in the options seems to be working correctly and disables the errors (well, disables localStorage)

but that would probably also disable localStorage in the client?

bmulholland commented 2 years ago

You can't test the PR from npm, since it's not merged, so just deleting package.json or node_modules and re-installing would not be sufficient. You'd have to use the git branch directly, which I'm guessing none of you did?

In any case, I just remembered that it's a pain to refer specifically to the raw git repo due to the way the package is built, so I'll just merge it.

bmulholland commented 2 years ago

Please let me know if it's fixed

IsraelOrtuno commented 2 years ago

Seems to be fixed! 👍

VividLemon commented 2 years ago

Seems to be fixed! 👍

My comment was while using auth-next#b8697ab. I had the same idea that they might be using outdated code, but I edited my message when I figured out how to pull a specific branch.

bmulholland commented 2 years ago

My comment was while using auth-next#b8697ab

Yeah, probably because you have to build it with a magic incantation :(

Thanks for everyone's help and patience here -- glad we got it fixed.

VividLemon commented 2 years ago

My comment was while using auth-next#b8697ab

Yeah, probably because you have to build it with a magic incantation :(

Thanks for everyone's help and patience here -- glad we got it fixed.

The #b8 is the sha hash of your branch. tbh didn't know you could do that, but I checked and the changed code was there so idk. But the full release seems to be working as intended. tyvm