Auth-module: LoginWith is not responding although there is no error

Created on 1 Jan 2021  路  9Comments  路  Source: nuxt-community/auth-module

Version

module: 5.0.0
nuxt: 6.14.4

Nuxt configuration

mode:

  • [mode ] universal

Nuxt configuration

auth: {
      strategies: {
        local: {
          token: {
            property: 'token',
            // required: true,
            // type: 'Bearer'
          },
          user: {
            property: 'user',
            // autoFetch: true
          },
          endpoints: {
            login: { url: 'http://localhost:3000/api/auth/login', method: 'post' },
            logout: { url: process.env.baseUrl + '/auth/logout', method: 'post' },
            user: { url: process.env.baseUrl + '/auth/user', method: 'get' }
          }
        }
      }
    }

Reproduction

:warning: without a minimal reproduction we won't be able to look into your issue

What is expected?

I installed the auth-next module. I'm working on making login with loginWith.

let response = await this.$auth.loginWith('local', { data: form }) console.log(response)

What is actually happening?

When the request is sent, there is no response, although there was no error.
and I can't login to the server for a long time. "localhost: 3000". The browser has been trying to login for a long time and I am getting the error I wrote below.

api/index.js:

`const refreshTokens = {}

app.post('/auth/login', (req, res) => {


  const { username, password } = req.body
  const valid = username.length && password === '123'
  const expiresIn = 15
  const refreshToken =
    Math.floor(Math.random() * (1000000000000000 - 1 + 1)) + 1

  if (!valid) {
    throw new Error('Invalid username or password')
  }

  const accessToken = jsonwebtoken.sign(
    {
      username,
      picture: 'https://github.com/nuxt.png',
      name: 'User ' + username,
      scope: ['test', 'user']
    },
    'dummy',
    {
      expiresIn
    }
  )

  refreshTokens[refreshToken] = {
    accessToken,
    user: {
      username,
      picture: 'https://github.com/nuxt.png',
      name: 'User ' + username
    }
  }
console.log("burda")
  res.json({
    token: {
      accessToken,
      refreshToken
    }
  })
})`

error:

````
12:50:41

<--- Last few GCs --->

[1032:000001BBBC1CA4A0] 414463 ms: Mark-sweep 1983.7 (2051.9) -> 1976.2 (2053.2) MB, 4949.0 / 0.1 ms (average mu = 0.128, current mu = 0.018) deserialize GC in old space requested
[1032:000001BBBC1CA4A0] 418229 ms: Mark-sweep 1977.1 (2053.2) -> 1976.6 (2054.2) MB, 3699.0 / 0.2 ms (average mu = 0.079, current mu = 0.018) allocation failure GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x030358c06c61
0: builtin exit frame: defineProperty(this=0x0104219f1dd1 ,0x01ac32fcde51 ,0x01ac32fcde31 ,0x01ac32fc8769 ,0x0104219f1dd1 )

