import axios from "axios" ; import * as vscode from "vscode" ; import { instance } from "../service" ; export async function login ( context ) { const { account , accessToken } = await vscode . authentication . getSession ( "github" , [ "user:email" ] , { createIfNone : true , } ) ; if ( ! account ) { vscode . window . showWarningMessage ( "请检查github账户权限" ) ; return ; } const { data } = await axios ( { method : "get" , url : `https://api.github.com/user` , headers : { accept : "application/json" , Authorization : `token ${ accessToken }` , } , } ) ; if ( ! data ) { return ; } try { const res = await instance . post ( `/github/searchStudent` , { data } ) ; vscode . window . showInformationMessage ( `恭喜你登录成功` ) ; } catch ( e ) { console . log ( e ) ; } await context . globalState . update ( "login" , true ) ; return ; }