JavaScript: Listen to auth events

Examples

Listen to auth changes

supabase.auth.onAuthStateChange((event, session) => \{
  console.log(event, session)
\})

Listen to sign in

supabase.auth.onAuthStateChange((event, session) => \{
  if (event == 'SIGNED_IN') console.log('SIGNED_IN', session)
\})

Listen to sign out

supabase.auth.onAuthStateChange((event, session) => \{
  if (event == 'SIGNED_OUT') console.log('SIGNED_OUT', session)
\})

Listen to token refresh

supabase.auth.onAuthStateChange((event, session) => \{
  if (event == 'TOKEN_REFRESHED') console.log('TOKEN_REFRESHED', session)
\})

Listen to user updates

supabase.auth.onAuthStateChange((event, session) => \{
  if (event == 'USER_UPDATED') console.log('USER_UPDATED', session)
\})

Listen to user deleted

supabase.auth.onAuthStateChange((event, session) => \{
  if (event == 'USER_DELETED') console.log('USER_DELETED', session)
\})

Listen to password recovery events

supabase.auth.onAuthStateChange((event, session) => \{
  if (event == 'PASSWORD_RECOVERY') console.log('PASSWORD_RECOVERY', session)
\})