auth.ts 985 Bytes
import { AuthorizedState } from '@/store/modules/authorized/type';
import FileSaver from 'file-saver';
import axios from 'axios';

interface LoginData {
  type: 'email' | 'phone';
  email?: string;
  password?: string;
  phone?: string;
  code?: string;
  area?: string;
}

export async function downloadFile(url: string, fileName: string) {
  FileSaver.saveAs(`${url}`, fileName + url.substring(url.lastIndexOf('.')));

  // ?response-content-type=Blob
}

export default class useAuthApi {
  static async login(data: LoginData) {
    return axios
      .post<{ access_token: string; refresh_token: string; nick_name: string }>('login', data)
      .then((res) => Promise.resolve(res.data));
  }

  static async info() {
    return axios.get<{ user: AuthorizedState; permissions: string[] }>('auth/info').then((res) => Promise.resolve(res.data));
  }

  static changePwd(data: { password: string; password_confirmation: string }) {
    return axios.put('auth/change-pwd', data);
  }
}