Flairtable Docs

Auth changed listener

Table of Contents

The SDK offers a way to react to changes in the auth state by using the onAuthChanged function. Because the SDK had very limited side effects, the registered listener is only subscribed to one instance of Flairtable.

Usage

To subscribe to auth changes, use the onAuthChange function on a Flairtable instance.

You'll need to supply a callback function as a parameter which is invoked every time a user signs in, signs up, or signs out.

The onAuthChange function returns an unsubscribe function. If you invoke this function you unsubscribe the listener from any future events.

Code samples

const flairtable = Flairtable({apiKey: 'YOUR_API_KEY'});
// subscribe to auth changes
const unsubscribe = flairtable.onAuthChange((user) => {
if (user){
console.log(`${user.email} just signed in`);
return;
}
// no user object present, AKA signed out.
console.log('no user signed in')
});
// unsubscribe to prevent any future events triggering the function
unsubscribe();