Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add org role/permission helpers #40

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/clerk/authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def clerk_organization_id
request.env["clerk"].org_id
end

def clerk_organization_role
request.env["clerk"].org_role
end

def clerk_organization_permissions
request.env["clerk"].org_permissions
end

def clerk_user_signed_in?
!!clerk_verified_session_claims
end
Expand All @@ -82,7 +90,8 @@ def clerk_user_profile_url
:clerk_verified_session_claims, :clerk_verified_session_token,
:clerk_user, :clerk_user_id, :clerk_user_signed_in?, :clerk_sign_in_url,
:clerk_sign_up_url, :clerk_user_profile_url,
:clerk_organization, :clerk_organization_id
:clerk_organization, :clerk_organization_id, :clerk_organization_role,
:clerk_organization_permissions
end
end
end
12 changes: 12 additions & 0 deletions lib/clerk/rack_middleware_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def org_id
@session_claims["org_id"]
end

def org_role
return nil if @session_claims.nil?

@session_claims["org_role"]
end

def org_permissions
return nil if @session_claims.nil?

@session_claims["org_permissions"]
end

private

def fetch_user(user_id)
Expand Down