diff --git a/src/app/[locale]/(account)/account/gallery/[galleryId]/page.tsx b/src/app/[locale]/(account)/account/gallery/[galleryId]/page.tsx
index e6de7c6f..8cc9c785 100644
--- a/src/app/[locale]/(account)/account/gallery/[galleryId]/page.tsx
+++ b/src/app/[locale]/(account)/account/gallery/[galleryId]/page.tsx
@@ -4,6 +4,7 @@ import { createAdminClient } from '@/app/appwrite-session'
import { Gallery } from '@/utils/types/models'
import PageLayout from '@/components/pageLayout'
import { getUser } from '@/utils/server-api/account/user'
+import { redirect } from '@/navigation'
export const runtime = 'edge'
@@ -14,7 +15,13 @@ export const metadata = {
export default async function AccountSingleGalleryPage({
params: { galleryId },
}) {
- const userData = await getUser()
+ let userData = null
+ try {
+ userData = await getUser()
+ } catch (error) {
+ return redirect('/login')
+ }
+
const userId = userData?.$id
const { databases } = await createAdminClient()
@@ -31,7 +38,6 @@ export default async function AccountSingleGalleryPage({
const galleryUserId = singleGallery?.userId
if (!galleryUserId) return notFound() // Wait for userId to be available
- if (!userId) return notFound() // Wait for userId to be available
if (userId !== galleryUserId) {
return notFound()
diff --git a/src/app/[locale]/(main)/community/[communityId]/page.client.tsx b/src/app/[locale]/(main)/community/[communityId]/page.client.tsx
index 23b2839c..2683661c 100644
--- a/src/app/[locale]/(main)/community/[communityId]/page.client.tsx
+++ b/src/app/[locale]/(main)/community/[communityId]/page.client.tsx
@@ -14,8 +14,12 @@ export function FollowerButton({ displayName, communityId }) {
useEffect(() => {
const getUserId = async () => {
- const data = await account.get()
- setUserId(data.$id)
+ try {
+ const data = await account.get()
+ setUserId(data?.$id)
+ } catch (error) {
+ setUserId(null)
+ }
}
getUserId().then()
}, [])
diff --git a/src/app/[locale]/(main)/gallery/[galleryId]/page.tsx b/src/app/[locale]/(main)/gallery/[galleryId]/page.tsx
index 5304ff20..c956284a 100644
--- a/src/app/[locale]/(main)/gallery/[galleryId]/page.tsx
+++ b/src/app/[locale]/(main)/gallery/[galleryId]/page.tsx
@@ -21,8 +21,14 @@ export const runtime = 'edge'
export default async function GalleryPage({ params: { galleryId } }) {
const { databases } = await createSessionServerClient()
- const userSelf = await getUser()
- const enableNsfw = userSelf?.prefs?.nsfw || false
+ let userSelf = null
+ let enableNsfw = false
+ try {
+ userSelf = await getUser()
+ enableNsfw = userSelf?.prefs?.nsfw
+ } catch (e) {
+ // do nothing
+ }
const gallery: Gallery.GalleryType = await databases.listDocuments(
'hp_db',
diff --git a/src/app/[locale]/(main)/gallery/page.tsx b/src/app/[locale]/(main)/gallery/page.tsx
index 033f6cb3..d6239aff 100644
--- a/src/app/[locale]/(main)/gallery/page.tsx
+++ b/src/app/[locale]/(main)/gallery/page.tsx
@@ -53,8 +53,13 @@ function UploadButton() {
}
export default async function Gallery() {
- const accountData = await getUser()
- const enableNsfw = accountData?.prefs?.nsfw
+ let enableNsfw = false
+ try {
+ const accountData = await getUser()
+ enableNsfw = accountData?.prefs?.nsfw
+ } catch (e) {
+ // do nothing
+ }
return (