Commit 2490a3c
authored
fix(auth): return 403 instead of 500 for blocked sign-in/sign-up attempts (#4783)
The hooks.before middleware threw plain Errors for the four auth-policy
gates (registration disabled, email/password disabled, login allowlist,
blocked signup domains). better-auth surfaces an uncaught hook Error as a
generic 500 SERVER_ERROR, so users hitting these gates saw 'Failed to
create account' with no actionable message.
Throw APIError('FORBIDDEN', { message }) instead so the endpoints return a
clean 403 with the policy message, which the client surfaces directly.
Internal/server failures (email send, provider userinfo fetch, ID-token
parse) intentionally remain plain Errors so they continue to surface as
500s.1 parent 2ede04d commit 2490a3c
1 file changed
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
796 | | - | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
797 | 799 | | |
798 | 800 | | |
799 | 801 | | |
800 | 802 | | |
801 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
802 | 806 | | |
803 | 807 | | |
804 | 808 | | |
| |||
826 | 830 | | |
827 | 831 | | |
828 | 832 | | |
829 | | - | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
830 | 836 | | |
831 | 837 | | |
832 | 838 | | |
833 | 839 | | |
834 | 840 | | |
835 | | - | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
836 | 844 | | |
837 | 845 | | |
838 | 846 | | |
| |||
0 commit comments