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 }
        }
    },
})


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: 12.3.1
@supabase/supabase-js: 2.0.4
@supabase/auth-helpers-nextjs: 0.4.2
unknown.png
Was this page helpful?