2.9 KiB
2.9 KiB
Subscription Bypass for Development/Test Environments
Overview
The subscription system has been modified to automatically bypass subscription checks in development and test environments. This allows developers to work without needing to set up complex subscription data or Stripe integrations during development.
How it Works
Environment Detection
The system automatically detects the environment using the ENV
environment variable:
dev
- Development environmenttest
- Test environment- Any other value - Production environment
Bypass Behavior
When running in dev
or test
environments:
- All Users: The
isUserSubscribed()
method automatically returnstrue
for all users - Admin Users: Admin and super-admin users get additional subscription management rules automatically assigned
- Logging: All bypass actions are logged with
[DEV/TEST]
prefix for easy identification
Production Behavior
In production environments (any ENV value other than dev
or test
):
- Subscription checks work normally
- No bypassing occurs
- All existing subscription logic is preserved
Configuration
Environment Variables
Set the ENV
environment variable in your environment files:
# .env.dev
ENV=dev
# .env.test
ENV=test
# .env.prod
ENV=prod
Code Structure
The bypass logic is centralized in:
src/common/config/SubscriptionBypass.ts
- Main configuration classsrc/services/admin/SubscriptionsService/SubscriptionsService.ts.ts
- Service layer bypasssrc/app/api/idnot/UserController.ts
- Controller layer bypass
Logging
When subscription checks are bypassed, you'll see logs like:
[DEV/TEST] Bypassing subscription check for user abc123 in office xyz789 (ENV: dev) - isUserSubscribed method
[DEV/TEST] Bypassing subscription check for user abc123 in office xyz789 (ENV: dev) - admin user login
Benefits
- Faster Development: No need to set up Stripe subscriptions for testing
- Simplified Testing: Tests can run without subscription dependencies
- Production Safety: No risk of accidentally bypassing subscriptions in production
- Clear Logging: Easy to identify when bypasses are happening
- Maintainable: Centralized configuration makes it easy to modify bypass behavior
Security Considerations
- The bypass only works in
dev
andtest
environments - Production environments are completely unaffected
- All bypass actions are logged for audit purposes
- The bypass is implemented at the service layer, ensuring consistency across the application
Troubleshooting
If subscription checks are still failing in development:
- Check that
ENV=dev
orENV=test
is set in your environment - Verify the environment variable is being loaded correctly
- Check the logs for
[DEV/TEST]
messages to confirm bypass is working - Ensure the
SubscriptionBypass
service is being injected correctly