Skip to content

Commit

Permalink
Fix supabase.auth after upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
seballot committed Sep 26, 2024
1 parent f7e90bc commit d07332d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
8 changes: 6 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
3 changes: 2 additions & 1 deletion src/views/auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/views/auth/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d07332d

Please sign in to comment.