Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to implement a callback when auth state changes in supabase

I’m struggling to implement an idea. If a user is logged in, I want to show a hidden div.

For example in firebase I can do this:

firebase.auth.signInAnonymessly()

// Detecting if the auth state changed
firebase.auth.onAuthStateChanged((user) => {
  // If a user exists show him a hidden div
  if(user) {
    HiddenDiv.style.display = block
  }
})

I want to do this but in supabase

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I searched the supabase docs and didn’t find anything pls help

>Solution :

There’s a method in Supabase that works in almost the same way as Firebases’ onAuthStateChange, here’s a reference to the docs.

supabase.auth.onAuthStateChange((event, session) => {
  console.log(event, session)
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading