#REST API - Basic Auth

9 messages · Page 1 of 1 (latest)

keen karma
#

Hello,

Is it possible to have a collection with only admin access, that i can fetch data from using basic auth with my admins credentials and the rest api?

civic shuttle
#

Simply create an API key for your admin user, and use the created api key to authenticate 🙂

keen karma
#

So i would just do this:

const Users: CollectionConfig = {
  slug: 'users',
  admin: {
    useAsTitle: 'name',
    defaultColumns: ['name', 'email'],
  },
  access: {
    read: admins,
    create: anyone,
    update: adminsAndUser,
    delete: admins,
    // admin: ({ req: { user } }) => checkRole(['admin'], user),
  },
  auth: {
    useAPIKey: true,
  },
  fields: UserFields,
  timestamps: true,
}

On my users config, and then i will be able to authenticate to all my collections, after checking the checkbox on the users page?

civic shuttle
#

Yup

#

This will appear on a user, it will generate an API key

#

And here I use the Authorization header

#

And it allows me to create a new document entry