Unit tests for API endpoints that need authentication

Hi everyone! I want to create unit tests for my Nest.js API. In those tests, I want to test the endpoints that need authentication. I have made a test user and I just want to log that user in so I can use it’s token.

I already tried it with just logging in into my client application and copying the code but this is manual and I want it to be automated just in the unit tests itself.

I already looked at the Authentication API because I saw that I needed to follow this: (https://auth0.com/docs/api/authentication?javascript#resource-owner-password). But when I post the login request I get this error: Authorization server not configured with default connection. I also read that this resource-owner-password way of authenticating is not recommended. If so, how else can I test my API and provide the token of a test user?

If you need more information just let me know! :slight_smile:

Hi there @luuk welcome to the community!

This error can be resolved by setting a default directory in your tenant settings.

Using the ROPG flow for testing purposes is totally fine - There are certainly other flows recommended for production:

1 Like

It worked! Thank you very much!

1 Like

Awesome, thanks for confirming! :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.