Skip to content

v0.2.6

Choose a tag to compare

@pillowsoft pillowsoft released this 05 Nov 18:28
· 12 commits to main since this release

🎯 New Feature: Session Token Access API

Added Session Token Access

  • βœ… Added sessionToken getter - Preferred name for accessing the current user's session token
  • βœ… Added getSessionToken() method - Method-based access for those who prefer method calls
  • βœ… Enhanced API clarity - Clear naming for use in API authentication headers
  • βœ… Full backward compatibility - Existing authToken getter continues to work unchanged

Use Cases

  • βœ… API authentication - Use session token in Authorization: Bearer <token> headers
  • βœ… Proxy authentication - Pass token to Cloudflare Workers or other proxies for user validation
  • βœ… Cost tracking - Track API usage per user by validating tokens server-side

API Examples

// Getter-based access (preferred)
final token = db.auth.sessionToken;
if (token != null) {
  headers['Authorization'] = 'Bearer $token';
}

// Method-based access
final token = db.auth.getSessionToken();
if (token != null) {
  headers['Authorization'] = 'Bearer $token';
}

// Backward compatible - existing code still works
final token = db.auth.authToken; // Still available

Technical Details

  • βœ… Same underlying token - All three methods (sessionToken, getSessionToken(), authToken) return the same JWT token
  • βœ… Null when not authenticated - Returns null when user is not signed in
  • βœ… Comprehensive test coverage - Added 7 new tests for session token access

πŸ“š Impact

This release addresses a common user request for accessing the session token for use in API authentication. The new API provides clearer naming while maintaining full backward compatibility with the existing authToken getter.