🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
16 lines
504 B
PL/PgSQL
16 lines
504 B
PL/PgSQL
-- Function to handle user signup and create user record
|
|
CREATE OR REPLACE FUNCTION handle_auth_signup()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
-- Create user record in users table
|
|
INSERT INTO users (id, email, name)
|
|
VALUES (NEW.id, NEW.email, NEW.raw_user_meta_data->>'name');
|
|
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql SECURITY DEFINER;
|
|
|
|
-- Trigger to run the function when a user signs up
|
|
CREATE TRIGGER on_auth_user_created
|
|
AFTER INSERT ON auth.users
|
|
FOR EACH ROW EXECUTE FUNCTION handle_auth_signup(); |