1: copyPropsRenamed(aka copyPropsRenamed) [000001AC32FC9059] [internal/per_context/primor...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Writing Node.js report to file: report.20210101.125635.1032.0.001.json
Node.js report completed
1: 00007FF740FCCF2F napi_wrap+112799
2: 00007FF740F6CF26 public: bool __cdecl v8::base::CPU::has_sse(void)const __ptr64+55702
3: 00007FF740F6DDB3 public: bool __cdecl v8::base::CPU::has_sse(void)const __ptr64+59427
4: 00007FF74178A27E private: void __cdecl v8::Isolate::ReportExternalAllocationLimitReached(void) __ptr64+94
5: 00007FF741772351 public: class v8::SharedArrayBuffer::Contents __cdecl v8::SharedArrayBuffer::Externalize(void) __ptr64+833
6: 00007FF74163E8AC public: static void __cdecl v8::internal::Heap::EphemeronKeyWriteBarrierFromCode(unsigned __int64,unsigned __int64,class v8::internal::Isolate * __ptr64)+1436
7: 00007FF741649AE0 public: void __cdecl v8::internal::Heap::ProtectUnprotectedMemoryChunks(void) __ptr64+1312
8: 00007FF741646604 public: static bool __cdecl v8::internal::Heap::PageFlagsAreConsistent(class v8::internal::HeapObject)+3204
9: 00007FF74163BE03 public: bool __cdecl v8::internal::Heap::CollectGarbage(enum v8::internal::AllocationSpace,enum v8::internal::GarbageCollectionReason,enum v8::GCCallbackFlags) __ptr64+1283
10: 00007FF74163A474 public: void __cdecl v8::internal::Heap::AddRetainedMap(class v8::internal::Handle) __ptr64+2452
11: 00007FF74165B7BB private: class v8::internal::Handle __cdecl v8::internal::Factory::NewFixedArrayWithFiller(enum v8::internal::RootIndex,int,class v8::internal::Object,enum v8::internal::AllocationType) __ptr64+107
12: 00007FF741654787 public: class v8::internal::Handle __cdecl v8::internal::Factory::InternalizeString(class v8::internal::Vector

const & __ptr64,bool) __ptr64+471
13: 00007FF7414A3209 public: static class v8::internal::Handle __cdecl v8::internal::HashTable::EnsureCapacity(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,int,enum v8::internal::AllocationType)+233
14: 00007FF74149A05D public: static class v8::internal::Handle __cdecl v8::internal::Dictionary::Add(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,class v8::internal::Handle,class v8::internal::Handle,class v8::internal::PropertyDetails,int * __ptr64)+109
15: 00007FF741499E76 public: static class v8::internal::Handle __cdecl v8::internal::BaseNameDictionary::Add(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,class v8::internal::Handle,class v8::internal::Handle,class v8::internal::PropertyDetails,int * __ptr64)+118
16: 00007FF7414EC829 public: void __cdecl v8::internal::JSReceiver::SetIdentityHash(int) __ptr64+4217
17: 00007FF7414CDE66 public: void __cdecl v8::internal::LookupIterator::TransitionToAccessorPair(class v8::internal::Handle,enum v8::internal::PropertyAttributes) __ptr64+598
18: 00007FF7414CE1D5 public: void __cdecl v8::internal::LookupIterator::TransitionToAccessorProperty(class v8::internal::Handle,class v8::internal::Handle,enum v8::internal::PropertyAttributes) __ptr64+789
19: 00007FF7414DE4EA public: static void __cdecl v8::internal::JSObject::AddProperty(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,class v8::internal::Handle,class v8::internal::Handle,enum v8::internal::PropertyAttributes)+4794
20: 00007FF7414EF2D1 public: static void __cdecl v8::internal::JSObject::TransitionElementsKind(class v8::internal::Handle,enum v8::internal::ElementsKind)+2497
21: 00007FF7414EA802 public: static void __cdecl v8::internal::JSObject::NormalizeProperties(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,enum v8::internal::PropertyNormalizationMode,int,char const * __ptr64)+1778
22: 00007FF7414DE643 public: static class v8::internal::MaybeHandle __cdecl v8::internal::JSObject::DefineAccessor(class v8::internal::Handle t>,class v8::internal::Handle,class v8::internal::Handle,class v8::internal::Handle,enum v8::internal::PropertyAttributes)+307
23: 00007FF7416FCA81 public: class v8::internal::Handle __cdecl v8::internal::Builtins::builtin_handle(int) __ptr64+56049
24: 00007FF7416FD8FE public: class v8::internal::Handle __cdecl v8::internal::Builtins::builtin_handle(int) __ptr64+59758
25: 00007FF741BD740D public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+546893
26: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
27: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
28: 00007FF741BE94FC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+620860
29: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
30: 00007FF741B597F1 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+31793
31: 00007FF741B593DC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+30748
32: 00007FF741697F63 public: static void __cdecl v8::internal::Execution::CallWasm(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,unsigned __int64,class
v8::internal::Handle,unsigned __int64)+1395
33: 00007FF7416978E6 public: static class v8::internal::MaybeHandle __cdecl v8::internal::Execution::Call(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,class v8::internal::Handle,int,class v8::internal::Handle * __ptr64 const)+182
34: 00007FF74176895D public: class v8::MaybeLocal __cdecl v8::Function::Call(class v8::Local,class v8::Local,int,class v8::Local * __ptr64 const) __ptr64+605
35: 00007FF740FEB190 bool __cdecl node::InitializeContext(class v8::Local)+864
36: 00007FF740FEB4B9 class v8::Local __cdecl node::NewContext(class v8::Isolate * __ptr64,class v8::Local)+89
37: 00007FF740F76241 public: bool __cdecl v8::base::CPU::has_sse(void)const __ptr64+93361
38: 00007FF740F7768B public: bool __cdecl v8::base::CPU::has_sse(void)const __ptr64+98555
39: 00007FF74173DF10 public: class v8::internal::Handle __cdecl v8::internal::Builtins::builtin_handle(int) __ptr64+323456
40: 00007FF74173D457 public: class v8::internal::Handle __cdecl v8::internal::Builtins::builtin_handle(int) __ptr64+320711
41: 00007FF74173D798 public: class v8::internal::Handle __cdecl v8::internal::Builtins::builtin_handle(int) __ptr64+321544
42: 00007FF74173D59E public: class v8::internal::Handle __cdecl v8::internal::Builtins::builtin_handle(int) __ptr64+321038
43: 00007FF741BD740D public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+546893
44: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
45: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
46: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
47: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
48: 00007FF741BAA486 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+362694
49: 00007FF741B57973 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+23987
50: 00007FF741C3BAF0 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+958256
51: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
52: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
53: 00007FF741B5C2BC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+42748
54: 00007FF741B86F63 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+218019
55: 00007FF741BAB8C2 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+367874
56: 00007FF741B7945D public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+161949
57: 00007FF741B596DC public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+31516
58: 00007FF741697FF0 public: static void __cdecl v8::internal::Execution::CallWasm(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,unsigned __int64,class
v8::internal::Handle,unsigned __int64)+1536
v8::internal::Handle,unsigned __int64)+1779
60: 00007FF7416984C2 public: static class v8::internal::MaybeHandle __cdecl v8::internal::Execution::TryCall(class v8::internal::Isolate * __ptr64,class v8::internal::Handle,class v8::internal::Handle,int,class v8::internal::Handle * __ptr64 const,enum v8::internal::Execution::MessageHandling,class v8::internal::MaybeHandle * __ptr64)+354
61: 00007FF74167A4D5 public: int __cdecl v8::internal::MicrotaskQueue::RunMicrotasks(class v8::internal::Isolate * __ptr64) __ptr64+501
62: 00007FF740FECE35 public: __cdecl node::CallbackScope::~CallbackScope(void) __ptr64+597
63: 00007FF740FED1A4 public: __cdecl node::CallbackScope::~CallbackScope(void) __ptr64+1476
64: 00007FF740FE6E73 public: int __cdecl v8::internal::compiler::Operator::EffectOutputCount(void)const __ptr64+179
66: 00007FF740F5B8F7 public: static int __cdecl v8::internal::OrderedHashTable::NumberOfBucketsOffset(void)+61383
67: 00007FF74101D417 uv_timer_stop+775
68: 00007FF741019ECB uv_async_send+331
69: 00007FF74101966C uv_loop_init+1212
70: 00007FF741019834 uv_run+244
71: 00007FF740F29681 private: class v8::internal::SourcePositionTableBuilder * __ptr64 __cdecl v8::internal::interpreter::BytecodeArrayWriter::source_position_table_builder(void) __ptr64+31713
72: 00007FF740F96223 int __cdecl node::Start(int,char * __ptr64 * __ptr64 const)+275
73: 00007FF740E16A9C RC4_options+340380
74: 00007FF741C8F3F8 public: virtual bool __cdecl v8::internal::SetupIsolateDelegate::SetupHeap(class v8::internal::Heap * __ptr64) __ptr64+1300536
75: 00007FFB33797034 BaseThreadInitThunk+20
76: 00007FFB3531D0D1 RtlUserThreadStart+33
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] dev: nuxt
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\acer\AppData\Roaming\npm-cache_logs\2021-01-01T09_56_40_326Z-debug.log
````

