From d07332d35898b9301e36ba31a26ccacf37fcb56a Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Thu, 26 Sep 2024 16:36:00 +0200 Subject: [PATCH] Fix supabase.auth after upgrade --- src/App.vue | 6 ++++-- src/main.js | 8 ++++++-- src/views/auth/Login.vue | 3 ++- src/views/auth/Profile.vue | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index b0460c8..a24858f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -38,8 +38,10 @@ export default { help: false, // Displaying or not help messages } }, - created() { - this.user = supabase.auth.user() + async created() { + const { data, error } = await supabase.auth.getSession() + if (error) this.toastError(error) + this.user = data.session?.user this.help = localStorage.getItem('help') === 'true' }, computed: { diff --git a/src/main.js b/src/main.js index 36a5d61..b556c10 100644 --- a/src/main.js +++ b/src/main.js @@ -47,12 +47,16 @@ const app = createApp(App) .component('HelpMessage', HelpMessage) router.beforeEach(async (to) => { - let user = supabase.auth.user() + const { data, error } = await supabase.auth.getSession() + if (error) this.toastError(error) + let user = data.session?.user if (to.path.includes('update-password')) { // wait for the user to be signed in in the backend while (user == null) { await new Promise((r) => setTimeout(r, 400)) - user = supabase.auth.user() + const { data, error } = await supabase.auth.getSession() + if (error) this.toastError(error) + user = data.session?.user } app._instance.data.user = user return { name: 'profile' } diff --git a/src/views/auth/Login.vue b/src/views/auth/Login.vue index 0e68961..f6c8916 100644 --- a/src/views/auth/Login.vue +++ b/src/views/auth/Login.vue @@ -40,10 +40,11 @@ export default { } if (this.loading) return this.loading = true - const { user, error } = await supabase.auth.signIn({ + const { data, error } = await supabase.auth.signInWithPassword({ email: this.user.email, password: this.user.password, }) + const { user } = data this.loading = false if (error) this.toastError(error) else { diff --git a/src/views/auth/Profile.vue b/src/views/auth/Profile.vue index 4919a0d..7f9b1fe 100644 --- a/src/views/auth/Profile.vue +++ b/src/views/auth/Profile.vue @@ -55,7 +55,7 @@ export default { ...{ user_id: this.$root.user.id }, }).single() if (this.newPassword) { - error2 = await supabase.auth.update({ + error2 = await supabase.auth.updateUser({ password: this.newPassword, }).error }