84 lines
2.9 KiB
Markdown
84 lines
2.9 KiB
Markdown
# 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 environment
|
|
- `test` - Test environment
|
|
- Any other value - Production environment
|
|
|
|
### Bypass Behavior
|
|
|
|
When running in `dev` or `test` environments:
|
|
|
|
1. **All Users**: The `isUserSubscribed()` method automatically returns `true` for all users
|
|
2. **Admin Users**: Admin and super-admin users get additional subscription management rules automatically assigned
|
|
3. **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:
|
|
|
|
```bash
|
|
# .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 class
|
|
- `src/services/admin/SubscriptionsService/SubscriptionsService.ts.ts` - Service layer bypass
|
|
- `src/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
|
|
|
|
1. **Faster Development**: No need to set up Stripe subscriptions for testing
|
|
2. **Simplified Testing**: Tests can run without subscription dependencies
|
|
3. **Production Safety**: No risk of accidentally bypassing subscriptions in production
|
|
4. **Clear Logging**: Easy to identify when bypasses are happening
|
|
5. **Maintainable**: Centralized configuration makes it easy to modify bypass behavior
|
|
|
|
## Security Considerations
|
|
|
|
- The bypass only works in `dev` and `test` 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:
|
|
|
|
1. Check that `ENV=dev` or `ENV=test` is set in your environment
|
|
2. Verify the environment variable is being loaded correctly
|
|
3. Check the logs for `[DEV/TEST]` messages to confirm bypass is working
|
|
4. Ensure the `SubscriptionBypass` service is being injected correctly |