#User authentication
12 messages · Page 1 of 1 (latest)
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
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
Where should I do the endpoint, next to my collection?
I am doing this:
path: '/users',
method: 'get',
handler: async (req, res, next) => {
const docs = await req.payload.find({
collection: 'users',
pagination: false,
showHiddenFields: true,
queryHiddenFields: true,
});
}
}]```
But where does `{docs}` get unstructured from?
From the object find returns
Also, you are not destructuring the docs right now
And I would change the path to something different than users