Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

See and edit own account only

default discord avatar
shimizuizumilast year
18

I'm implementing a basic RBAC, how can I have an editor role which should only be able to see and edit their own account, I already locked the role field behind the manager role

  • default discord avatar
    shimizuizumilast year

    Tried both ways and still get the same result with both when trying to access the /admin/account route with a non admin user.

  • default discord avatar
    nils06488last year

    hmmm, works for others.



    And you are getting an error and not a redirect.



    Share the relevant parts of the code, we will figuree it out.

  • default discord avatar
    shimizuizumilast year

    Here's the temporary repo

    @795565624860344320

    , it has nothing besides the the users. I think the issue could be linked to

    ({ req, doc })

    because

    doc

    gives me the "TS2339: Property

    doc

    does not exist on type

    AccessArgs<any>

    " error.

    https://github.com/shimizu-izumi/payload-issue
  • default discord avatar
    rubixvilast year

    you don't need doc, doc is when you do fields



    here's one of mine



    import { AccessArgs, FieldAccess } from "payload"
    import type { Where } from "payload"
    import type { User } from "@/payload/payload-types"
    
    type isAuthenticated = (args: AccessArgs<User>) => boolean | Where
    
    export const self: isAuthenticated = ({ req: { user } }) => {
      if (user) {
        if (user.roles?.includes("admin") || user.roles?.includes("moderator")) {
          return true
        }
    
        return {
          id: {
            equals: user.id,
          },
        }
      }
    
      return false
    }
    
    export const selfcreated: isAuthenticated = ({ req: { user } }) => {
      if (user) {
        if (user.roles?.includes("admin") || user.roles?.includes("moderator")) {
          return true
        }
    
        return {
          createdBy: {
            equals: user.id,
          },
        }
      }
    
      return false
    }
    
    export const selffields: FieldAccess = ({ req: { user }, doc }) => {
      if (user) {
        if (user.roles?.includes("admin") || user.roles?.includes("moderator")) {
          return true
        }
    
        if (doc && doc.id === user.id) {
          return true
        }
      }
    
      return false
    }
  • default discord avatar
    shimizuizumilast year

    I am currently orientating myself on this and it has doc, so I have it too



    Downloaded the auth example and even after updating the dependencies to the newest versions it resulted in a redirect

    @795565624860344320

    I'm really confused now

  • default discord avatar
    nils06488last year

    but the auth example works out of the box? So before your changes?



    Izumi is spring in Japanese, right?

  • default discord avatar
    shimizuizumilast year

    Auth example works, my basically blank project gives me the not found error



    I'm still learning Japanese so it's just a username, but from what I learned so far, yes "spring" should be correct

  • default discord avatar
    nils06488last year

    Maybe you need describe the use case you are trying to implement again.



    Just scrolled up the initial question included /admin/account and users can see on that page.


    The page (view) uses the user from the request to query the data.


    So maybe you are worrying about something, that is no problem?

  • default discord avatar
    shimizuizumilast year

    Ok, here is more detail on why I need this:


    The final website will have a news system (that's where Payload comes in), I want the admin dashboard to have at least 2 roles, editor and admin (permissions are probably self-explanatory), people on the team with the editor role should only be able to see and update their own account in the admin dashboard

  • default discord avatar
    nils06488last year

    Ah! So you create an own dashboard for the users?


    And it is not Payload's Account page?

  • default discord avatar
    shimizuizumilast year

    User authentication is done using logto (makes things easier with the game launcher and game server), the website will have an account settings page for that. I want to use Payload internally to manage the news on the website

  • default discord avatar
    nils06488last year

    So you have your own page and not the /admin/accounts page.


    Everything

    /admin/

    is PayloadCMS, not your app.

  • default discord avatar
    shimizuizumilast year

    /account => user can manage his account


    /admin/account (?) => team member can manage their payload account (except for deleting it)



    Something like that would be the end result I want

  • default discord avatar
    nils06488last year

    and where you face issues?



    /admin/account

    takes the PayloadCMS user and only presents data when found. You do not need to change anything there, I guess.



    Your custom page

    /account/

    should do the same. Take the user make the query.

  • default discord avatar
    shimizuizumilast year

    Ok, let me rephrase it:


    I want to hide the usera collection from team members without admin role, while they can still access /admin/account to edit their own user there (except the role)



    Actually, I think I'll just make it easy for myself and don't allow team members to edit their own user.



    Ok decided to try it one more time and this worked this time, thanks.

  • default discord avatar
    rubixvilast year

    yeh my access controls are different from the ones in the templates. seems like the ones in the templates have been changed not sure if its for the better

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.