diff --git a/web/components/Registration/ReplaceCheck.vue b/web/components/Registration/ReplaceCheck.vue index c662937c7..2ce01489e 100644 --- a/web/components/Registration/ReplaceCheck.vue +++ b/web/components/Registration/ReplaceCheck.vue @@ -7,10 +7,10 @@ import { storeToRefs } from 'pinia'; import { DOCS_REGISTRATION_REPLACE_KEY } from '~/helpers/urls'; import BrandLoadingWhite from '~/components/Brand/LoadingWhite.vue'; -import { useReplaceCheckStore } from '~/store/replaceCheck'; +import { useReplaceRenewStore } from '~/store/replaceRenew'; -const replaceCheckStore = useReplaceCheckStore(); -const { status, statusOutput } = storeToRefs(replaceCheckStore); +const replaceRenewStore = useReplaceRenewStore(); +const { status, statusOutput } = storeToRefs(replaceRenewStore); defineProps<{ t: any; @@ -21,10 +21,10 @@ defineProps<{
{ } if (guid.value && keyfile.value) { + // automatically check for replacement and renewal eligibility…will prompt user if eligible for a renewal / key re-roll for legacy keys + replaceRenewCheckStore.check(); + + // automatically check for OS updates for global notifications updateOsStore.checkForUpdate({ cache: true, guid: guid.value, @@ -107,7 +113,7 @@ onBeforeMount(() => { osVersion: osVersion.value, }); } else { - console.warn('A valid keyfile and USB Flash boot device are required to check for updates.'); + console.warn('A valid keyfile and USB Flash boot device are required to check for key renewals, key replacement eligibiliy, and OS update availability.'); } }); diff --git a/web/store/replaceCheck.ts b/web/store/replaceRenew.ts similarity index 80% rename from web/store/replaceCheck.ts rename to web/store/replaceRenew.ts index 788e90960..99420d301 100644 --- a/web/store/replaceCheck.ts +++ b/web/store/replaceRenew.ts @@ -6,7 +6,7 @@ import { import { defineStore, createPinia, setActivePinia } from 'pinia'; import type { WretchError } from 'wretch'; -import { validateGuid, type ValidateGuidPayload } from '~/composables/services/keyServer'; +import { validateGuid, type ValidateGuidResponse } from '~/composables/services/keyServer'; import { useServerStore } from '~/store/server'; import type { UiBadgeProps } from '~/types/ui/badge'; /** @@ -21,7 +21,7 @@ export interface UiBadgePropsExtended extends UiBadgeProps { export const REPLACE_CHECK_LOCAL_STORAGE_KEY = 'unraidReplaceCheck'; -export const useReplaceCheckStore = defineStore('replaceCheck', () => { +export const useReplaceRenewStore = defineStore('replaceRenewCheck', () => { const serverStore = useServerStore(); const guid = computed(() => serverStore.guid); @@ -34,7 +34,7 @@ export const useReplaceCheckStore = defineStore('replaceCheck', () => { cause?: unknown; } | null>(null); const status = ref<'checking' | 'eligible' | 'error' | 'ineligible' | 'ready'>(guid.value ? 'ready' : 'error'); - const statusOutput = computed((): UiBadgePropsExtended => { + const statusOutput = computed((): UiBadgePropsExtended | undefined => { // text values are translated in the component switch (status.value) { case 'eligible': @@ -55,10 +55,10 @@ export const useReplaceCheckStore = defineStore('replaceCheck', () => { icon: ShieldExclamationIcon, text: error.value?.message || 'Unknown error', }; - default: return null; + default: return undefined; } }); - const validationResponse = ref( + const validationResponse = ref( sessionStorage.getItem(REPLACE_CHECK_LOCAL_STORAGE_KEY) ? JSON.parse(sessionStorage.getItem(REPLACE_CHECK_LOCAL_STORAGE_KEY) as string) : undefined @@ -83,15 +83,25 @@ export const useReplaceCheckStore = defineStore('replaceCheck', () => { * this should happen automatically when the web components are mounted… * account.unraid.net will do a similar thing` */ - const response: ValidateGuidPayload = await validateGuid({ + const response: ValidateGuidResponse = await validateGuid({ guid: guid.value, keyfile: keyfile.value, }).json(); - /** @todo fix type issue */ + console.log('[ReplaceCheck.check] response', response); + status.value = response?.replaceable ? 'eligible' : 'ineligible'; + if (status.value === 'eligible' || status.value === 'ineligible') { sessionStorage.setItem(REPLACE_CHECK_LOCAL_STORAGE_KEY, JSON.stringify(response)); } + + /** + * @todo if response?.hasNewerKeyfile then we need to prompt the user to replace the keyfile. This will be a separate request to the key server. + * @todo we don't want to automatically make this request for the new keyfile. + */ + if (response?.hasNewerKeyfile) { + console.log('[ReplaceCheck.check] hasNewerKeyfile'); + } } catch (err) { const catchError = err as WretchError; status.value = 'error';