如何在REST API中将移动应用程序用户和Web应用程序用户分开?

发布于 2025-02-03 18:18:33 字数 117 浏览 3 评论 0原文

有不同的用户,例如教练,运动员,见面主任和管理员。教练&运动员是移动应用程序用户,管理员是Web应用程序用户,Meet Director既是移动设备& Web应用程序用户。 请建议任何宝石或分享您的想法。

There are different user like Coach, Athlete, Meet Director and Admin. Coach & Athlete are mobile app users, Admin are Web app user, Meet Director are both mobile & web app user.
Please suggest any gem or share your thoughts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2025-02-10 18:18:33

这个问题非常广泛,我将做出建议以提出建议:

  • 您拥有相同的服务(相同的API入口点),以所有不同的角色(“角色”为关键词),
  • 取决于角色, 基于此,用户将具有不同的操作范围

,我建议您根据角色分配使用检查点的服务。

我在下面建议的方法非常幼稚,但是好像您作为“工厂”的入口点,根据用户的角色产生回应...

我会说一件事可能在将来证明有价值的一件事是允许用户具有多个角色。如果这很有意义,那将使用户允许教练和运动员进入。

例如:

class Api::V1::SomethingController < ApplicationController

  ...
  def my_service
     user = User.find(params[:id])
     
     # Makes sure we have an user
     render json: {}, status: :bad_request unless user

     # performs differently based on the role
     my_service_for_coaches if user.roles.include? 'coach'
     my_service_for_athletes if user.roles.include? 'athlete'
     ....
  end

  def my_service_for_coaches
    ...
  end
  ...

end

但是,让我添加一种方法的建议

This question is very broad, and I will make sume assumptions in order to make a suggestion:

  • you have the same service (same api entry point) served to all different Roles ("role" being the key word)
  • Depending on the role, the user will have different scope of action withing that same service

Based on this, I would suggest you to assign your service with checkpoints based on the role.

The approach I suggest below is quite naive, but works as if your entry point as a 'factory', producing the response based on the users's role...

I would say one thing that might prove valuable in the future is to allow an user to have multiple roles. That would grant the user both coach and athlete access, for exemple, if that makes sense.

Ex:

class Api::V1::SomethingController < ApplicationController

  ...
  def my_service
     user = User.find(params[:id])
     
     # Makes sure we have an user
     render json: {}, status: :bad_request unless user

     # performs differently based on the role
     my_service_for_coaches if user.roles.include? 'coach'
     my_service_for_athletes if user.roles.include? 'athlete'
     ....
  end

  def my_service_for_coaches
    ...
  end
  ...

end

but let me add a suggestion of approach to take

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文