limiting oauth to specific emails #5088
-
questionEnabling say, Google OAuth for an app backed by Supabase would mean everyone with a google account will be able to authenticate. Is is possible to limit auth to users from possible solutions
Is it possible to configure the GoTrue component in Supabase directly to achieve this? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
This should work but I've not done it. You can create a trigger function on "before" for the auth.users table on insert/update. In the trigger function check the domain part of the email against the valid domain string and if not valid, return null else return new. |
Beta Was this translation helpful? Give feedback.
-
|
Hey! ~4 years late but now you could also use a "before user created" auth hook: The Postgres function attached to the hook will be called by a principal with the role of |
Beta Was this translation helpful? Give feedback.
This should work but I've not done it.
You can create a trigger function on "before" for the auth.users table on insert/update. In the trigger function check the domain part of the email against the valid domain string and if not valid, return null else return new.
(New is the record passed in to the trigger function and must be returned in order for the insert/update to complete when using the before option on trigger.)
You might still want to do a user friendly check in the app signup screen, but this insures they don't get to sign in if they bypass your code.