Skip to content

Instantly share code, notes, and snippets.

@ashx3s
Last active January 11, 2024 18:21
Show Gist options
  • Save ashx3s/7cf9cc0a148ae578d00e1d36248df8c1 to your computer and use it in GitHub Desktop.
Save ashx3s/7cf9cc0a148ae578d00e1d36248df8c1 to your computer and use it in GitHub Desktop.
Supabase Nuxt Logout

README

Things to watch for

  • that the JWT token is removed from browser cookies
  • set the user to null
  • navigate the user to an unprotected page to stop access

Places to check for verification of logout

  • browser devtools
    • application tab
      • local storage
        • check for a sb- prefixed access token

Instructions

  1. set the client
const supabase = useSupabaseClient();
  1. create a function (this one does not need to be async) for logout
function logout() {
  try {
  const { error } = supabase.auth.signOut();
  if (error) {
    throw error;
  }
  } catch (error) {
    console.error(error)
  }
}
  1. attach the function to the logout button
<button @click="logout">Log out</button>

How to verify logout

  1. In the devtools, check Application Tab -> Local Storage -> sb- access token
  2. get the user info from the session and print it to the page (it will disappear on a successful log out)
<script setup>
const user = useSupabaseUser();
</script>
<template>
<p>{{ user }}</p>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment