fix: align with backend

This commit is contained in:
Calum H. (IMB11)
2026-05-31 16:16:09 +01:00
parent 6300c08b05
commit 657d1764c5
13 changed files with 111 additions and 16 deletions
@@ -1,5 +1,5 @@
import type { Labrinth } from '@modrinth/api-client'
import { type AuthProvider, provideAuth } from '@modrinth/ui'
import { type AuthProvider, type AuthUser, provideAuth } from '@modrinth/ui'
import { computed, type Ref, ref, watchEffect } from 'vue'
type AppCredentials = {
@@ -12,7 +12,7 @@ export function setupAuthProvider(
requestSignIn: (redirectPath: string) => void | Promise<void>,
) {
const sessionToken = ref<string | null>(null)
const user = ref<Labrinth.Users.v2.User | null>(null)
const user = ref<AuthUser | null>(null)
const isReady = computed(() => credentials.value !== undefined)
const authProvider: AuthProvider = {
+2
View File
@@ -75,6 +75,7 @@ export const initAuth = async (oldToken = null) => {
auth.user = await useBaseFetch(
'user',
{
apiVersion: 3,
headers: {
Authorization: auth.token,
},
@@ -105,6 +106,7 @@ export const initAuth = async (oldToken = null) => {
auth.user = await useBaseFetch(
'user',
{
apiVersion: 3,
headers: {
Authorization: auth.token,
},
+2 -1
View File
@@ -793,6 +793,7 @@ import ModrinthFooter from '~/components/ui/ModrinthFooter.vue'
import { getSignInRouteObj } from '~/composables/auth.js'
import { errors as generatedStateErrors } from '~/generated/state.json'
import { getProjectTypeMessage } from '~/utils/i18n-project-type.ts'
import { hasActiveMidas } from '~/utils/user-membership.ts'
const generatedState = useGeneratedState()
@@ -1096,7 +1097,7 @@ const userMenuOptions = computed(() => {
id: 'plus',
link: '/plus',
color: 'purple',
shown: !flags.value.hidePlusPromoInUserMenu && !isPermission(user.badges, 1 << 0),
shown: !flags.value.hidePlusPromoInUserMenu && !hasActiveMidas(user),
},
{
id: 'servers',
+5 -3
View File
@@ -2,19 +2,21 @@ import { useAppQueryClient } from '~/composables/query-client'
import { useServerModrinthClient } from '~/server/utils/api-client'
export default defineNuxtRouteMiddleware(async (to) => {
if (!to.path.startsWith('/user/') || !to.params.id) {
const userParam = to.params.user ?? to.params.id
const userId = Array.isArray(userParam) ? userParam[0] : userParam
if (!to.path.startsWith('/user/') || !userId) {
return
}
const queryClient = useAppQueryClient()
const authToken = useCookie('auth-token')
const client = useServerModrinthClient({ authToken: authToken.value || undefined })
const userId = to.params.id as string
try {
const user = await queryClient.fetchQuery({
queryKey: ['user', userId],
queryFn: () => client.labrinth.users_v2.get(userId),
queryFn: () => client.labrinth.users_v3.get(userId),
})
if (!user) return
+2 -2
View File
@@ -39,7 +39,7 @@
annual billing!
</p>
<ButtonStyled
v-if="auth.user && isPermission(auth.user.badges, 1 << 0)"
v-if="auth.user && hasActiveMidas(auth.user)"
color="purple"
size="large"
>
@@ -95,8 +95,8 @@ import {
import { calculateSavings, getCurrency } from '@modrinth/utils'
import { useBaseFetch } from '@/composables/fetch.js'
import { isPermission } from '@/utils/permissions.ts'
import { products } from '~/generated/state.json'
import { hasActiveMidas } from '~/utils/user-membership.ts'
const { addNotification } = injectNotificationManager()
const formatPrice = useFormatPrice()
+4 -1
View File
@@ -484,6 +484,8 @@
:join-date="joinDate"
:role="user.role"
:badges="user.badges"
:has-midas="hasActiveMidas(user)"
:has-pride="hasPride26Badge(user)"
:earliest-project-by-type="earliestProjectByType"
class="mb-4 rounded-2xl border border-solid border-surface-4 bg-surface-3 p-4 pt-3"
/>
@@ -546,6 +548,7 @@ import AdPlaceholder from '~/components/ui/AdPlaceholder.vue'
import CollectionCreateModal from '~/components/ui/create/CollectionCreateModal.vue'
import ModalCreation from '~/components/ui/create/ProjectCreateModal.vue'
import { getSignInRouteObj } from '~/composables/auth.js'
import { hasActiveMidas, hasPride26Badge } from '~/utils/user-membership.ts'
import { reportUser } from '~/utils/report-helpers.ts'
const data = useNuxtApp()
@@ -730,7 +733,7 @@ const {
suspense: userSuspense,
} = useQuery({
queryKey: computed(() => ['user', userId]),
queryFn: () => client.labrinth.users_v2.get(userId),
queryFn: () => client.labrinth.users_v3.get(userId),
})
watch(
+3 -3
View File
@@ -1,5 +1,5 @@
import type { Labrinth } from '@modrinth/api-client'
import { type AuthProvider, provideAuth } from '@modrinth/ui'
import { type AuthProvider, type AuthUser, provideAuth } from '@modrinth/ui'
import { ref, watchEffect } from 'vue'
import { getSignInRedirectPath } from '~/composables/auth.js'
@@ -8,7 +8,7 @@ export function setupAuthProvider(auth: Awaited<ReturnType<typeof useAuth>>) {
const router = useRouter()
const route = useRoute()
const sessionToken = ref<string | null>(null)
const user = ref<Labrinth.Users.v2.User | null>(null)
const user = ref<AuthUser | null>(null)
const authProvider: AuthProvider = {
session_token: sessionToken,
@@ -26,7 +26,7 @@ export function setupAuthProvider(auth: Awaited<ReturnType<typeof useAuth>>) {
watchEffect(() => {
sessionToken.value = auth.value.token || null
user.value = (auth.value.user as Labrinth.Users.v2.User | null) ?? null
user.value = (auth.value.user as Labrinth.Users.v3.User | null) ?? null
})
provideAuth(authProvider)
@@ -0,0 +1,40 @@
import { UserBadge } from '@modrinth/utils'
const PRIDE_26_MIDAS_DURATION_MS = 30 * 24 * 60 * 60 * 1000
type Pride26Campaign = {
last_donated_at?: string | null
has_badge?: boolean | null
has_midas?: boolean | null
}
type UserWithMembership = {
badges?: number | null
campaigns?: {
pride_26?: Pride26Campaign | null
} | null
}
export function hasPride26Badge(user?: UserWithMembership | null) {
return user?.campaigns?.pride_26?.has_badge === true
}
export function hasActivePride26Midas(user?: UserWithMembership | null, now = Date.now()) {
const pride26Campaign = user?.campaigns?.pride_26
if (!pride26Campaign?.has_midas || !pride26Campaign.last_donated_at) {
return false
}
const lastDonatedAt = Date.parse(pride26Campaign.last_donated_at)
if (!Number.isFinite(lastDonatedAt)) {
return false
}
return lastDonatedAt + PRIDE_26_MIDAS_DURATION_MS > now
}
export function hasActiveMidas(user?: UserWithMembership | null, now = Date.now()) {
return Boolean((user?.badges ?? 0) & UserBadge.MIDAS) || hasActivePride26Midas(user, now)
}