bug

All 9 comments

Sorry, I can't understand what your issue is. It seems like the problem is with the server response to your login request? If so, that's not the responsibility of this auth module, which only handles the client side.

I had to revert to the stable version v4.9.1 for it to work.

@StanleyMasinde Can you please provide information so that we can fix v5? We need your help so that you're not stuck on 4.9.

The loginWith() method does not initiate login function however no errors are displayed. I'll try to write down the steps to reproduce the error later today.

Thanks! What would be most helpful is if you could stick a breakpoint there and trace execution into where the issue actually happens.

Hi there,

I ran into the same issue. My JS debugging isn't the best, but I believe I have narrowed down the issue a little more. I believe the issue is related to the autofetch to /api/auth/user. I have just added this route to my api, and it worked. I also tried stepping through in the console, and it was at this point I noticed it was doing a call to /api/auth/user that I hadn't expected or got around to implementing yet, as I just wanted to make sure my login endpoint worked.
So it appears the loginWith doesn't resolve until /api/auth/user also resolves.

Setting
user: {
property: 'user',
autoFetch: false
},
doesn't stop the endpoint from being called.

Copying the config from https://auth.nuxtjs.org/schemes/local (Cookie) and without implementing the /user endpoint.

"@nuxtjs/auth": "^4.9.1",
"@nuxtjs/axios": "^5.12.5",

I tried the latest version of auth with the same issue + issue with using an auth0 setup. As V5 isn't stable, I am currently using 4.9.1

Edit:
I found V4 docs (https://github.com/nuxt-community/auth-module/blob/master/docs/schemes/local.md) which says I need to set: autoFetchUser: false and that works.

So the bug is with v4 and is caused by an autofetch that assumes the endpoint is there if autofetch isn't set to false & fails to resolve/reject when the endpoint doesn't exist.

Edit 2: The same assumption & issue appears to exist in V5 also. Again, adding the endpoint or user: { autoFetch: false } prevents it.
"@nuxtjs/auth-next": "^5.0.0-1611071776.3646657",

@frostie614 that's _very_ helpful - thank you!

In terms of an explanation of the behaviour, please see https://github.com/nuxt-community/auth-module/pull/1002. It would help us improve the docs if you could add any unanswered questions or thoughts that you have on that PR.

In terms of something that should at least help you debug this faster in future, I've filed https://github.com/nuxt-community/auth-module/issues/1024

Is there anything else I've missed?

I see you have just merged #1002, so i won't comment on that. I thought it would be good to provide the endpoints.user default in the example for the cookie based flow aswell as the token based flow. Anyone who C&P's, the example, thinking they know how this module works without reading the doc's will run into the same issue. At least by adding endpoint.user to the example, they can see a hint that the endpoint should be implemented also. Thank you for raising #1024, an error being reported would definitely help!

Thanks for the feedback! I've created a specific item to improve the cookie docs. With that issue, I believe we've now split out all the feedback in this Issue into more specific ones, so I'm closing this larger one. Please let me know if I've missed anything.

Was this page helpful?
0 / 5 - 0 ratings