[PR #3074] [CLOSED] Fix: Aggregate permissions from all user roles in hasPermission & Extending the ctx object in the fetch options #30232

Closed
opened 2026-04-17 21:23:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3074
Author: @NalinDalal
Created: 6/18/2025
Status: Closed

Base: mainHead: main


📄 Description

hasPermission fails when called with multiple permissions if those permissions are granted by different roles

Extending the ctx object in the fetch options (#3149)

This PR includes two main improvements:


1. Permission Aggregation Across Roles

Problem:
Previously, hasPermission would only return true if a single role contained all requested permissions. Users with multiple roles could not access features requiring permissions spread across those roles.

Solution:

  • The hasPermission function now aggregates permissions from all roles assigned to a user.
  • It returns true if the union of all assigned roles grants all requested permissions.
  • Maintains backward compatibility for both permissions and deprecated permission properties.

Why:
This aligns permission checks with expected behavior: a user with multiple roles should be granted access if their combined roles provide all required permissions.

Closes:
#3011


2. Extending the ctx Object in Sign-In API Responses

Problem:
The sign-in API response did not include custom user fields (like role and username), making it difficult to access these dynamically in sign-in callbacks.

Solution:

  • The user object returned by both email and social sign-in endpoints now includes role and username.
  • Frontend code can now access these fields via ctx.data.user.role and ctx.data.user.username in sign-in callbacks.

Why:
This enables dynamic redirects and logic based on user properties, without hardcoding values.

Closes:
#3149


Summary of changes:

  • Aggregates permissions from all user roles in

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3074 **Author:** [@NalinDalal](https://github.com/NalinDalal) **Created:** 6/18/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📄 Description # hasPermission fails when called with multiple permissions if those permissions are granted by different roles # Extending the ctx object in the fetch options (#3149) This PR includes two main improvements: --- ## 1. Permission Aggregation Across Roles **Problem:** Previously, `hasPermission` would only return true if a single role contained all requested permissions. Users with multiple roles could not access features requiring permissions spread across those roles. **Solution:** - The `hasPermission` function now aggregates permissions from all roles assigned to a user. - It returns true if the union of all assigned roles grants all requested permissions. - Maintains backward compatibility for both `permissions` and deprecated `permission` properties. **Why:** This aligns permission checks with expected behavior: a user with multiple roles should be granted access if their combined roles provide all required permissions. **Closes:** #3011 --- ## 2. Extending the ctx Object in Sign-In API Responses **Problem:** The sign-in API response did not include custom user fields (like `role` and `username`), making it difficult to access these dynamically in sign-in callbacks. **Solution:** - The user object returned by both email and social sign-in endpoints now includes `role` and `username`. - Frontend code can now access these fields via `ctx.data.user.role` and `ctx.data.user.username` in sign-in callbacks. **Why:** This enables dynamic redirects and logic based on user properties, without hardcoding values. **Closes:** #3149 --- **Summary of changes:** - Aggregates permissions from all user roles in --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 21:23:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#30232