Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
How to implement cookie authentication with Sveltekit & Supabase?

I'm fairly new to both SvelteKit & Supabase and have done a bit of experimentation on my own, but I would like to know what is the best way to implement user authentication with both of these technologies.

I currently have the following in my __layout.svelte file so that every page on my web application will have access to the session but I'm not sure how to implement persistent user authentication with a cookie.

If anyone can guide me and future users that would be awesome!

<script>
  import supabase from "$lib/api";
  import { page, session } from '$app/stores';
  import { browser } from '$app/env';

    if(browser){
      $session = supabase.auth.session();
      supabase.auth.onAuthStateChange((event, sesh) => {
        $session = sesh;
      });
    }
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is definitely not clear how to do this. I tried to make it easy and put it into a user readable store:

export const user = readable<any>(null, (set) => {

    set(supabase.auth.user());
    const unsubscribe = supabase.auth.onAuthStateChange((_, session) => {
        session ? set(session.user) : set(null);
    });
    return () => {
        unsubscribe.data.unsubscribe();
    }
});

Now you can just use $user anywhere to get the session, or see if there is a session.

J

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!