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 ( }> diff --git a/src/app/[locale]/(main)/gallery/upload/page.tsx b/src/app/[locale]/(main)/gallery/upload/page.tsx index 80992df3..e75183da 100644 --- a/src/app/[locale]/(main)/gallery/upload/page.tsx +++ b/src/app/[locale]/(main)/gallery/upload/page.tsx @@ -6,9 +6,10 @@ import { redirect } from '@/navigation' export const runtime = 'edge' export default async function Page() { - const user = await getUser() - - if (!user.$id) { + let user = null + try { + user = await getUser() + } catch (e) { return redirect('/login') } diff --git a/src/app/[locale]/(user)/user/[profileUrl]/page.tsx b/src/app/[locale]/(user)/user/[profileUrl]/page.tsx index 47bdc002..0924f953 100644 --- a/src/app/[locale]/(user)/user/[profileUrl]/page.tsx +++ b/src/app/[locale]/(user)/user/[profileUrl]/page.tsx @@ -70,7 +70,12 @@ export async function generateMetadata({ export default async function UserProfile({ params: { profileUrl } }) { const { databases } = await createSessionServerClient() - const account = await getUser() + let account = null + try { + account = await getUser() + } catch (error) { + // User is not logged in + } const userDataResponse: UserData.UserDataType = await databases.listDocuments( 'hp_db', @@ -80,7 +85,7 @@ export default async function UserProfile({ params: { profileUrl } }) { const userData = userDataResponse.documents[0] const followers = await getFollowers(userData.$id, 0, 5000000) const following = await getFollowing(userData.$id, 0, 5000000) - const isFollowingResponse = await getIsFollowing(account.$id, userData.$id) + const isFollowingResponse = await getIsFollowing(account?.$id, userData?.$id) const isFollowing = isFollowingResponse?.documents?.length > 0 || false const totalFollowers: number = followers?.length @@ -211,20 +216,20 @@ export default async function UserProfile({ params: { profileUrl } }) { {userData.displayName}
- {userData.status} + {userData?.status}