You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
message = "Failed to send magic link: failed to make magiclink request: Error sending magic link"
14
14
15
15
[[errors]]
16
-
message = "Failed to delete user: Database error deleting user"
16
+
http_status_code = 500
17
+
code = "unexpected_failure"
18
+
message = "Database error saving new user"
17
19
18
20
[[errors]]
19
-
message = "Failed to create user: Database error creating new user"
21
+
http_status_code = 500
22
+
code = "unexpected_failure"
23
+
message = "Failed to create user"
20
24
21
25
[[errors]]
22
26
http_status_code = 500
23
-
message = "Database error saving new user"
27
+
code = "unexpected_failure"
28
+
message = "Database error creating new user"
29
+
30
+
[[errors]]
31
+
http_status_code = 500
32
+
code = "unexpected_failure"
33
+
message = "Failed to delete user"
34
+
35
+
[[errors]]
36
+
http_status_code = 500
37
+
code = "unexpected_failure"
38
+
message = "Database error deleting user"
39
+
40
+
[[errors]]
41
+
http_status_code = 500
42
+
code = "unexpected_failure"
43
+
message = "Error updating user"
44
+
45
+
[[errors]]
46
+
http_status_code = 500
47
+
code = "unexpected_failure"
48
+
message = "Database error updating user"
49
+
24
50
---
25
51
26
-
## PROBLEM
52
+
These error are normal a side effect of issues in your custom user management logic. This can cause errors that return HTTP `500` status codes with a of code `unexpected_failure` and one of the following error messages
53
+
54
+
- Failed to create user: Database error creating new user
55
+
- Failed to update user: Error updating user
56
+
- Failed to delete user: Database error deleting user
57
+
- Database error updating user
58
+
- Database error saving new user
59
+
60
+
## Debugging this error
61
+
62
+
-[Auth logs](/dashboard/project/_/logs/auth-logs): as the error relates to [Auth](/docs/guides/auth) users
63
+
-[Postgres logs](/dashboard/project/_/logs/postgres-logs): for raw error logs related to database
64
+
65
+
## Common causes of this error:
66
+
67
+
- Trigger/trigger function setup on the `auth.users` table
68
+
- A constraint on the `auth.users` table which isn't being met
69
+
- You are using Prisma and it has broken all the permissions on the `auth.users` table
27
70
28
-
### Receiving the following or _similar_error messages in the Dashboard when managing users.
71
+
##Example error messages
29
72
30
-
> ... Database error
31
-
> ... Error sending
73
+
Use the hints provided in the error message to fix issues in your custom user management logic.
**Constraint related error message** - [Solution for constraint related issues](#solution-constraint)
82
+
83
+
```
84
+
ERROR: 23503: update or delete on table "users" violates foreign key constraint "profiles_id_fkey" on table "profiles"
85
+
DETAIL: Key (id)=(7428a53c-75b7-4531-9ae9-1567d9c4ac0a) is still referenced from table "profiles".
86
+
```
87
+
88
+
**Missing column**
89
+
90
+
```
91
+
ERROR: column \"updated_at\" of relation \"profiles\" does not exist (SQLSTATE 42703)
92
+
```
93
+
94
+
**Broken search path / incorrect name** - [42P01 related solution](docs/guides/troubleshooting/resolving-42p01-relation-does-not-exist-error-W4_9-V)
47
95
48
-
> Database error ...
96
+
```
97
+
failed to close prepared statement: ERROR: current transaction is aborted, commands ignored until end of transaction block (SQLSTATE 25P02): ERROR: relation \"public.profiles\" does not exist (SQLSTATE 42P01)
98
+
```
99
+
100
+
---
101
+
102
+
## Solution for constraint related issues [#solution-constraint]
- Check for foreign/primary key relationship between the `auth.users` table and another table
105
+
- Then ALTER the [behavior](https://stackoverflow.com/questions/5383612/setting-up-table-relations-what-do-cascade-set-null-and-restrict-do) of the relationship and recreate it with a less [restrictive constraint](https://stackoverflow.com/questions/3359329/how-to-change-the-foreign-key-referential-action-behavior).
106
+
- If this is related to deleting records, review the [Cascade Deletes doc](/docs/guides/database/postgres/cascade-deletes) for possible approaches (e.g. using `CASCADE` / `SET NULL`)
55
107
56
-
## SOLUTION 1 (trigger related)
108
+
---
57
109
58
-
Check if the auth schema contains any triggers in the [Dashboard's trigger section](/dashboard/project/_/database/triggers). Remove all triggers by dropping their functions with a CASCADE modifier:
110
+
## Solution for trigger related issues [#solution-trigger]
111
+
112
+
Supabase Auth uses your project's database to store user data. It relies on the `auth` schema, and Supabase restricts access to the `auth` schema to prevent unintended custom changes that could break the functionality of the Auth service.
113
+
114
+
Check if the `auth` schema contains any triggers in the [Dashboard's trigger section](/dashboard/project/_/database/triggers?schema=auth).
115
+
116
+
1. Identify related functions using `security invoker` from the [Dashboard's function section](/dashboard/project/_/database/functions)
117
+
2. Remove all triggers by dropping their functions with a CASCADE modifier shown below (This command still works because the `postgres` role has the ownership of the function, and the `CASCADE` clause will drop the trigger indirectly.)
59
118
60
119
```sql
61
120
DROPFUNCTION<function name>() CASCADE;
@@ -64,8 +123,10 @@ DROP FUNCTION <function name>() CASCADE;
64
123
-- DROP TRIGGER <trigger_name> on auth.<table_name>;
65
124
```
66
125
67
-
Then recreate the functions with a [security definer](/docs/guides/database/functions#security-definer-vs-invoker) modifier before recreating the triggers.
126
+
3. Recreate the functions with a [security definer](/docs/guides/database/functions#security-definer-vs-invoker) modifier
127
+
4. Recreate the triggers
68
128
129
+
**Example function and trigger using security definer**
69
130
The [SQL Editor](/dashboard/project/_/sql/) contains a template for [User Management](/dashboard/project/_/sql/quickstarts). Within it, there is a working example of how to setup triggers with security definer that may be worth referencing:
for each row execute procedure public.handle_new_user();
95
158
```
96
159
97
-
### EXPLANATION
160
+
### Explanation
98
161
99
-
One of the most common design patterns in Supabase is to add a trigger to the `auth.users` table. The database role managing authentication (supabase_auth_admin) only has the necessary permissions it needs to perform its duties. So, when a trigger operated by the supabase_auth_admin interacts outside the auth schema, it causes a permission error.
162
+
One of the most common design patterns in Supabase is to add a trigger to the `auth.users` table. The database role managing authentication (`supabase_auth_admin`) only has the necessary permissions it needs to perform its duties. So, when a trigger operated by the `supabase_auth_admin` interacts outside the auth schema, it causes a permission error.
100
163
101
164
A security definer function retains the privileges of the database user that created it. As long as it is the `postgres` role, your auth triggers should be able to engage with outside tables.
102
-
103
-
## SOLUTION 2 (constraint related)
104
-
105
-
If you did not create a trigger, check if you created a foreign/primary key relationship between the auth.users table and another table. If you did, then ALTER the [behavior](https://stackoverflow.com/questions/5383612/setting-up-table-relations-what-do-cascade-set-null-and-restrict-do) of the relationship and recreate it with a less [restrictive constraint](https://stackoverflow.com/questions/3359329/how-to-change-the-foreign-key-referential-action-behavior).
0 commit comments