Role-based Access Control (RBAC) User Authorization in Next.js

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ม.ค. 2025

ความคิดเห็น • 40

  • @Supabase
    @Supabase  10 หลายเดือนก่อน +5

    Thanks for tuning in! Make sure to check out the docs: supabase.com/docs/guides/auth/custom-claims-and-role-based-access-control-rbac?
    And you can find the code on GitHub: github.com/supabase/supabase/tree/master/examples/slack-clone/nextjs-slack-clone

  • @carlosricardoziegler2650
    @carlosricardoziegler2650 10 หลายเดือนก่อน +9

    What is the good approach to change claims from a user and get changes in realtime ?

  • @proletarium
    @proletarium 10 หลายเดือนก่อน +2

    Small tangent, perhaps, but what was the approach to determine which channels were available to delete for the moderator role in the UI? The trash icon existed for just the one available to delete. Presumably that's using the same rules as RLS for the delete, but are those rules duplicated into a function your UI is using?

  • @SsaliJonathan
    @SsaliJonathan 3 หลายเดือนก่อน +3

    Let us all be real. This appraoch is the hardest. I followed the docs, And there is nothing.

  • @hago7568
    @hago7568 7 หลายเดือนก่อน +2

    Is there an update for the app router? I am trying to do this in the middleware but can't get it to work

  • @skillsvsdegree6139
    @skillsvsdegree6139 10 หลายเดือนก่อน +3

    Perfect timing for me, This is what I need for my website now,
    Do you have the videos of how you developed this chat app that you showed in the video?
    Thank you

    • @thorwebdev
      @thorwebdev 10 หลายเดือนก่อน +1

      You mean a video of live coding the entire Slack clone?

    • @skillsvsdegree6139
      @skillsvsdegree6139 10 หลายเดือนก่อน

      @@thorwebdev Yes. I have seen their video stream of happy hours few months ago and it made me start my own website. now i have launched it. but it's bit old, Is there a entire slack clone video like that? can you give the link if it there?

    • @skillsvsdegree6139
      @skillsvsdegree6139 10 หลายเดือนก่อน

      Oh i didn't notice, it's you Thor, you were in that stream right? i think came only in one video :) they were joking about Hammer, it was such a wonderful stream, made me start my own website and i started to learn react and now my website is live, but need soooo many improvements to make. love you guys. Thanks Thor

  • @nikitastriuk
    @nikitastriuk 10 หลายเดือนก่อน +3

    Thanks!
    What if user could be part of multiple organizations and have different roles within them? Struggling with implementing this - will appreciate any advice.

    • @syedfaysel
      @syedfaysel 9 หลายเดือนก่อน

      I have the similar query. Let me know if anyone have any good idea

    • @johngn1978
      @johngn1978 7 หลายเดือนก่อน

      same problem here, did you find any solution?

    • @haraldlons
      @haraldlons 7 หลายเดือนก่อน

      I'm wondering about the same

    • @alexizhernandez8011
      @alexizhernandez8011 6 หลายเดือนก่อน

      same here. anyone ever figure out a good way?
      Edit: An approach I was thinking maybe was refetching the token based on the organization instance. For example, you can have their meta data something like this
      {
      "org": "org-id",
      "role": "user",
      "additional_permissions": []
      }
      and on the client side, if they change between orgs somehow, that can trigger a session refresh with somehow passing in the org id that they wish to switch to?

    • @matthewbeardsley7004
      @matthewbeardsley7004 5 หลายเดือนก่อน

      your user_roles table could have an organisation_id column, so then you should be able to do different organisations with different roles

  • @belmo_
    @belmo_ 9 หลายเดือนก่อน

    Just tried using this approach adding a custom claim (is_admin) to the JWT in a NextJS 14 but it just keep running into an Error -> AuthApiError: Error invoking access token hook

  • @jonathangamble
    @jonathangamble 10 หลายเดือนก่อน +1

    If custom claims still reads from the database, how is this faster than just using RLS directly?

    • @Supabase
      @Supabase  10 หลายเดือนก่อน

      The Auth Hook is only triggered when a token is issued rather than the RLS policy triggering for each API call. So there is a bit of optimization here.

    • @Rexhibition
      @Rexhibition 9 หลายเดือนก่อน

      @@Supabasehi, I am a beginner so the RLS is easier for me to control. Would the optimization really make a difference in term of performance and security? Or controlling the RLS directly is sufficient. Thank you.

  • @nic_fontana
    @nic_fontana 6 หลายเดือนก่อน +1

    Nice video! Thank you 😊
    I am wondering why you don’t enable this feature by default, like Auth0 does, but we have to actually write a bunch of stuff in our project following a documentation page

  • @martinl.2033
    @martinl.2033 หลายเดือนก่อน

    Hi @Supabase,
    thanks for that. I have tweaked it so that I can use a helper function and trigger to control all my fields by the roles (I ignore permissions for now, it is way too much for my usecase).
    But here is the thing: with your Custom Auth Hook when Impersonating the user right in your SupaBase Webapp to quick-checking things - it is just not working. I guess this impersonating stuff ignores to get the JWT which contains the custom Data from the Custom Auth Hook function that has to be called. When checking these things in my own app, I see that the Custom JWT is issued and all infos are there. Also my Policy setup is working. But not when impersonating. This is really pain when it comes to quick checking things right in your tool rather than having rapid implementations in the app itself.
    Any comments on this?

  • @GabrielFernandes-bc7se
    @GabrielFernandes-bc7se 5 หลายเดือนก่อน

    Does the impersonate method work correctly with this?
    Imagine that we have two policies:
    - one to get the user's own messages (individual select)
    - one to get every message (for admin users)
    I tried it and technically it works but it does not work when I'm impersonating... Is there anything missing? Does the auth hook run on impersonate?
    I don't feel confident enough by testing these policies in development but not being able to test them using impersonate.

  • @tej_777_
    @tej_777_ 10 หลายเดือนก่อน +1

    This is amazing been wanting to implement such functionality , nice to see a tutorial on this. Wonder if it works well with graphql too ?

    • @Supabase
      @Supabase  10 หลายเดือนก่อน

      Yes, GraphQL fully supports this approach also 👍

  • @sandeepyadav4508
    @sandeepyadav4508 3 หลายเดือนก่อน

    Hi , i have used the same steps. Still i am not getting user_role in jwt, can someone help

  • @АлибекБилалов-н4я
    @АлибекБилалов-н4я 8 หลายเดือนก่อน

    Question how can I create custom access token if I deployed supabase in self hosting docker? I'm trying to create a Hook: Custom access token but I can't get it to work... Supabase I deployed in self-hosting version. The documentation says to add fields to config.toml I found it in supabase/supabase/config.toml . But as I understand it is not what I need. Question how can I create custom access token if I deployed supabase in self hosting docker ?

  • @Tanner-cz4bd
    @Tanner-cz4bd 10 หลายเดือนก่อน

    Supabase with drizzle ?
    Or local dev ?

  • @derekjwilliams
    @derekjwilliams 8 หลายเดือนก่อน

    Great stuff, I was wondering what the Supabase team thinks of services like Cerbos for RBAC, ABAC

  • @zeeeeeman
    @zeeeeeman 6 หลายเดือนก่อน +1

    Noob question: why a public.users table? Why not use auth.users?

    • @Justin-oo2xt
      @Justin-oo2xt 6 หลายเดือนก่อน +1

      You can’t query auth.users using the Javascript client

    • @flowmv
      @flowmv 6 หลายเดือนก่อน +1

      @@Justin-oo2xt why do we need to query auth.users anyway when the cookie/jwt will be stored locally in the browser?

    • @zeeeeeman
      @zeeeeeman 6 หลายเดือนก่อน

      @@flowmv I was thinking about trying to get all the users out of the auth table.

  • @VOVOPERADOR
    @VOVOPERADOR 8 หลายเดือนก่อน

    this saved me

  • @devdariill
    @devdariill 10 หลายเดือนก่อน

    nice 9:34 mins, how to learn more about it.

  • @mehmethanifierenler3612
    @mehmethanifierenler3612 4 หลายเดือนก่อน

    thanks

  • @HijabiCoder
    @HijabiCoder 10 หลายเดือนก่อน +2

    Always pronounced it Ree-back 😅

    • @skillsvsdegree6139
      @skillsvsdegree6139 10 หลายเดือนก่อน

      Have you developed any personal websites with this? can i see? Thank you.

  • @Muyiwamighty
    @Muyiwamighty หลายเดือนก่อน +1

    Let's be honest, this video on is disappointing and not helpful.