import { CanActivateFn } from '@angular/router';
import * as Parse from "parse";

export const authGuard: CanActivateFn = (route, state) => {
  // 检查当前本地存储中，是否有用户验证信息
  let userAuth = Parse.User.current();
  if (userAuth?.id) {
    return true;
  } else {
    // 暂时存储登录前用户所在页面
    let REDIRECT_URL = location.pathname;
    localStorage.setItem("REDIRECT_URL", REDIRECT_URL);
    if (location.pathname?.startsWith("/s0210402")) {
      location.href = "/s0210402/user/login"
    } else {
      location.href = "/user/login"
    }
    return false;
  }
};