Ok, I might have totally misunderstood how the authentication in Payload and Passport works but I'm trying to implement a custom strategy using
https://www.passportjs.org/packages/passport-custom/.
My somewhat simplified code looks like this:
export const usersCollection: CollectionConfig = {
slug: "users",
auth: {
disableLocalStrategy: true,
strategies: [{
name: 'users-custom'
strategy: new CustomStrategy(( req, callback ) => {
let user;
// Do stuff here to find out which user is requesting and populate user
callback(null, user);
});
}],
},
admin: {
useAsTitle: "email",
},
access: {
read: ({ req }) => {
if (req.user && req.user.groups && req.user.groups.includes("Admin")) {
return true;
}
if (req.user) {
return {
email: req.user.email,
}
}
return false;
},
admin: ({ req }) => {
return req.user && req.user.groups && req.user.groups.includes("Admin");
},
},
...
};
This works fine when accessing api endpoints but for some reason it does not work when trying to access the Payload admin UI.
My understanding was that the custom strategy is used for all authentication in Payload, even the Admin UI? No matter what I do, after logging in the user is redirected back to the login screen even though the Payload JWT cookie is set.
Hey Did you end up finding a solution for this?
Hey, I am facing the same issue, could you help me understand what the issue was
Hey how did you manage to solve this? I am also getting an error on the admin saying: "LocalStrategy is not a constructor"
Star
Discord
online
Get dedicated engineering support directly from the Payload team.