import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { CloudUser } from '../../lib/ncloud';

@Injectable({
  providedIn: 'root'
})
export class AuthGuard implements CanActivate {
  user = new CloudUser();

  constructor(private router: Router) {}

  async canActivate(): Promise<boolean> {
    const currentUser = await this.user.current();
    if (!currentUser) {
      this.router.navigate(['/tabs/tab5']);
      return false;
    }
    return true;
  }
}