fix: improper route gating (#596)
This commit is contained in:
1 parent
a8b65750ca
commit
9f4790326f
6 files changed
+25
-20
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
import { resolveRoute } from '$app/paths'
|
||||||
import { instance } from '$lib/instance.svelte'
|
import { instance } from '$lib/instance.svelte'
|
||||||
import { redirect } from '@sveltejs/kit'
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
@@ -5,6 +6,9 @@ export function load({ params }) {
|
|||||||
// If you somehow got to /comment/instance, it likely means you passed in an ID, not an instance.
|
// If you somehow got to /comment/instance, it likely means you passed in an ID, not an instance.
|
||||||
redirect(
|
redirect(
|
||||||
302,
|
302,
|
||||||
`/comment/${encodeURIComponent(instance.data)}/${params.instance}`,
|
resolveRoute('/comment/[instance]/[id]', {
|
||||||
|
instance: instance.data.toLowerCase(),
|
||||||
|
id: params.instance,
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,12 @@ import {
|
|||||||
generalizePrivateMessage,
|
generalizePrivateMessage,
|
||||||
} from '$lib/lemmy/inbox.js'
|
} from '$lib/lemmy/inbox.js'
|
||||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||||
|
import { error } from '@sveltejs/kit'
|
||||||
|
|
||||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
if (!profile.data.jwt) return
|
if (!profile.data.jwt) error(401)
|
||||||
|
|
||||||
const type: InboxFeedType =
|
const type: InboxFeedType =
|
||||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||||
|
|||||||
@@ -7,18 +7,17 @@ import {
|
|||||||
generalizePrivateMessageReport,
|
generalizePrivateMessageReport,
|
||||||
} from '$lib/lemmy/report.js'
|
} from '$lib/lemmy/report.js'
|
||||||
import { ReactiveState } from '$lib/promise.svelte'
|
import { ReactiveState } from '$lib/promise.svelte'
|
||||||
|
import { error } from '@sveltejs/kit'
|
||||||
|
|
||||||
type ReportListType = 'unread' | 'all'
|
type ReportListType = 'unread' | 'all'
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
|
if (!profile.data.jwt) error(401)
|
||||||
|
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
const type: ReportListType =
|
const type: ReportListType =
|
||||||
(url.searchParams.get('type') as ReportListType) || 'unread'
|
(url.searchParams.get('type') as ReportListType) || 'unread'
|
||||||
|
|
||||||
const jwt = profile.data?.jwt
|
|
||||||
|
|
||||||
if (!jwt) return { type: type, page: page }
|
|
||||||
|
|
||||||
// can they please
|
// can they please
|
||||||
// make a sane, consistent, and simple API for once
|
// make a sane, consistent, and simple API for once
|
||||||
// 3 separate requests? really?
|
// 3 separate requests? really?
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
|
import { resolveRoute } from '$app/paths'
|
||||||
import { profile } from '$lib/auth.svelte.js'
|
import { profile } from '$lib/auth.svelte.js'
|
||||||
import { error, redirect } from '@sveltejs/kit'
|
import { error, redirect } from '@sveltejs/kit'
|
||||||
|
|
||||||
export function load({ params, url }) {
|
export function load({ params }) {
|
||||||
if (Number(params.instance)) {
|
if (Number(params.instance)) {
|
||||||
const split = url.pathname.split('/')
|
redirect(
|
||||||
|
302,
|
||||||
split.splice(
|
resolveRoute(`/post/[instance]/[id]`, {
|
||||||
2,
|
instance: profile.data.instance.toLowerCase(),
|
||||||
0,
|
id: params.instance,
|
||||||
`${encodeURIComponent(profile.data.instance)?.toLowerCase()}`,
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
const newUrl = new URL(url)
|
|
||||||
newUrl.pathname = split.join('/')
|
|
||||||
|
|
||||||
redirect(302, newUrl.toString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error(404, 'Not found')
|
error(404)
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
import { profile } from '$lib/auth.svelte'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import { client } from '$lib/lemmy.svelte.js'
|
import { client } from '$lib/lemmy.svelte.js'
|
||||||
|
import { error } from '@sveltejs/kit'
|
||||||
|
|
||||||
// disable ssr, as the server cannot be authenticated
|
// disable ssr, as the server cannot be authenticated
|
||||||
export const ssr = false
|
export const ssr = false
|
||||||
|
|
||||||
export async function load({ fetch }) {
|
export async function load({ fetch }) {
|
||||||
|
if (!profile.data.jwt) error(401)
|
||||||
|
|
||||||
const my_user =
|
const my_user =
|
||||||
// profile.data?.user ??
|
// profile.data?.user ??
|
||||||
(await client({ auth: profile.data?.jwt, func: fetch }).getSite()).my_user
|
(await client({ auth: profile.data?.jwt, func: fetch }).getSite()).my_user
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { profile } from '$lib/auth.svelte'
|
import { profile } from '$lib/auth.svelte'
|
||||||
import { getClient } from '$lib/lemmy.svelte.js'
|
import { getClient } from '$lib/lemmy.svelte.js'
|
||||||
|
import { error } from '@sveltejs/kit'
|
||||||
import type { CommentView, ListingType, PostView } from 'lemmy-js-client'
|
import type { CommentView, ListingType, PostView } from 'lemmy-js-client'
|
||||||
|
|
||||||
function getSavedItemPublished(item: PostView | CommentView) {
|
function getSavedItemPublished(item: PostView | CommentView) {
|
||||||
@@ -11,7 +12,8 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
if (!profile) return { posts: [], page: 0 }
|
if (!profile.data.jwt) throw error(401)
|
||||||
|
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
const type: 'comments' | 'posts' | 'all' =
|
const type: 'comments' | 'posts' | 'all' =
|
||||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||||
|
|||||||
Reference in new issue
Block a user