Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseβ€’4y agoβ€’
12 replies
Karbust

Using withPageAuth without a session

Hello,

I'm making a page where I want to access public data and at the same time private data related to the current logged in user (if there is any).

This is my code:

export const getServerSideProps = withPageAuth<Database>({
    authRequired: false,
    async getServerSideProps(ctx, supabase) {
        try {
            const { id } = ctx.query

            const response = await supabase
                .from('Videos')
                .select(`
                    title,
                    description,
                    likes,
                    dislikes,
                    views,
                    created_at,
                    VideoLikes (
                        type
                    ),
                    Profiles (
                        username,
                        profile_picture_url
                    ),
                    Servers (
                        id,
                        name
                    )
                `)
                .eq('id', id)
                .limit(1)
                .single()

            return {
                props: {
                    video: response.data,
                    userRating: response.data?.VideoLikes && response.data.VideoLikes[0] ? response.data.VideoLikes[0]['type'] : 0
                }
            }
        } catch (error) {
            console.error(error)
            return { notFound: true }
        }
    },
})
export const getServerSideProps = withPageAuth<Database>({
    authRequired: false,
    async getServerSideProps(ctx, supabase) {
        try {
            const { id } = ctx.query

            const response = await supabase
                .from('Videos')
                .select(`
                    title,
                    description,
                    likes,
                    dislikes,
                    views,
                    created_at,
                    VideoLikes (
                        type
                    ),
                    Profiles (
                        username,
                        profile_picture_url
                    ),
                    Servers (
                        id,
                        name
                    )
                `)
                .eq('id', id)
                .limit(1)
                .single()

            return {
                props: {
                    video: response.data,
                    userRating: response.data?.VideoLikes && response.data.VideoLikes[0] ? response.data.VideoLikes[0]['type'] : 0
                }
            }
        } catch (error) {
            console.error(error)
            return { notFound: true }
        }
    },
})


It works without any issues when there's a logged user, but when there's no user logged in it throws that error.

The code from the supabase query is being executed correctly

Any idea on how to solve it?

Thank you

next
next
: 12.3.1
@supabase/supabase-js
@supabase/supabase-js
: 2.0.4
@supabase/auth-helpers-nextjs
@supabase/auth-helpers-nextjs
: 0.4.2
unknown.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Next.js helpers v2 - Get user or session on the server without HOF (`withPageAuth`)
SupabaseSSupabase / help-and-questions
4y ago
withPageAuth Dynamic Page
SupabaseSSupabase / help-and-questions
4y ago
Permission based withPageAuth
SupabaseSSupabase / help-and-questions
4y ago
Session using a store or not?
SupabaseSSupabase / help-and-questions
4y ago