mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-11-27 14:22:41 +08:00
Refresh token after changing account
This commit is contained in:
@@ -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;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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 = '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user