mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add user information retrieval endpoint and update token management
This commit is contained in:
@@ -63,12 +63,16 @@ class Network {
|
||||
if (!app.token) {
|
||||
return;
|
||||
}
|
||||
const res = await this.getUserInfo(app.user!.username)
|
||||
const res = await this.getMe()
|
||||
if (!res.success && res.message.includes("Invalid token")) {
|
||||
app.token = null;
|
||||
app.user = null;
|
||||
app.saveData();
|
||||
window.location.reload();
|
||||
} else {
|
||||
app.user = res.data!;
|
||||
app.token = res.data!.token;
|
||||
app.saveData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +109,19 @@ class Network {
|
||||
}
|
||||
}
|
||||
|
||||
async getMe(): Promise<Response<UserWithToken>> {
|
||||
try {
|
||||
const response = await axios.get(`${this.apiBaseUrl}/user/me`)
|
||||
return response.data
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
return {
|
||||
success: false,
|
||||
message: e.toString(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getUserInfo(username: string): Promise<Response<User>> {
|
||||
try {
|
||||
const response = await axios.get(`${this.apiBaseUrl}/user/info`, {
|
||||
|
Reference in New Issue
Block a user