#Rest API validation on collection

1 messages · Page 1 of 1 (latest)

glass island
#

Heya, making my first steps into payload and unfortunately I am blocked by a weird not yet understandable issue.

I have added a new collection next to the user collection that should be accessible by the rest api using the auth tokens generated on user collection objects. Using that generated token I can create one new entry for the second collection (configurator) via api and when proceeding by creating another one, I receive an validation error "email must be unique". Seems like somehow the collection I want to create is linked to the accounts email address.. Is there a way to debug / get around such things?

My collection

const Users: CollectionConfig = {
  slug: 'users',
  auth: {
    useAPIKey: true,
  },
  admin: {
    useAsTitle: 'email',
  },
  fields: [
    // Email added by default
    // Add more fields as needed
  ],
};

const Configurators: CollectionConfig = {
  slug: 'configurators',
  admin: {
    useAsTitle: 'title',
    defaultColumns: [],
  },
  access: {
    create: () => true,
    read: () => true,
    update: () => true,
    delete: () => true,
  },
  fields: [
    {
      name: 'title', // required
      type: 'text', // required
      required: true,
      localized: true,
    },
  ],
};
tidal kayak
#

Whats the fetch/REST call you're making?

#

Is it possible you're trying to create another user by accident?

glass island
#

I guess not but the response does behave a little like that.

#

In my headers I have set the Authorization Header as described in the docs as users API-Key mykey

tidal kayak
#

it should return the current user if its successful

glass island
#

you mean get to api/me ?

tidal kayak
#

yeah

#

but in this case it shouldnt matter because your access control is all => true

glass island
#

it responds with an cannot GET /api/me

#

404

#

Interesting fact the first configurator object I was able to generate has a hash salt and email included

tidal kayak
#

ohh sorry it should be /api/{user-collection}/me

#

can you inspect your collection in the db via something like mongo compass

#

the other thing im thinking could be an issue

#

is a leftover/dead content in the db

#

if you previously had something else for the configurators collection

glass island
#

Ah that might be, I have switched on and off useAPI stuff..

tidal kayak
#

ah ok you wanna remove anything not matching the config from the database

glass island
#

okay, I will just start from scratch prob easier cause I dont know in detail what to cleanup 😄

#

But thanks a lot mate!!

tidal kayak
#

you can just drop your whole collection just to test it

#

if you only have test content

glass island
#

Ah okay, how can i do that ?

tidal kayak
#

in mongo compass

#

and then restart payload and try again

glass island
#

Oh okay, nvm dont have mongo compass installed - need to do that.. but for now I have just dropped the docker image 😄

#

Mongocompass is equivalent to pgadmin or phpmyadmin or other sql related clients ?

#

just for mongodb ?

tidal kayak
#

yep, very useful when working with mongo

#

though it doesnt have quite the power of pgadmin

glass island
#

okay got rid of the collections

#

ah perfect, now it works 🙂

#

Highly appreciate your help!

#

so conclusion: when ever there is a document inside of my collection that contains like authentication related stuff, payload requires all new documents to match the structure?

#

might be a stupid question, but I am relatively new to nosql databases especially mongodb

tidal kayak
#

99% of the time its because of some dead content in the database after schema changes

#

sql forces you to update schema (and therefore drop or modify data) so its less noticeable there

#

but mongo just kinda shrugs about it

glass island
#

Haha yes.. indeed.. mongo had me there.. I am used to migrations and stuff in sql world mongo feels like "i dont care what you have, just give it to me and i save it"

mossy lance