flutter_next_auth 1.3.0
flutter_next_auth: ^1.3.0 copied to clipboard
Authentication, session management and permission checks for Frappe/ERPNext apps. Secure session storage, token auth, 2FA and Frappe v13-v16 compatible role handling.
1.3.0 #
Reliability and Frappe-version compatibility release. No public API was removed; two methods are deprecated with replacements.
Fixed #
- Being offline no longer signs the user out.
relogin()cleared the stored session on any exception, so a timeout, a 5xx or an unreachable server destroyed the session permanently. It now clears only when the server actually rejects the session (401/403, or a FrappeAuthenticationError/SessionExpired).ReloginResult.sessionClearedtells the two cases apart. changePassword()no longer strands the app on a dead session. Frappe re-authenticates insideupdate_password, which issues a new session id. That id is now persisted; previously the app worked until its next launch and then failed to restore the session.- A rejected login no longer leaves a
Guestsession behind. Frappe answers a wrong password withSet-Cookie: sid=Guest; that was being adopted and sent on every later request. Session ids are now only read from successful responses, andGuestis rejected outright. - User ids containing
+work again. The roles lookup interpolated the user id straight into a URL, and a literal+in a query string decodes to a space server-side, sosomeone+erp@gmail.comwas sent assomeone erp@gmail.com. All query parameters are now properly encoded. - Frappe error messages survive.
_server_messages— the textfrappe.throw()actually shows the user — is now extracted and HTML-stripped, falling back throughmessage,exceptionandexc_type. Non-JSON bodies (nginx error pages, proxy timeouts) no longer produce a cast error. - Requests can no longer hang forever. The configured timeout is now applied
to every request and surfaces as a
NextApiExceptionwithstatusCode == NextApiException.timeoutStatus. UserProfile.fullNameand.emailare no longer permanently null.frappe.auth.get_logged_userreturns nothing but the user id, so the profile is now enriched from the User document where permissions allow, and falls back to the full name captured at login.
Added #
- Permission checks —
role.canRead,canWrite,canCreate,canDelete,canSubmit,canCancel,hasPermission()andgetDocPermissions(), backed byfrappe.client.has_permissionandfrappe.client.get_doc_permissions. These are what the desk itself uses, they work on every Frappe version, and they are the recommended replacement for role checks. - Two factor authentication.
LoginResult.requiresTwoFactorplusconfirmTwoFactor(). Sites with 2FA enabled previously could not sign in at all. - Token authentication. Pass
apiKeyandapiSecrettoinitialize()to authenticate with an API key pair instead of a session. Token auth does not expire and is the only scheme that works on Flutter web, where browsers hideSet-Cookiefrom the app. flutternext.apiexposesNextApiClientfor authenticated calls this package does not wrap.NextApiClientandNextApiExceptionare now exported, so errors can be caught by type.cookieHeader()returns the session as aCookieheader, for sharing one session withflutter_next_base, a WebSocket, or a WebView.getServerVersions()readsfrappe.utils.change_log.get_versions, for branching on server capabilities.hasStoredSession()(local check) andvalidateSession()(live check).initialize(force: true)to reconfigure against a different site, anddispose()to release the HTTP client.NextApiException.excType,.isAuthError,.isTransportErrorand.data.- A test suite covering session handling, query encoding, error parsing, error classification and timeouts.
Changed #
-
Role lookup is now version-aware. Frappe removed
frappe.core.doctype.user.user.get_rolesin v16 — it exists in v13, v14 and v15 only.getUserRoles()now tries, in order: a custom method you name via the newrolesMethodoption, the built-in endpoint, thenfrappe.client.get_listoverHas Role.The previous fallback queried
/api/resource/Has Rolewithout aparent, which Frappe rejects withPermissionErroron every version — it never worked. It now sendsparent=Useras Frappe requires. Note that even then it needs read permission on the User DocType, which by default only System Manager holds. If you depend on role checks, setrolesMethod, or move to the permission checks above. -
The session id is cached in memory instead of being read from secure storage on every request. That removes a Keychain/Keystore round trip per call and the race that overlapping requests could hit.
-
Diagnostics go through
dart:developerinstead ofprint(), and theavoid_print: falselint override has been removed. -
Base URLs are normalised, so a trailing slash no longer produces
//api/.... -
Minimum SDK is now Dart 3.8 / Flutter 3.32.
Deprecated #
hasActiveSession()→hasStoredSession(). The old name implied a live check it never performed. Both remain; the old one will be removed in 2.0.0.
Known dependency note #
flutter_secure_storage is pinned to ^9.2.4. Version 10+ pulls win32 ^6,
which requires Dart 3.10; bump to ^11.0.0 once you are on Flutter 3.35 or
newer.
1.2.1 #
- BREAKING CHANGE: Removed
checkIfUserIsAdmin()andgetIsAdmin()methods - NEW: Dynamic role-based access control (RBAC) system
- Added
getUserRoles()- Fetch and cache all user roles from server - Added
getCachedRoles()- Get cached roles without network call - Added
hasRole(roleName)- Check if user has a specific role (e.g., 'Stock Manager', 'HR Admin') - Added
hasAnyRole(roleNames)- Check if user has any of the specified roles - Added
hasAllRoles(roleNames)- Check if user has all of the specified roles - Added
clearCachedRoles()- Clear cached role data - Updated storage to cache user roles as JSON array instead of boolean admin flag
- Improved flexibility: Users can now check for any role dynamically
- Enhanced documentation with comprehensive RBAC examples
1.1.0 #
- RBAC: Added
NextRoleServiceto detect admin users (cached via storage).
1.0.1 #
- Fix: Remove deprecated author field from pubspec.yaml
1.0.0 #
- Initial release
- Login with username and password
- Logout functionality
- Password reset request
- Password change/update
- Session management with secure storage (SID)
- Automatic re-authentication using stored session
- Get logged user profile