Is there anyway to get the loading state of this v...
# javascript
t
Is there anyway to get the loading state of this variable ?
const { user } = Auth.useUser();
b
The way I handle this in Angular is to create a behavior subject and subscribe to it.
For example:
public user = new BehaviorSubject<User>(null);
Here's my entire code:
Copy code
public user = new BehaviorSubject<User>(null);
  private _user: User = null;

  constructor() {
    // Try to recover our user session
    this.loadUser();
    supabase.auth.onAuthStateChange(async (event, session) => {
      if (event === 'SIGNED_IN') {
        this._user = session.user;
        this.user.next(session.user);
      } else {
        this._user = null;
        this.user.next(null);
      }
    });
  }
  private async loadUser() {
    const user = supabase.auth.user();
    if (user) {
      this._user = user;
      this.user.next(user);
    } 
  };