add sign in redirect path (#5746)
This commit is contained in:
@@ -104,13 +104,28 @@ export const initAuth = async (oldToken = null) => {
|
|||||||
return auth
|
return auth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getSignInRedirectPath = (route) => {
|
||||||
|
const fullPath = route.fullPath
|
||||||
|
if (fullPath === '/auth' || fullPath.startsWith('/auth/')) {
|
||||||
|
return '/dashboard'
|
||||||
|
}
|
||||||
|
return fullPath
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getSignInRouteObj = (route, redirectOverride) => ({
|
||||||
|
path: '/auth/sign-in',
|
||||||
|
query: {
|
||||||
|
redirect: redirectOverride ?? getSignInRedirectPath(route),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
export const getAuthUrl = (provider, redirect = '/dashboard') => {
|
export const getAuthUrl = (provider, redirect = '/dashboard') => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const route = useNativeRoute()
|
const route = useNativeRoute()
|
||||||
|
|
||||||
const fullURL = route.query.launcher
|
const fullURL = route.query.launcher
|
||||||
? getLauncherRedirectUrl(route)
|
? getLauncherRedirectUrl(route)
|
||||||
: `${config.public.siteUrl}/auth/sign-in?redirect=${redirect}`
|
: `${config.public.siteUrl}/auth/sign-in?redirect=${encodeURIComponent(redirect)}`
|
||||||
|
|
||||||
return `${config.public.apiBaseUrl}auth/init?provider=${provider}&url=${encodeURIComponent(fullURL)}`
|
return `${config.public.apiBaseUrl}auth/init?provider=${provider}&url=${encodeURIComponent(fullURL)}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -501,7 +501,7 @@
|
|||||||
</OverflowMenu>
|
</OverflowMenu>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<ButtonStyled color="brand">
|
<ButtonStyled color="brand">
|
||||||
<nuxt-link to="/auth/sign-in">
|
<nuxt-link :to="signInRouteObj">
|
||||||
<LogInIcon aria-hidden="true" />
|
<LogInIcon aria-hidden="true" />
|
||||||
{{ formatMessage(commonMessages.signInButton) }}
|
{{ formatMessage(commonMessages.signInButton) }}
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
@@ -556,7 +556,7 @@
|
|||||||
<div>{{ formatMessage(commonMessages.visitYourProfile) }}</div>
|
<div>{{ formatMessage(commonMessages.visitYourProfile) }}</div>
|
||||||
</div>
|
</div>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<nuxt-link v-else class="iconified-button brand-button" to="/auth/sign-in">
|
<nuxt-link v-else class="iconified-button brand-button" :to="signInRouteObj">
|
||||||
<LogInIcon aria-hidden="true" /> {{ formatMessage(commonMessages.signInButton) }}
|
<LogInIcon aria-hidden="true" /> {{ formatMessage(commonMessages.signInButton) }}
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
</div>
|
</div>
|
||||||
@@ -761,6 +761,7 @@ import OrganizationCreateModal from '~/components/ui/create/OrganizationCreateMo
|
|||||||
import ProjectCreateModal from '~/components/ui/create/ProjectCreateModal.vue'
|
import ProjectCreateModal from '~/components/ui/create/ProjectCreateModal.vue'
|
||||||
import ModrinthFooter from '~/components/ui/ModrinthFooter.vue'
|
import ModrinthFooter from '~/components/ui/ModrinthFooter.vue'
|
||||||
import TeleportOverflowMenu from '~/components/ui/servers/TeleportOverflowMenu.vue'
|
import TeleportOverflowMenu from '~/components/ui/servers/TeleportOverflowMenu.vue'
|
||||||
|
import { getSignInRouteObj } from '~/composables/auth.js'
|
||||||
import { errors as generatedStateErrors } from '~/generated/state.json'
|
import { errors as generatedStateErrors } from '~/generated/state.json'
|
||||||
import { getProjectTypeMessage } from '~/utils/i18n-project-type.ts'
|
import { getProjectTypeMessage } from '~/utils/i18n-project-type.ts'
|
||||||
|
|
||||||
@@ -779,6 +780,7 @@ const flags = useFeatureFlags()
|
|||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const route = useNativeRoute()
|
const route = useNativeRoute()
|
||||||
const router = useNativeRouter()
|
const router = useNativeRouter()
|
||||||
|
const signInRouteObj = computed(() => getSignInRouteObj(route))
|
||||||
const link = config.public.siteUrl + route.path.replace(/\/+$/, '')
|
const link = config.public.siteUrl + route.path.replace(/\/+$/, '')
|
||||||
const client = injectModrinthClient()
|
const client = injectModrinthClient()
|
||||||
|
|
||||||
|
|||||||
@@ -647,7 +647,7 @@
|
|||||||
<nuxt-link
|
<nuxt-link
|
||||||
v-else
|
v-else
|
||||||
v-tooltip="formatMessage(commonMessages.followButton)"
|
v-tooltip="formatMessage(commonMessages.followButton)"
|
||||||
to="/auth/sign-in"
|
:to="signInRouteObj"
|
||||||
:aria-label="formatMessage(commonMessages.followButton)"
|
:aria-label="formatMessage(commonMessages.followButton)"
|
||||||
>
|
>
|
||||||
<HeartIcon aria-hidden="true" />
|
<HeartIcon aria-hidden="true" />
|
||||||
@@ -655,7 +655,7 @@
|
|||||||
<template #fallback>
|
<template #fallback>
|
||||||
<nuxt-link
|
<nuxt-link
|
||||||
v-tooltip="formatMessage(commonMessages.followButton)"
|
v-tooltip="formatMessage(commonMessages.followButton)"
|
||||||
to="/auth/sign-in"
|
:to="signInRouteObj"
|
||||||
:aria-label="formatMessage(commonMessages.followButton)"
|
:aria-label="formatMessage(commonMessages.followButton)"
|
||||||
>
|
>
|
||||||
<HeartIcon aria-hidden="true" />
|
<HeartIcon aria-hidden="true" />
|
||||||
@@ -715,7 +715,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
</PopoutMenu>
|
</PopoutMenu>
|
||||||
<nuxt-link v-else v-tooltip="'Save'" to="/auth/sign-in" aria-label="Save">
|
<nuxt-link v-else v-tooltip="'Save'" :to="signInRouteObj" aria-label="Save">
|
||||||
<BookmarkIcon aria-hidden="true" />
|
<BookmarkIcon aria-hidden="true" />
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
@@ -768,7 +768,11 @@
|
|||||||
{
|
{
|
||||||
id: 'report',
|
id: 'report',
|
||||||
action: () =>
|
action: () =>
|
||||||
auth.user ? reportProject(project.id) : navigateTo('/auth/sign-in'),
|
auth.user
|
||||||
|
? reportProject(project.id)
|
||||||
|
: navigateTo(
|
||||||
|
getSignInRouteObj(route, getReportPath('project', project.id)),
|
||||||
|
),
|
||||||
color: 'red',
|
color: 'red',
|
||||||
hoverOnly: true,
|
hoverOnly: true,
|
||||||
shown: !isMember,
|
shown: !isMember,
|
||||||
@@ -1117,12 +1121,13 @@ import CollectionCreateModal from '~/components/ui/create/CollectionCreateModal.
|
|||||||
import MessageBanner from '~/components/ui/MessageBanner.vue'
|
import MessageBanner from '~/components/ui/MessageBanner.vue'
|
||||||
import ModerationChecklist from '~/components/ui/moderation/checklist/ModerationChecklist.vue'
|
import ModerationChecklist from '~/components/ui/moderation/checklist/ModerationChecklist.vue'
|
||||||
import ProjectMemberHeader from '~/components/ui/ProjectMemberHeader.vue'
|
import ProjectMemberHeader from '~/components/ui/ProjectMemberHeader.vue'
|
||||||
|
import { getSignInRouteObj } from '~/composables/auth.js'
|
||||||
import { saveFeatureFlags } from '~/composables/featureFlags.ts'
|
import { saveFeatureFlags } from '~/composables/featureFlags.ts'
|
||||||
import { STALE_TIME, STALE_TIME_LONG } from '~/composables/queries/project'
|
import { STALE_TIME, STALE_TIME_LONG } from '~/composables/queries/project'
|
||||||
import { versionQueryOptions } from '~/composables/queries/version'
|
import { versionQueryOptions } from '~/composables/queries/version'
|
||||||
import { userCollectProject, userFollowProject } from '~/composables/user.js'
|
import { userCollectProject, userFollowProject } from '~/composables/user.js'
|
||||||
import { useModerationStore } from '~/store/moderation.ts'
|
import { useModerationStore } from '~/store/moderation.ts'
|
||||||
import { reportProject } from '~/utils/report-helpers.ts'
|
import { getReportPath, reportProject } from '~/utils/report-helpers.ts'
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
key: (route) => `${route.params.id}`,
|
key: (route) => `${route.params.id}`,
|
||||||
@@ -1130,6 +1135,7 @@ definePageMeta({
|
|||||||
|
|
||||||
const data = useNuxtApp()
|
const data = useNuxtApp()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const signInRouteObj = computed(() => getSignInRouteObj(route))
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const moderationStore = useModerationStore()
|
const moderationStore = useModerationStore()
|
||||||
const notifications = injectNotificationManager()
|
const notifications = injectNotificationManager()
|
||||||
|
|||||||
@@ -110,7 +110,8 @@
|
|||||||
id: 'report',
|
id: 'report',
|
||||||
color: 'red',
|
color: 'red',
|
||||||
hoverFilled: true,
|
hoverFilled: true,
|
||||||
action: () => (auth.user ? reportVersion(version.id) : navigateTo('/auth/sign-in')),
|
action: () =>
|
||||||
|
auth.user ? reportVersion(version.id) : navigateTo(getSignInRouteObj(route)),
|
||||||
shown: !currentMember,
|
shown: !currentMember,
|
||||||
},
|
},
|
||||||
{ divider: true, shown: !!currentMember || flags.developerMode },
|
{ divider: true, shown: !!currentMember || flags.developerMode },
|
||||||
@@ -307,8 +308,11 @@ import {
|
|||||||
import { useTemplateRef } from 'vue'
|
import { useTemplateRef } from 'vue'
|
||||||
|
|
||||||
import CreateProjectVersionModal from '~/components/ui/create-project-version/CreateProjectVersionModal.vue'
|
import CreateProjectVersionModal from '~/components/ui/create-project-version/CreateProjectVersionModal.vue'
|
||||||
|
import { getSignInRouteObj } from '~/composables/auth.js'
|
||||||
import { reportVersion } from '~/utils/report-helpers.ts'
|
import { reportVersion } from '~/utils/report-helpers.ts'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
const client = injectModrinthClient()
|
const client = injectModrinthClient()
|
||||||
const { addNotification } = injectNotificationManager()
|
const { addNotification } = injectNotificationManager()
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -147,7 +147,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
<ButtonStyled v-if="!auth.user">
|
<ButtonStyled v-if="!auth.user">
|
||||||
<nuxt-link to="/auth/sign-in">
|
<nuxt-link :to="signInRouteObj">
|
||||||
<ReportIcon aria-hidden="true" />
|
<ReportIcon aria-hidden="true" />
|
||||||
Report
|
Report
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
@@ -443,6 +443,7 @@ import { formatBytes, renderHighlightedString } from '@modrinth/utils'
|
|||||||
import Breadcrumbs from '~/components/ui/Breadcrumbs.vue'
|
import Breadcrumbs from '~/components/ui/Breadcrumbs.vue'
|
||||||
import CreateProjectVersionModal from '~/components/ui/create-project-version/CreateProjectVersionModal.vue'
|
import CreateProjectVersionModal from '~/components/ui/create-project-version/CreateProjectVersionModal.vue'
|
||||||
import Modal from '~/components/ui/Modal.vue'
|
import Modal from '~/components/ui/Modal.vue'
|
||||||
|
import { getSignInRouteObj } from '~/composables/auth.js'
|
||||||
import { useImageUpload } from '~/composables/image-upload.ts'
|
import { useImageUpload } from '~/composables/image-upload.ts'
|
||||||
import { inferVersionInfo } from '~/helpers/infer'
|
import { inferVersionInfo } from '~/helpers/infer'
|
||||||
import { createDataPackVersion } from '~/helpers/package.js'
|
import { createDataPackVersion } from '~/helpers/package.js'
|
||||||
@@ -454,6 +455,7 @@ const emit = defineEmits<{
|
|||||||
// Composables
|
// Composables
|
||||||
const data = useNuxtApp()
|
const data = useNuxtApp()
|
||||||
const route = useNativeRoute()
|
const route = useNativeRoute()
|
||||||
|
const signInRouteObj = computed(() => getSignInRouteObj(route))
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const auth = await useAuth()
|
const auth = await useAuth()
|
||||||
const tags = useGeneratedState()
|
const tags = useGeneratedState()
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
color: 'red',
|
color: 'red',
|
||||||
hoverFilled: true,
|
hoverFilled: true,
|
||||||
action: () =>
|
action: () =>
|
||||||
auth.user ? reportVersion(version.id) : navigateTo('/auth/sign-in'),
|
auth.user ? reportVersion(version.id) : navigateTo(getSignInRouteObj(route)),
|
||||||
shown: !currentMember,
|
shown: !currentMember,
|
||||||
},
|
},
|
||||||
{ divider: true, shown: currentMember || flags.developerMode },
|
{ divider: true, shown: currentMember || flags.developerMode },
|
||||||
@@ -269,8 +269,11 @@ import {
|
|||||||
import { onMounted, useTemplateRef } from 'vue'
|
import { onMounted, useTemplateRef } from 'vue'
|
||||||
|
|
||||||
import CreateProjectVersionModal from '~/components/ui/create-project-version/CreateProjectVersionModal.vue'
|
import CreateProjectVersionModal from '~/components/ui/create-project-version/CreateProjectVersionModal.vue'
|
||||||
|
import { getSignInRouteObj } from '~/composables/auth.js'
|
||||||
import { reportVersion } from '~/utils/report-helpers.ts'
|
import { reportVersion } from '~/utils/report-helpers.ts'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
const tags = useGeneratedState()
|
const tags = useGeneratedState()
|
||||||
const flags = useFeatureFlags()
|
const flags = useFeatureFlags()
|
||||||
const auth = await useAuth()
|
const auth = await useAuth()
|
||||||
|
|||||||
@@ -199,7 +199,8 @@
|
|||||||
{ divider: true, shown: auth.user && auth.user.id === user.id },
|
{ divider: true, shown: auth.user && auth.user.id === user.id },
|
||||||
{
|
{
|
||||||
id: 'report',
|
id: 'report',
|
||||||
action: () => (auth.user ? reportUser(user.id) : navigateTo('/auth/sign-in')),
|
action: () =>
|
||||||
|
auth.user ? reportUser(user.id) : navigateTo(getSignInRouteObj(route)),
|
||||||
color: 'red',
|
color: 'red',
|
||||||
hoverOnly: true,
|
hoverOnly: true,
|
||||||
shown: auth.user?.id !== user.id,
|
shown: auth.user?.id !== user.id,
|
||||||
@@ -520,6 +521,7 @@ import UpToDate from '~/assets/images/illustrations/up_to_date.svg?component'
|
|||||||
import AdPlaceholder from '~/components/ui/AdPlaceholder.vue'
|
import AdPlaceholder from '~/components/ui/AdPlaceholder.vue'
|
||||||
import CollectionCreateModal from '~/components/ui/create/CollectionCreateModal.vue'
|
import CollectionCreateModal from '~/components/ui/create/CollectionCreateModal.vue'
|
||||||
import ModalCreation from '~/components/ui/create/ProjectCreateModal.vue'
|
import ModalCreation from '~/components/ui/create/ProjectCreateModal.vue'
|
||||||
|
import { getSignInRouteObj } from '~/composables/auth.js'
|
||||||
import { reportUser } from '~/utils/report-helpers.ts'
|
import { reportUser } from '~/utils/report-helpers.ts'
|
||||||
|
|
||||||
const data = useNuxtApp()
|
const data = useNuxtApp()
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import type { Labrinth } from '@modrinth/api-client'
|
|||||||
import { type AuthProvider, provideAuth } from '@modrinth/ui'
|
import { type AuthProvider, provideAuth } from '@modrinth/ui'
|
||||||
import { ref, watchEffect } from 'vue'
|
import { ref, watchEffect } from 'vue'
|
||||||
|
|
||||||
|
import { getSignInRedirectPath } from '~/composables/auth.js'
|
||||||
|
|
||||||
export function setupAuthProvider(auth: Awaited<ReturnType<typeof useAuth>>) {
|
export function setupAuthProvider(auth: Awaited<ReturnType<typeof useAuth>>) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const route = useRoute()
|
||||||
const sessionToken = ref<string | null>(null)
|
const sessionToken = ref<string | null>(null)
|
||||||
const user = ref<Labrinth.Users.v2.User | null>(null)
|
const user = ref<Labrinth.Users.v2.User | null>(null)
|
||||||
|
|
||||||
@@ -14,7 +17,7 @@ export function setupAuthProvider(auth: Awaited<ReturnType<typeof useAuth>>) {
|
|||||||
await router.push({
|
await router.push({
|
||||||
path: '/auth/sign-in',
|
path: '/auth/sign-in',
|
||||||
query: {
|
query: {
|
||||||
redirect: redirectPath,
|
redirect: redirectPath || getSignInRedirectPath(route),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
const startReport = (type: string, id: string) => {
|
export const getReportPath = (type: string, id: string) => {
|
||||||
const prefill = new URLSearchParams()
|
const prefill = new URLSearchParams()
|
||||||
|
|
||||||
// type
|
|
||||||
prefill.set('item', type)
|
prefill.set('item', type)
|
||||||
prefill.set('itemID', id)
|
prefill.set('itemID', id)
|
||||||
|
return '/report?' + prefill.toString()
|
||||||
|
}
|
||||||
|
|
||||||
navigateTo('/report?' + prefill.toString())
|
const startReport = (type: string, id: string) => {
|
||||||
|
navigateTo(getReportPath(type, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reportProject = (id: string) => {
|
export const reportProject = (id: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user