From f501f3d024fa7a75c33df262b08369ac42300c89 Mon Sep 17 00:00:00 2001 From: BilelJegham Date: Sun, 13 Aug 2023 18:11:45 +0200 Subject: [PATCH] fix: change username --- src/stores/auth.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/stores/auth.ts b/src/stores/auth.ts index 48fa325..05f0913 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -75,6 +75,20 @@ export const useAuthStore = defineStore('auth', () => { profile.value = data[0] } + async function changeUsername(username: string) { + if (!userId.value || !profile.value) return + + const { error } = await supabase + .from('profiles') + .update({ + username, + }) + .eq('user_id', userId.value) + + if (error) throw error + profile.value.username = username + } + return { profile, session, @@ -84,6 +98,7 @@ export const useAuthStore = defineStore('auth', () => { updateConnection, logout, signInWithEmail, + changeUsername, setProfile, } })