The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
vue3-ts-todo: make user sessions persistent upon refresh
ykdojo9f66c1535d28
diff --git a/examples/vue3-ts-todo-list/src/App.vue b/examples/vue3-ts-todo-list/src/App.vueindex afa7fbacde5..b458c0aceef 100644--- a/examples/vue3-ts-todo-list/src/App.vue+++ b/examples/vue3-ts-todo-list/src/App.vue@@ -40,6 +40,19 @@ export default {Footer,},setup() {+ // Get the auth token in the local storage.+ const json = localStorage.getItem('supabase.auth.token')+ if (json) {+ const data = JSON.parse(json)+ const { currentSession, expiresAt } = data+ const timeNow = Math.round(Date.now() / 1000)+ // If it hasn't expired yet, update userSession.+ if (timeNow < expiresAt) {+ userSession.value = currentSession+ }+ }+ // NOTE: The pattern above is similar to that of the _recoverSession() function+ // in supabase/gotrue-js: https://github.com/supabase/gotrue-js/blob/dc6cf10dcac016ba4831efdb9b8683bda109dab0/src/GoTrueClient.ts#L328return { userSession, handleLogout }},}diff --git a/examples/vue3-ts-todo-list/src/vuetils/useTodo.ts b/examples/vue3-ts-todo-list/src/vuetils/useTodo.tsindex 67f20acab7d..979b077659a 100644--- a/examples/vue3-ts-todo-list/src/vuetils/useTodo.ts+++ b/examples/vue3-ts-todo-list/src/vuetils/useTodo.ts@@ -9,6 +9,10 @@ const allTodos = ref<Todo[]>([])*/async function fetchTodos() {try {+ // Wait for the supabase client to be fully initialized+ // before making the following query. Without this line,+ // this query would return an empty array.+ await supabaseconst { data: todos, error } = await supabase.from('todos').select('*')