feat: verify token and user

This commit is contained in:
Levi Yan
2025-03-23 17:16:35 +08:00
parent 4188072065
commit fe52e2bf8f

View File

@@ -17,6 +17,33 @@ export default class DevstarAPIHandler {
}
}
public async verifyToken(token: string, username: string): Promise<string> {
return new Promise(async (resolve) => {
fetch(this.devstarDomain + `/api/devcontainer/user`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + token
}
})
.then(response => {
response.json().then(async data => {
if (response.ok) {
if (data.username == username) {
resolve('ok')
} else {
utils.showErrorNotification('Token与用户名不符')
console.error('Token: ', token, ' Username: ', username)
}
} else {
utils.showErrorNotification('Token错误')
console.error('Error token: ', token)
}
})
})
})
}
// 上传公钥
public async uploadUserPublicKey(user: User): Promise<string> {
return new Promise(async (resolve) => {
@@ -55,7 +82,7 @@ export default class DevstarAPIHandler {
console.error(error);
});
})
})
}
}