directus-labs / agency-os

The open source operating system for digital agencies. Built with Directus and Nuxt.
https://agencyos.dev
MIT License
593 stars 113 forks source link

Get user permissions? #70

Closed Loosie94 closed 9 months ago

Loosie94 commented 9 months ago

Hi guys,

I am working on the AgencyOS portal area. Now I and what to add some logic to some modals and pages, based on the logged-in user (role). I know I can get the logged-in user with the function: const { user } = useDirectusAuth();. but I am running into a few problems with this.

  1. No "role" key and value in response This makes is hard to see if the user is a admin or a client for example.

  2. Permissions cannot be checked without a role? Because no role is set in the user object, it makes it hard check for the correct permissions. I know middleware uses this check page permissions, but is not working for modals/slide-outs right?

Or should I use another way to check this? Thanks in advance!

René

bryantgillespie commented 9 months ago

There's no logic built into the frontend for checking based on roles.

What data users who are logged into the portal have access to is controlled by the permissions within the Directus instance.

Which fields get fetched for the user is controlled in the nuxt.config.ts file.

The user value gets set here in the useDirectusAuth.ts composable.

But if I login to the demo site - I can see the role value for the user in the Nuxt payload. ScreenShot 2024-01-31 at 23 17 41@2x

So it could be potentially be a permissions issue within your Directus instance that's not returning the role for that users within that particular role.

Loosie94 commented 9 months ago

Hi @bryantgillespie , It seems it was a permission issue after all. Been doing a lot of WordPress projects before doing more Directus, so I think I still have to get used to this haha. Thanks again! 👍

bryantgillespie commented 9 months ago

Glad to hear it was a fairly easy fix 👍