Refresh token after changing account

This commit is contained in:
Rewrite0
2023-05-28 13:08:45 +08:00
parent e3fa8c543f
commit 278f95421b
2 changed files with 14 additions and 10 deletions

View File

@@ -33,15 +33,14 @@ export const apiAuth = {
async update(username: string, password: string) {
const message = useMessage();
if (password.length < 8) {
message.error('密码至少8个字符!');
message.error('Password must be at least 8 characters long!');
} else {
const { data } = await axios.post<Update>('api/v1/auth/update', {
username,
password,
});
return data.message === 'update success';
return data;
}
},
};

View File

@@ -61,14 +61,19 @@ export const useAuth = createSharedComposable(() => {
};
const update = async () => {
const res = await apiAuth.update(user.username, user.password);
if (res) {
message.success('Update Success!');
clearUser();
} else if (res === false) {
try {
const res = await apiAuth.update(user.username, user.password);
if (res?.message === 'update success') {
auth.value = `${res.token_type} ${res.access_token}`;
message.success('Update Success!');
clearUser();
} else {
message.error('Update Failed!');
user.password = '';
}
} catch (error) {
message.error('Update Failed!');
} else {
user.password = '';
}
};