Track Supabase auth events effortlessly with our guide. Set up your project, configure the database, create SQL triggers, and integrate your JS app for live monitoring.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Your Supabase Project
Step 2: Configure Database
auth_events
.id
: UUID, Primary Keyuser_id
: UUIDevent_type
: Texttimestamp
: Timestamp
Step 3: Setup Supabase Functions
CREATE OR REPLACE FUNCTION log_auth_event()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO auth_events (user_id, event_type, timestamp)
VALUES (NEW.id, TG_ARGV[0], NOW());
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
Step 4: Configure Triggers for Auth Events
-- Trigger on signup event
CREATE TRIGGER on_signup
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE FUNCTION log_auth_event('signup');
-- Trigger on delete event
CREATE TRIGGER on_delete
AFTER DELETE ON auth.users
FOR EACH ROW EXECUTE FUNCTION log_auth_event('delete');
Step 5: Access the Auth Event Data
auth_events
table.SELECT * FROM auth_events ORDER BY timestamp DESC;
Step 6: Integrate Event Tracking in Your Application
supabase
client in your project. If you haven't installed the client, use npm to install it:npm install @supabase/supabase-js
import { createClient } from '@supabase/supabase-js'
const supabaseUrl = 'your-supabase-url'
const supabaseAnonKey = 'your-anon-key'
const supabase = createClient(supabaseUrl, supabaseAnonKey)
// Sign up a new user
const signUpUser = async (email, password) => {
const { user, session, error } = await supabase.auth.signUp({
email: email,
password: password
})
if (error) console.error('Error signing up:', error)
else console.log('User signed up:', user)
}
// Delete a user
const deleteUser = async () => {
const user = supabase.auth.user()
if (user) {
const { error } = await supabase.auth.api.deleteUser(user.id, supabase.config.jwtSecret)
if (error) console.error('Error deleting user:', error)
else console.log('User deleted')
}
}
auth_events
table.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.