mirror of
https://github.com/unraid/api.git
synced 2026-01-01 06:01:18 -06:00
fix: sign out doesn't work (#1486)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved handling of Connect account sign-in and sign-out with persistent mutation instances for better status updates and error reporting. * **Chores** * Expanded allowed command patterns in configuration for development, build, and testing tasks. * **Tests** * Enhanced mutation mocks in component tests to increase test reliability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -2,7 +2,14 @@
|
|||||||
"permissions": {
|
"permissions": {
|
||||||
"allow": [
|
"allow": [
|
||||||
"Bash(rg:*)",
|
"Bash(rg:*)",
|
||||||
"Bash(find:*)"
|
"Bash(find:*)",
|
||||||
|
"Bash(pnpm codegen:*)",
|
||||||
|
"Bash(pnpm dev:*)",
|
||||||
|
"Bash(pnpm build:*)",
|
||||||
|
"Bash(pnpm test:*)",
|
||||||
|
"Bash(grep:*)",
|
||||||
|
"Bash(pnpm type-check:*)",
|
||||||
|
"Bash(pnpm lint:*)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"enableAllProjectMcpServers": false
|
"enableAllProjectMcpServers": false
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ vi.mock('@vue/apollo-composable', () => ({
|
|||||||
onResult: vi.fn(),
|
onResult: vi.fn(),
|
||||||
onError: vi.fn(),
|
onError: vi.fn(),
|
||||||
}),
|
}),
|
||||||
|
useMutation: () => ({
|
||||||
|
mutate: vi.fn(),
|
||||||
|
onDone: vi.fn(),
|
||||||
|
onError: vi.fn(),
|
||||||
|
}),
|
||||||
provideApolloClient: vi.fn(),
|
provideApolloClient: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ vi.mock('@vue/apollo-composable', () => ({
|
|||||||
onResult: vi.fn(),
|
onResult: vi.fn(),
|
||||||
onError: vi.fn(),
|
onError: vi.fn(),
|
||||||
}),
|
}),
|
||||||
|
useMutation: () => ({
|
||||||
|
mutate: vi.fn(),
|
||||||
|
onDone: vi.fn(),
|
||||||
|
onError: vi.fn(),
|
||||||
|
}),
|
||||||
provideApolloClient: vi.fn(),
|
provideApolloClient: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,59 @@ export const useAccountStore = defineStore('account', () => {
|
|||||||
accountActionStatus.value = 'waiting';
|
accountActionStatus.value = 'waiting';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Initialize mutations during store setup to maintain Apollo context
|
||||||
|
const { mutate: signOutMutation, onDone: onSignOutDone, onError: onSignOutError } = useMutation(CONNECT_SIGN_OUT);
|
||||||
|
const { mutate: signInMutation, onDone: onSignInDone, onError: onSignInError } = useMutation(CONNECT_SIGN_IN);
|
||||||
|
|
||||||
|
// Handle sign out mutation results
|
||||||
|
onSignOutDone((res) => {
|
||||||
|
console.debug('[connectSignOutMutation]', res);
|
||||||
|
accountActionStatus.value = 'success';
|
||||||
|
setQueueConnectSignOut(false); // reset
|
||||||
|
});
|
||||||
|
|
||||||
|
onSignOutError((error) => {
|
||||||
|
logErrorMessages(error);
|
||||||
|
accountActionStatus.value = 'failed';
|
||||||
|
errorsStore.setError({
|
||||||
|
heading: 'Failed to update Connect account configuration',
|
||||||
|
message: error.message,
|
||||||
|
level: 'error',
|
||||||
|
ref: 'connectSignOutMutation',
|
||||||
|
type: 'account',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle sign in mutation results
|
||||||
|
onSignInDone((res) => {
|
||||||
|
if (res.data?.connectSignIn) {
|
||||||
|
accountActionStatus.value = 'success';
|
||||||
|
setConnectSignInPayload(undefined); // reset
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accountActionStatus.value = 'failed';
|
||||||
|
errorsStore.setError({
|
||||||
|
heading: 'unraid-api failed to update Connect account configuration',
|
||||||
|
message: 'Sign In mutation unsuccessful',
|
||||||
|
level: 'error',
|
||||||
|
ref: 'connectSignInMutation',
|
||||||
|
type: 'account',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
onSignInError((error) => {
|
||||||
|
logErrorMessages(error);
|
||||||
|
accountActionStatus.value = 'failed';
|
||||||
|
errorsStore.setError({
|
||||||
|
heading: 'unraid-api failed to update Connect account configuration',
|
||||||
|
message: error.message,
|
||||||
|
level: 'error',
|
||||||
|
ref: 'connectSignInMutation',
|
||||||
|
type: 'account',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (unraidApiClient.value && connectSignInPayload.value) {
|
if (unraidApiClient.value && connectSignInPayload.value) {
|
||||||
// connectSignInMutation();
|
// connectSignInMutation();
|
||||||
@@ -258,7 +311,7 @@ export const useAccountStore = defineStore('account', () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const connectSignInMutation = async () => {
|
const connectSignInMutation = () => {
|
||||||
if (
|
if (
|
||||||
!connectSignInPayload.value ||
|
!connectSignInPayload.value ||
|
||||||
(connectSignInPayload.value &&
|
(connectSignInPayload.value &&
|
||||||
@@ -271,83 +324,21 @@ export const useAccountStore = defineStore('account', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
accountActionStatus.value = 'updating';
|
accountActionStatus.value = 'updating';
|
||||||
const {
|
|
||||||
mutate: signInMutation,
|
return signInMutation({
|
||||||
onDone,
|
input: {
|
||||||
onError,
|
apiKey: connectSignInPayload.value.apiKey,
|
||||||
} = await useMutation(CONNECT_SIGN_IN, {
|
userInfo: {
|
||||||
variables: {
|
email: connectSignInPayload.value.email,
|
||||||
input: {
|
preferred_username: connectSignInPayload.value.preferred_username,
|
||||||
apiKey: connectSignInPayload.value.apiKey,
|
|
||||||
userInfo: {
|
|
||||||
email: connectSignInPayload.value.email,
|
|
||||||
preferred_username: connectSignInPayload.value.preferred_username,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
signInMutation();
|
|
||||||
|
|
||||||
onDone((res) => {
|
|
||||||
if (res.data?.connectSignIn) {
|
|
||||||
accountActionStatus.value = 'success';
|
|
||||||
setConnectSignInPayload(undefined); // reset
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
accountActionStatus.value = 'failed';
|
|
||||||
errorsStore.setError({
|
|
||||||
heading: 'unraid-api failed to update Connect account configuration',
|
|
||||||
message: 'Sign In mutation unsuccessful',
|
|
||||||
level: 'error',
|
|
||||||
ref: 'connectSignInMutation',
|
|
||||||
type: 'account',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
onError((error) => {
|
|
||||||
logErrorMessages(error);
|
|
||||||
accountActionStatus.value = 'failed';
|
|
||||||
errorsStore.setError({
|
|
||||||
heading: 'unraid-api failed to update Connect account configuration',
|
|
||||||
message: error.message,
|
|
||||||
level: 'error',
|
|
||||||
ref: 'connectSignInMutation',
|
|
||||||
type: 'account',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const connectSignOutMutation = async () => {
|
const connectSignOutMutation = () => {
|
||||||
accountActionStatus.value = 'updating';
|
accountActionStatus.value = 'updating';
|
||||||
// @todo is this still needed here with the change to a mutation?
|
return signOutMutation();
|
||||||
// if (!serverStore.registered && accountAction.value && !accountAction.value?.user) {
|
|
||||||
// accountActionHide.value = true;
|
|
||||||
// accountActionStatus.value = 'success';
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const { mutate: signOutMutation, onDone, onError } = await useMutation(CONNECT_SIGN_OUT);
|
|
||||||
|
|
||||||
signOutMutation();
|
|
||||||
|
|
||||||
onDone((res) => {
|
|
||||||
console.debug('[connectSignOutMutation]', res);
|
|
||||||
accountActionStatus.value = 'success';
|
|
||||||
setQueueConnectSignOut(false); // reset
|
|
||||||
});
|
|
||||||
|
|
||||||
onError((error) => {
|
|
||||||
logErrorMessages(error);
|
|
||||||
accountActionStatus.value = 'failed';
|
|
||||||
errorsStore.setError({
|
|
||||||
heading: 'Failed to update Connect account configuration',
|
|
||||||
message: error.message,
|
|
||||||
level: 'error',
|
|
||||||
ref: 'connectSignOutMutation',
|
|
||||||
type: 'account',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setAccountAction = (action: ExternalSignIn | ExternalSignOut) => {
|
const setAccountAction = (action: ExternalSignIn | ExternalSignOut) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user