mirror of
https://github.com/modrinth/code.git
synced 2026-07-31 21:26:40 +00:00
fix: pats page code invalidating in same session (#6924)
This commit is contained in:
@@ -62,7 +62,13 @@
|
|||||||
<label for="pat-expires">
|
<label for="pat-expires">
|
||||||
<span class="font-semibold">{{ formatMessage(createModalMessages.expiresLabel) }}</span>
|
<span class="font-semibold">{{ formatMessage(createModalMessages.expiresLabel) }}</span>
|
||||||
</label>
|
</label>
|
||||||
<DatePicker id="pat-expires" v-model="expires" show-today wrapper-class="w-full" />
|
<DatePicker
|
||||||
|
id="pat-expires"
|
||||||
|
v-model="expires"
|
||||||
|
:min-date="minimumPatExpiry"
|
||||||
|
show-today
|
||||||
|
wrapper-class="w-full"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ml-auto mt-4 flex gap-2">
|
<div class="ml-auto mt-4 flex gap-2">
|
||||||
@@ -73,13 +79,13 @@
|
|||||||
</button>
|
</button>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
<ButtonStyled v-if="editPatId !== null" color="brand">
|
<ButtonStyled v-if="editPatId !== null" color="brand">
|
||||||
<button :disabled="loading || !name || !expires" @click="editPat">
|
<button :disabled="loading || !name || !isExpiryInFuture" @click="editPat">
|
||||||
<SaveIcon />
|
<SaveIcon />
|
||||||
{{ formatMessage(commonMessages.saveChangesButton) }}
|
{{ formatMessage(commonMessages.saveChangesButton) }}
|
||||||
</button>
|
</button>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
<ButtonStyled v-else color="brand">
|
<ButtonStyled v-else color="brand">
|
||||||
<button :disabled="loading || !name || !expires" @click="createPat">
|
<button :disabled="loading || !name || !isExpiryInFuture" @click="createPat">
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
{{ formatMessage(createModalMessages.action) }}
|
{{ formatMessage(createModalMessages.action) }}
|
||||||
</button>
|
</button>
|
||||||
@@ -123,8 +129,8 @@
|
|||||||
<strong>{{ pat.name }}</strong>
|
<strong>{{ pat.name }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<template v-if="pat.access_token">
|
<template v-if="createdPatTokens[pat.id] || pat.access_token">
|
||||||
<CopyCode :text="pat.access_token" />
|
<CopyCode :text="createdPatTokens[pat.id] || pat.access_token" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<span v-tooltip="pat.last_used ? formatDateTime(pat.last_used) : null">
|
<span v-tooltip="pat.last_used ? formatDateTime(pat.last_used) : null">
|
||||||
@@ -331,12 +337,17 @@ useHead({
|
|||||||
const data = useNuxtApp()
|
const data = useNuxtApp()
|
||||||
const { scopesToLabels } = useScopes()
|
const { scopesToLabels } = useScopes()
|
||||||
const patModal = ref()
|
const patModal = ref()
|
||||||
|
const minimumPatExpiry = data.$dayjs().add(1, 'day').format('YYYY-MM-DD')
|
||||||
|
|
||||||
const editPatId = ref(null)
|
const editPatId = ref(null)
|
||||||
|
|
||||||
const name = ref(null)
|
const name = ref(null)
|
||||||
const scopesVal = ref(BigInt(0))
|
const scopesVal = ref(BigInt(0))
|
||||||
const expires = ref(null)
|
const expires = ref(null)
|
||||||
|
const createdPatTokens = ref({})
|
||||||
|
const isExpiryInFuture = computed(
|
||||||
|
() => expires.value && data.$dayjs(expires.value).isAfter(data.$dayjs(), 'day'),
|
||||||
|
)
|
||||||
|
|
||||||
const deletePatIndex = ref(null)
|
const deletePatIndex = ref(null)
|
||||||
|
|
||||||
@@ -415,6 +426,9 @@ async function createPat() {
|
|||||||
scopes: Number(scopesVal.value),
|
scopes: Number(scopesVal.value),
|
||||||
expires: data.$dayjs(expires.value).toISOString(),
|
expires: data.$dayjs(expires.value).toISOString(),
|
||||||
})
|
})
|
||||||
|
if (res.access_token) {
|
||||||
|
createdPatTokens.value[res.id] = res.access_token
|
||||||
|
}
|
||||||
queryClient.setQueryData(['pat'], (old) => [...(old || []), res])
|
queryClient.setQueryData(['pat'], (old) => [...(old || []), res])
|
||||||
patModal.value.hide()
|
patModal.value.hide()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user