Commit 5e7c1bb
Fix billing user status bug: users with credits no longer incorrectly shown as inactive
This fix addresses a critical bug where users who have been issued credits were
showing as inactive and unable to log in.
Changes:
- Modified 402 (Payment Required) handling in middleware to check if user has
active credits (input_tokens > 0 or output_tokens > 0 or is_active === true)
before redirecting to subscribe page
- Added safe property access using optional chaining for customer_session to
prevent runtime errors when response structure differs
- Users with active credits will no longer be incorrectly redirected to the
subscribe page
The root cause was that the middleware was redirecting ALL 402 responses to
the subscribe page without checking if the user actually had active credits.
Additionally, the code assumed responseJSON.detail.customer_session always
existed, which could cause runtime errors.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent e282124 commit 5e7c1bb
1 file changed
+12
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
197 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
198 | 206 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| 211 | + | |
209 | 212 | | |
210 | 213 | | |
211 | 214 | | |
| |||
0 commit comments