#User authentication

12 messages · Page 1 of 1 (latest)

honest herald
#

I have my UserFrontend collection, which allows me to register and assign permissions to users, the question is how do I get their password and token because the API does not return this data? The authentication is handled with ReactJS from the Frontend.

keen charm
#

Hi!
Payload saves password as salt and hash to the database. All find operations are sanitized, and specifically hash and salt are removed from the document when you use any find operations. If you want to query tokens, you can create a custom endpoint and use

const { docs } = await req.payload.find({
  collection: "users",
  pagination: false,
  showHiddenFields: true,
  queryHiddenFields: true,
});
#

And as Payload uses MongoDB, you can also query the database on your own

keen charm
#

For querying all users with all data you can use this snippet inside server.ts

import { Collection, Db, MongoClient } from "mongodb"; // You need to install MongoDB as a dependency, but don't worry, as Payload already uses MongoDB already, you won't be adding much more in terms of bloat to your app

app.get("/get-users", async (req, res) => {
  const connectionString = ""; // Paste connection string you use in Payload here just to test it, or use environment variable
  const client = new MongoClient(connectionString);
  let conn: any;
  try {
    conn = await client.connect();
  } catch (e) {
    console.error(e);
  }
  let db: Db = conn.db("prod"); // Set to database you use for your CMS
  const collection: Collection = db.collection("users");
  const users = await collection.find().toArray();
  res.json(users);
});
#

As you can see, I got all data

honest herald
keen charm
honest herald
keen charm
#

From the object find returns

keen charm
#

And I would change the path to something different than users