payload-auth-plugin: The plugin does not work when run and produces an error: [PAYLOAD_AUTH_PLUGIN_ERROR: Missing users collection]

Describe the bug I am following the tutorial from https://authsmith.com/docs/plugins/payload/installation, but until now I can’t use it because when running npm run dev, payloadcms always produces an error:

Image

If I look at the example of usage in this Youtube tutorial https://www.youtube.com/watch?v=ahlk76lsqD0&t=22s, it should automatically create the Accounts collection, right? I’m new to Payloadcms, if there are any steps I missed, please correct me, thank you.

My package.json: Image

My payload.config.ts:

Image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26

Most upvoted comments

You should set type to module because If this field is not present, Node.js will treat the files as CommonJS modules by default.

Ah I see, this works although I have to make some adjustments to the existing code. Thanks @itzpere !

Should I close this issue or is there something you want resolved @sourabpramanik ?

You should set type to module because If this field is not present, Node.js will treat the files as CommonJS modules by default.

This is fixed in v0.5.8. Feel free to re-open the issue if you are still facing problems

Thank you, but I’m still facing the same error, even I’ve already upgraded the plugin to 0.5.8 Image

I tried this after doing that, but it’s still the same.

Ah, it turns out it was our engineer’s fault, so I just need to add the users collection manually. (It seems it was previously deleted).

One more question, if I want to add an accounts collection to make writing code easier and ensure type safety (safety props typing) in TypeScript, do I need to add it manually into payload.config.ts?

You can read about it here

Payload by default will create a Users collection with slug “users” as it will use it to store the admin users. This plugin will use the same collection slug as well to process the auth.

In your project look for “/src/collections/Users/index.ts”. Let me know if you are able to find it