Ā© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
13 replies
spanishbombs

SSR Auth / SvelteKit / RLS issue

Hi! I'm trying to set up Auth in my SvelteKit project but can't make RLS work.

I followed the instructions to instantiate Supabase client in hooks and layout.ts. Sign up, Log in and Log out seem to work fine.

I can see cookies with JWT tokens created, active sessions in auth.sessions, the session is active on the server (locals.getSession()), etc.

One thing I noticed is that when I try to check JWT token on jwt.io, it correctly displays sub and aud ('authenticated') but also it says 'Invalid Signature' at the bottom - not sure why?

I've set up RLS policies to restrict select with USING (auth.uid() = user_id).

Then I load data from my +page.server.ts file.

export const load = (async (locals) => {
    const user_id = (await locals.parent()).session.user.id

    const response = await getRecords(user_id)
    if (response.error) {
        throw error(400, "Something went wrong. Please try again later")
    }

    return { data: response.data }
})
export const load = (async (locals) => {
    const user_id = (await locals.parent()).session.user.id

    const response = await getRecords(user_id)
    if (response.error) {
        throw error(400, "Something went wrong. Please try again later")
    }

    return { data: response.data }
})


getRecords is defined as following (I use pg function to select data)
async function getRecords(user_id: string) {
    try {
        const recordsResponse = await supabaseDB.rpc('get_latest_iterations', { _user_id: user_id })
        if (recordsResponse.error) throw recordsResponse.error

        return ({
            data: recordsResponse.data
        })
    }
    catch (error) { return error }
}
async function getRecords(user_id: string) {
    try {
        const recordsResponse = await supabaseDB.rpc('get_latest_iterations', { _user_id: user_id })
        if (recordsResponse.error) throw recordsResponse.error

        return ({
            data: recordsResponse.data
        })
    }
    catch (error) { return error }
}


Not sure how to troubleshoot it either. Seems like I'm missing something obvious but not sure what.
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

Sveltekit SSR auth
SupabaseSSupabase / help-and-questions
8mo ago
SvelteKit SSR auth example bug?
SupabaseSSupabase / help-and-questions
6mo ago
Next.js SSR RLS
SupabaseSSupabase / help-and-questions
13mo ago
SSR authentication on SvelteKit
SupabaseSSupabase / help-and-questions
3y ago