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 { 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.
|
||||
redirect(
|
||||
302,
|
||||
`/comment/${encodeURIComponent(instance.data)}/${params.instance}`,
|
||||
resolveRoute('/comment/[instance]/[id]', {
|
||||
instance: instance.data.toLowerCase(),
|
||||
id: params.instance,
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -7,11 +7,12 @@ import {
|
||||
generalizePrivateMessage,
|
||||
} from '$lib/lemmy/inbox.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) return
|
||||
if (!profile.data.jwt) error(401)
|
||||
|
||||
const type: InboxFeedType =
|
||||
(url.searchParams.get('type') as InboxFeedType) || 'all'
|
||||
|
||||
@@ -7,18 +7,17 @@ import {
|
||||
generalizePrivateMessageReport,
|
||||
} from '$lib/lemmy/report.js'
|
||||
import { ReactiveState } from '$lib/promise.svelte'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
type ReportListType = 'unread' | 'all'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: ReportListType =
|
||||
(url.searchParams.get('type') as ReportListType) || 'unread'
|
||||
|
||||
const jwt = profile.data?.jwt
|
||||
|
||||
if (!jwt) return { type: type, page: page }
|
||||
|
||||
// can they please
|
||||
// make a sane, consistent, and simple API for once
|
||||
// 3 separate requests? really?
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
import { resolveRoute } from '$app/paths'
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import { error, redirect } from '@sveltejs/kit'
|
||||
|
||||
export function load({ params, url }) {
|
||||
export function load({ params }) {
|
||||
if (Number(params.instance)) {
|
||||
const split = url.pathname.split('/')
|
||||
|
||||
split.splice(
|
||||
2,
|
||||
0,
|
||||
`${encodeURIComponent(profile.data.instance)?.toLowerCase()}`,
|
||||
redirect(
|
||||
302,
|
||||
resolveRoute(`/post/[instance]/[id]`, {
|
||||
instance: profile.data.instance.toLowerCase(),
|
||||
id: params.instance,
|
||||
}),
|
||||
)
|
||||
|
||||
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 { client } from '$lib/lemmy.svelte.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
|
||||
// disable ssr, as the server cannot be authenticated
|
||||
export const ssr = false
|
||||
|
||||
export async function load({ fetch }) {
|
||||
if (!profile.data.jwt) error(401)
|
||||
|
||||
const my_user =
|
||||
// profile.data?.user ??
|
||||
(await client({ auth: profile.data?.jwt, func: fetch }).getSite()).my_user
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import type { CommentView, ListingType, PostView } from 'lemmy-js-client'
|
||||
|
||||
function getSavedItemPublished(item: PostView | CommentView) {
|
||||
@@ -11,7 +12,8 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
||||
}
|
||||
|
||||
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 type: 'comments' | 'posts' | 'all' =
|
||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||
|
||||
Reference in new issue
Block a user